Skip to main content

Authentication

PDFDancer uses API tokens to authenticate requests. You can get started immediately with anonymous tokens, or create an account for higher limits and advanced features.


Anonymous Tokens (Quick Start)

No API token needed to get started—the SDK automatically obtains an anonymous token when you don't provide one:

from pdfdancer import PDFDancer

# No token needed! SDK automatically gets an anonymous token
with PDFDancer.open("input.pdf") as pdf:
# Your PDF operations here
pass

Anonymous tokens are perfect for prototyping and small projects. For production use, higher rate limits, and access to premium features, create an account and use authenticated API tokens.


Obtaining an API Token

  1. Sign into the PDFDancer Dashboard.
  2. Navigate to Settings → API Tokens.
  3. Click Generate Token, provide a descriptive name, and copy the generated token.

Store tokens in a secrets manager such as AWS Secrets Manager, HashiCorp Vault, or your CI provider's encrypted variables. Never commit tokens to source control.


Authentication Methods

Set the token in an environment variable to avoid hardcoding credentials:

export PDFDANCER_TOKEN="your-api-token"

The SDK will automatically read this environment variable when initializing.

from pdfdancer import PDFDancer

# Token is automatically read from PDFDANCER_TOKEN environment variable
with PDFDancer.open("input.pdf") as pdf:
# Your PDF operations here
pass

Explicit Token Parameter

You can also pass the token explicitly when creating the client:

from pdfdancer import PDFDancer

with PDFDancer.open(
pdf_data="input.pdf",
token="your-api-token"
) as pdf:
# Your PDF operations here
pass

Configuration Options

Custom API Endpoint

This configuration is for self-hosted enterprise plans. If you're using a self-hosted instance of PDFDancer, you can override the default API endpoint by setting the PDFDANCER_BASE_URL environment variable or passing the base_url parameter:

from pdfdancer import PDFDancer

# Using environment variable
# export PDFDANCER_BASE_URL="https://sandbox.pdfdancer.com"

# Or passing explicitly
with PDFDancer.open(
pdf_data="input.pdf",
token="your-api-token",
base_url="https://sandbox.pdfdancer.com"
) as pdf:
pass

Request Timeout

Configure request timeout for long-running operations:

from pdfdancer import PDFDancer

with PDFDancer.open(
pdf_data="input.pdf",
token="your-api-token",
timeout=60 # 60 seconds
) as pdf:
pass

Security Best Practices

Token Storage

  • Never commit tokens to version control - Use .gitignore to exclude token files
  • Use secrets managers - Store tokens in AWS Secrets Manager, HashiCorp Vault, or similar
  • Environment-specific tokens - Use different tokens for development, staging, and production
  • Rotate regularly - Generate new tokens periodically and deactivate old ones

Token Rotation

  1. Generate a new token in the PDFDancer Dashboard
  2. Update your environment variables or secrets manager
  3. Deploy the changes to all environments
  4. Deactivate the old token after verifying the new one works

Compromised Tokens

If a token is compromised:

  1. Immediately deactivate it in the PDFDancer Dashboard
  2. Generate a new token
  3. Update all applications using the old token
  4. Review audit logs for suspicious activity

Next Steps