Last updated

Authentication

This guide explains how to authenticate with the Papr Memory API using various methods.

Authentication Methods

Papr Memory supports three authentication methods:

1. API Key

Include your API key in the X-API-Key header:

X-API-Key: <your-api-key>

This is the recommended method for server-side applications.

2. Bearer Token

Include your OAuth2 token from Auth0 in the Authorization header:

Authorization: Bearer <token>

This is recommended for web applications and services using OAuth.

3. Session Token

Include your session token in the X-Session-Token header:

X-Session-Token: <your-session-token>

This is primarily used for browser-based applications where session management is important.

Important API Requirements

There are several critical requirements when using the Papr Memory API:

  1. Environment Variable: You must set the PAPR_MEMORY_API_KEY environment variable before running your application.

  2. HTTPS Required: The endpoint requires HTTPS protocol. Using HTTP will result in connection failures.

  3. X-Client-Type Header Required: All requests must include the X-Client-Type header, which identifies the type of client making the request:

    X-Client-Type: <client-type>

    Example values: 'papr_plugin', 'browser_extension', 'sdk_typescript', 'sdk_python'

  4. Authentication Method Precedence:

    • When multiple authentication methods are provided, X-API-Key takes precedence over Bearer token
    • Only use one authentication method at a time to avoid conflicts

For improved performance with large responses, we recommend including the following header:

Accept-Encoding: gzip

This enables response compression, significantly reducing transfer times for large payloads.

Code Examples

API Key Authentication

curl -X POST https://memory.papr.ai/v1/memory \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Accept-Encoding: gzip" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "Memory content text",
    "type": "text"
  }'

Bearer Token Authentication

curl -X POST https://memory.papr.ai/v1/memory \
  -H "Authorization: Bearer YOUR_OAUTH_TOKEN" \
  -H "Accept-Encoding: gzip" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "Memory content text",
    "type": "text"
  }'

Security Best Practices

  1. Never hardcode authentication credentials in your source code. Always use environment variables or secure secret management.

  2. Generate different API keys - coming soon for different environments (development, staging, production).

  3. Implement proper token refreshing when using Bearer tokens to ensure they don't expire during user sessions.

  4. Rotate API keys periodically to minimize the impact of potential key leaks.

  5. Use gzip compression for large responses to improve performance and reduce bandwidth usage.

Troubleshooting

Common authentication errors and solutions:

ErrorDescriptionSolution
401 UnauthorizedInvalid or missing authenticationVerify your API key or token
403 ForbiddenValid authentication but insufficient permissionsCheck that your key has the right permissions
429 Too Many RequestsRate limit exceededImplement rate limiting and backoff strategies

Next Steps