Skip to main content

Overview

The SundayPyjamas AI Suite API uses API keys for authentication. All API requests must include a valid API key in the Authorization header.
API keys provide secure access to the API while maintaining workspace-level isolation and usage tracking.

API Key Format

API keys follow this specific format:
Example:
API keys are only shown once during creation. Store them securely immediately after generation!

Getting Your API Key

Follow these steps to generate your API key:
1

Access Workspace Settings

Navigate to your workspace settings in the SundayPyjamas platform.
2

Go to API Tab

Click on the “API” tab in your workspace settings.
3

Generate Key

Click “Generate API Key” to create a new key.
4

Name Your Key (Optional)

Give your API key a descriptive name to help you identify it later.
5

Copy and Store

Copy the generated key immediately and store it securely. It won’t be shown again!

Making Authenticated Requests

Include your API key in the Authorization header with the Bearer scheme:

Permissions and Access Control

API keys inherit the permissions of the user who created them:

Workspace Access

Keys can only access the workspace they were created in

Role Requirements

Only workspace owners and admins can create/manage API keys

Token Limits

API usage counts toward your workspace token limit

Usage Tracking

Monitor API key usage through workspace analytics

Auth by API Group

Most endpoints accept your workspace API key exactly as described above. A few groups differ:

Security Best Practices

✅ Do

  • Use environment variables or secure key management systems
  • Never hardcode API keys in your source code
  • Use different API keys for different applications/environments
  • Generate new API keys periodically
  • Deactivate old keys after replacement
  • Use descriptive names to track key usage
  • Review usage analytics regularly
  • Set up alerts for unusual activity
  • Track token consumption patterns
Use workspace analytics to monitor which API keys are consuming the most tokens and identify optimization opportunities.

❌ Don’t

API keys should never be included in frontend JavaScript, mobile apps, or any client-side code where users can access them.
Use separate API keys for different applications to maintain better security and usage tracking.
Use .gitignore to exclude files containing API keys and use environment variables instead.

API Key Management

Creating API Keys

1

Navigate to Settings

Go to your workspace settings in the SundayPyjamas web interface.
2

Access API Tab

Click on the “API” tab to view key management options.
3

Generate New Key

Click “Generate API Key” and optionally provide a descriptive name.
4

Save Securely

Copy the generated key immediately and store it in your secure key management system.

Managing Existing Keys

In your workspace API settings, you can:
  • View all active API keys with their names and creation dates
  • Delete keys you no longer need
  • Monitor usage for each individual key
  • Track token consumption per API key
API key creation and management is done exclusively through the web interface to ensure proper security and access control.

Rate Limits and Quotas

Per Workspace Limit

Maximum 10 active API keys per workspace

Token-based Usage

API usage counts toward workspace token quotas

Request Rate Limits

Standard rate limiting applies to all API endpoints

Fair Usage Policy

Usage monitoring to ensure fair access for all users

Error Responses

Invalid API Key (401)

Common causes:
  • API key doesn’t exist or has been deleted
  • Incorrect API key format
  • Missing or malformed Authorization header
Solution:
  • Verify your API key is correct and active
  • Check the Authorization header format: Bearer spj_ai_...
  • Generate a new API key if necessary

Insufficient Permissions (403)

Cause: User doesn’t have required role (owner/admin) for API key management Solution: Contact your workspace owner to grant appropriate permissions

Token Limit Exceeded (403)

Solutions:
  • Wait for your monthly token reset
  • Upgrade your subscription plan
  • Optimize prompts to reduce token usage

Environment Variables Best Practices

Local Development

Create a .env file for local development:

Production Deployment

Set environment variables in your deployment platform:

Access in Code

Testing Authentication

Verify API Key

Test your API key with a simple request:

Next Steps

Chat API

Start making requests to the Chat API with your authenticated key

Rate Limits

Understand usage limits and optimization strategies

Code Examples

View complete implementation examples with authentication

Error Handling

Learn how to handle authentication errors gracefully