Skip to main content

API Key Authentication

The Moorcheh API uses API key authentication. You must include your API key in the request headers to access any endpoint.

Getting Your API Key

1

Sign Up

Create a Moorcheh account at console.moorcheh.ai
2

Navigate to API Keys

Go to the API Keys section in your console
3

Generate Key

Generate a new API key or copy an existing one
4

Store Securely

Keep your API key secure and never share it publicly

Using Your API Key

Include your API key in the x-api-Key header with every request:
from moorcheh_sdk import MoorchehClient

client = MoorchehClient(
    api_key="your-api-key-here",
    base_url="https://api.moorcheh.ai/v1"
)

Security Best Practices

  • Use environment variables instead of hardcoding
  • Never commit API keys to version control
  • Use secret management services in production
# Good: Use environment variables
export MOORCHEH_API_KEY="your-api-key"
  • Generate new API keys periodically
  • Revoke old keys after rotation
  • Monitor key usage in your console
  • Separate keys for development, staging, and production
  • Easier to track usage and debug issues
  • Limit blast radius if a key is compromised
  • If a key is exposed, revoke it in the console
  • Generate a new key and update your applications
  • Monitor for unauthorized usage

Authentication Errors

401 Unauthorized

Error Response:
{
  "message": "Unauthorized: Invalid API key"
}
Common Causes:
  • Invalid or expired API key
  • Missing x-api-Key header
  • Incorrect header name (case-sensitive)
  • API key has been revoked
Solution:
  • Verify your API key is correct
  • Ensure you’re using x-api-Key (note the capital K)
  • Check that the key hasn’t been disabled in the console

403 Forbidden

Error Response:
{
  "message": "Forbidden: Insufficient permissions"
}
Common Causes:
  • API key doesn’t have required permissions
  • Account limits exceeded
Solution:
  • Check your account tier and limits
  • Contact support if you need increased limits

Environment Variables

  • Python
  • Node.js
  • .env File
import os
from moorcheh_sdk import MoorchehClient

# Load from environment variable
api_key = os.getenv('MOORCHEH_API_KEY')

client = MoorchehClient(api_key=api_key)

Next Steps