Skip to main content

API Keys

All requests to the Samurai AI API must include your API key as a Bearer token in the Authorization header.
Authorization: Bearer sk-samurai-YOUR_API_KEY

Getting Your API Key

  1. Log in to your Dashboard
  2. Navigate to Settings → API Keys
  3. Click + Create API Key
  4. Give it a name (e.g., “Production”, “Development”)
  5. Copy and store it securely — it won’t be shown again

Using Your API Key

from openai import OpenAI

client = OpenAI(
    api_key="sk-samurai-YOUR_API_KEY",  # Your Samurai AI key
    base_url="https://api.samuraiapi.in/v1"
)

Environment Variables

Always store your API key in environment variables, never hardcode it:
.env
SAMURAI_API_KEY=sk-samurai-xxxxxxxxxxxxxxxxxxxx
Python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ.get("SAMURAI_API_KEY"),
    base_url="https://api.samuraiapi.in/v1"
)
Never expose your API key in:
  • Client-side JavaScript / browser code
  • Public GitHub repositories
  • Log files or error messages
  • Mobile app bundles

Error Responses

StatusErrorMeaning
401auth_errorMissing or invalid API key
403permission_deniedValid key but insufficient plan for this model
402insufficient_creditsYour credit balance is depleted

Managing API Keys

  • Create multiple keys for different environments (dev, staging, prod)
  • Rotate keys periodically for security
  • Delete unused keys from your dashboard
  • Keys can be revoked instantly if compromised