Skip to main content

API Keys

All CAS Parser API requests require authentication via the x-api-key header.

Getting Your API Key

  1. Sign up at app.casparser.in
  2. Navigate to DevelopersAPI Keys
  3. Click Generate API Key
  4. Copy and store securely
Never expose your API key in client-side code. Use access tokens for frontend applications.

Using API Keys

import requests

response = requests.post(
    "https://api.casparser.in/v4/smart/parse",
    headers={"x-api-key": "YOUR_API_KEY"},
    files={"file": open("cas.pdf", "rb")},
    data={"password": "ABCDE1234F"}
)

Access Tokens

For frontend/SDK applications, use short-lived access tokens instead of exposing your API key.

Token Flow

Generate Access Token

Backend (server-side):
import requests

response = requests.post(
    "https://api.casparser.in/v1/token",
    headers={"x-api-key": "YOUR_API_KEY"},
    json={"expiry_minutes": 30}
)

access_token = response.json()["access_token"]
# Returns: at_xxxxxxxxxxxxxxxxxx
Frontend (client-side):
// Get token from your backend
const { access_token } = await fetch('/api/casparser/token').then(r => r.json());

// Use token in place of API key
const response = await fetch('https://api.casparser.in/v4/smart/parse', {
  method: 'POST',
  headers: { 'x-api-key': access_token },  // Use token here
  body: formData
});

Token Properties

PropertyValue
Prefixat_
Max TTL60 minutes
ScopeAll /v4/* endpoints
RestrictionsCannot generate other tokens, cannot access billing

Verify Token

response = requests.post(
    "https://api.casparser.in/v1/token/verify",
    headers={"x-api-key": "YOUR_API_KEY"},
    json={"access_token": "at_xxx"}
)

data = response.json()
# {"valid": true, "expires_at": "2024-01-15T11:30:00Z"}

Security Best Practices

1. Environment Variables

Never hardcode API keys:
# ❌ Bad
API_KEY = "sk_live_abc123"

# ✅ Good
import os
API_KEY = os.environ.get("CASPARSER_API_KEY")

2. Backend Token Generation

Create a backend endpoint:
# Flask example
from flask import Flask, jsonify
import requests
import os

app = Flask(__name__)

@app.route('/api/casparser/token')
def get_token():
    response = requests.post(
        'https://api.casparser.in/v1/token',
        headers={'x-api-key': os.environ['CASPARSER_API_KEY']},
        json={'expiry_minutes': 30}
    )
    return jsonify(response.json())

3. Rate Limiting

Implement rate limiting on your backend:
from flask_limiter import Limiter

limiter = Limiter(app, default_limits=["60 per minute"])

@app.route('/api/parse')
@limiter.limit("10 per minute")
def parse_cas():
    # Your parsing logic
    pass

4. HTTPS Only

Always use HTTPS for API requests. The API will reject HTTP requests.

5. Key Rotation

Rotate API keys periodically:
  1. Generate new API key in dashboard
  2. Update environment variables
  3. Deploy updated code
  4. Delete old API key

Sandbox Key

For testing and development:
sandbox-with-json-responses
  • Returns sample data
  • No credit consumption
  • Rate limited to 10 requests/minute

Troubleshooting

ErrorCauseSolution
401 UnauthorizedInvalid API keyCheck key in dashboard
401 UnauthorizedMissing headerAdd x-api-key header
403 ForbiddenExpired tokenGenerate new access token
403 ForbiddenQuota exceededCheck credits with /v1/credits

Next Steps