Overview

Samurai AI Documentation

Welcome to the official Samurai AI documentation. Learn how to integrate and utilize our unified AI gateway to access hundreds of AI models through a single API.

Introduction

Samurai AI provides a single, standardized API endpoint to access hundreds of Large Language Models (LLMs) from various providers like OpenAI, Anthropic, Google, Mistral, and more. Simplify your AI integrations, benefit from automatic failover, optimize costs, and ensure higher availability.

Our platform acts as a proxy, forwarding your requests to the appropriate provider while offering additional features like model routing, caching, and usage tracking. Get started quickly using familiar SDKs or direct API calls.

âš ī¸

Important:

Ensure you have generated an API key from your Samurai AI dashboard before proceeding with integration.

Quickstart

Get started with Samurai AI in minutes. Follow these simple steps to make your first API request.

Installation

pip install openai

Configuration

The primary configuration step involves setting your Samurai AI API key and pointing your client library to the correct base URL.

export SAMURAI_API_KEY="your_actual_api_key_here"

curl https://samuraiapi.in/v1/chat/completions \
  -H "Authorization: Bearer $SAMURAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-3.7-sonnet",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Hello from cURL!"}
    ],
    "temperature": 0.7,
    "max_tokens": 150
  }'

Authentication

All API requests require authentication using an API key. Include your API key in the Authorization header as a Bearer token.

Authorization: Bearer YOUR_API_KEY
â„šī¸

Security Best Practice:

Remember to handle your API key securely, preferably using environment variables. Do not commit keys directly into your codebase.

Chat Completions

POSThttps://samuraiapi.in/v1/chat/completions

Create a chat completion using any supported AI model. This endpoint supports both streaming and non-streaming responses.

Request Body

{
  "model": "anthropic/claude-3.7-sonnet",
  "messages": [
    {
      "role": "user",
      "content": "Hello, how are you?"
    }
  ],
  "max_tokens": 1024,
  "temperature": 0.7,
  "stream": false
}

Parameters

ParameterTypeRequiredDescription
modelstringYesThe model ID to use for completion
messagesarrayYesArray of message objects with role and content
max_tokensintegerNoMaximum tokens to generate (default: 1024)
temperaturenumberNoSampling temperature 0-2 (default: 0.7)
streambooleanNoEnable streaming responses (default: false)

Response

{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "anthropic/claude-3.7-sonnet",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! I'm doing well, thank you for asking."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 10,
    "completion_tokens": 12,
    "total_tokens": 22
  }
}

List Models

GEThttps://samuraiapi.in/v1/models

Retrieve a list of all available models. The response includes model IDs, providers, and tier information.

Example Response

{
  "models": [
    {
      "id": "anthropic/claude-3.7-sonnet",
      "provider": "Vercel AI Gateway",
      "plan_required": "pro",
      "context_window": 200000
    },
    {
      "id": "meta-llama/Llama-3.3-70B-Instruct",
      "provider": "HuggingFace",
      "plan_required": "free",
      "context_window": 8192
    }
  ]
}

Error Handling

The API uses standard HTTP status codes to indicate success or failure. Error responses include detailed messages to help you debug issues.

401Unauthorized

Invalid or missing API key

403Forbidden

Insufficient permissions (e.g., trying to use Pro models on Free plan)

429Too Many Requests

Rate limit exceeded

500Internal Server Error

Something went wrong on our end

Error Response Format

{
  "error": {
    "message": "Invalid API key provided",
    "type": "invalid_request_error",
    "code": "invalid_api_key"
  }
}

Rate Limits

Rate limits vary by plan tier to ensure fair usage and optimal performance for all users.

PlanRequests/MinuteRequests/DayTokens/Request
Free601,0004,096
Pro30010,00032,768

Pricing

Simple, transparent pricing based on your usage. No hidden fees.

Free

$0/month
  • Access to 100+ HuggingFace models
  • 1,000 requests per day
  • Basic analytics dashboard
  • Community support
POPULAR

Pro

$29/month
  • Everything in Free, plus:
  • Access to 130+ premium models (Claude, GPT-4, Gemini)
  • 10,000 requests per day
  • Advanced analytics & monitoring
  • Priority support

Need more?

Contact us for enterprise pricing with custom rate limits, dedicated support, and SLA guarantees.

Need Help?

Our team is here to help you get the most out of the Samurai AI API.

FAQ

What is Samurai AI?

Samurai AI is a unified AI gateway that provides a single API endpoint to access hundreds of AI models from various providers like OpenAI, Anthropic, Google, Mistral, and more. We simplify AI integrations by offering automatic failover, cost optimization, and higher availability.

How do I get started?

Simply sign up for a free account, generate an API key from your dashboard, and start making requests to our API endpoint. You can use familiar SDKs like OpenAI's Python or JavaScript libraries by just changing the base URL.

What's the difference between Free and Pro plans?

The Free plan gives you access to 100+ HuggingFace models with 1,000 requests per day. The Pro plan unlocks 130+ premium models including Claude, GPT-4, and Gemini, with 10,000 requests per day and priority support.

Do you store my API requests?

We only store minimal metadata for analytics and billing purposes. Your actual request content and responses are not stored. See our Privacy & Logging section for more details.

Can I use streaming responses?

Yes! All chat completion endpoints support streaming by setting the stream: true parameter in your request.

Principles

Samurai AI is built on core principles that guide our development and service delivery.

🚀

Simplicity First

One API, hundreds of models. We believe AI integration should be simple and straightforward, not complex and fragmented.

🔒

Privacy & Security

Your data is yours. We don't store request content, and all communications are encrypted end-to-end.

⚡

Performance

Low latency, high availability. Our infrastructure is optimized for speed with automatic failover and load balancing.

💰

Cost Optimization

Transparent pricing with no hidden fees. We help you optimize costs through intelligent model routing and caching.

Privacy & Logging

We take your privacy seriously. Here's what we log and what we don't.

What We Log

  • Request metadata (timestamp, model used, token count)
  • API key used (for billing and rate limiting)
  • Response status codes and error messages

What We Don't Log

  • ✕Your actual prompt content
  • ✕Model responses
  • ✕Any personally identifiable information (PII)

Provider Routing

Samurai AI automatically routes your requests to the appropriate AI provider based on the model you specify. Our intelligent routing system ensures optimal performance and availability.

How It Works

1

Model Selection

You specify the model in your request (e.g., "anthropic/claude-3.7-sonnet")

2

Automatic Routing

Our system identifies the provider and routes your request accordingly

3

Failover Protection

If a provider is unavailable, we automatically retry with backup providers

Tool Calling

Enable your AI models to call external tools and functions. Tool calling allows models to interact with APIs, databases, and other services.

â„šī¸

Note:

Tool calling is only supported by certain models. Check the model documentation for compatibility.

Example

{
  "model": "anthropic/claude-3.7-sonnet",
  "messages": [
    {"role": "user", "content": "What's the weather in Tokyo?"}
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get the current weather in a location",
        "parameters": {
          "type": "object",
          "properties": {
            "location": {
              "type": "string",
              "description": "The city name"
            }
          },
          "required": ["location"]
        }
      }
    }
  ]
}

Vision & PDFs

Use vision-capable models to analyze images and PDFs. Simply include image URLs or base64-encoded images in your messages.

Image Analysis Example

{
  "model": "anthropic/claude-3.7-sonnet",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "What's in this image?"
        },
        {
          "type": "image_url",
          "image_url": {
            "url": "https://example.com/image.jpg"
          }
        }
      ]
    }
  ]
}

Message Transforms

Samurai AI automatically transforms your messages to match the format expected by different providers. This means you can use a consistent message format regardless of which model you're using.

Supported Transformations

  • OpenAI format to Anthropic format
  • System messages to provider-specific formats
  • Tool calling format normalization
  • Image content format conversion

API Overview

The Samurai AI API is organized around REST principles. Our API has predictable resource-oriented URLs, accepts JSON-encoded request bodies, returns JSON-encoded responses, and uses standard HTTP response codes.

Base URL

https://samuraiapi.in/v1

Streaming

Enable streaming to receive responses as they're generated, providing a better user experience for long-form content.

Enable Streaming

Set stream: true in your request:

{
  "model": "anthropic/claude-3.7-sonnet",
  "messages": [
    {"role": "user", "content": "Write a story"}
  ],
  "stream": true
}

Handling Stream Events

Streaming responses use Server-Sent Events (SSE). Each event contains a JSON object:

data: {"choices":[{"delta":{"content":"Hello"},"index":0}]}

data: {"choices":[{"delta":{"content":" world"},"index":0}]}

data: [DONE]

Limits

Understanding the limits helps you design your application for optimal performance.

Limit TypeFree PlanPro Plan
Requests per minute60300
Requests per day1,00010,000
Max tokens per request4,09632,768
Max concurrent requests520

Parameters

Common parameters supported across all chat completion endpoints.

ParameterTypeDefaultDescription
temperaturenumber0.7Controls randomness (0-2)
max_tokensinteger1024Maximum tokens to generate
top_pnumber1.0Nucleus sampling threshold
frequency_penaltynumber0.0Penalize repeated tokens (-2 to 2)
presence_penaltynumber0.0Penalize new tokens (-2 to 2)
stoparraynullStop sequences

Image Generation

POSThttps://samuraiapi.in/v1/images/generations

Generate images from text prompts using state-of-the-art AI image generation models including FLUX, Stable Diffusion, and more.

Request Body

{
  "model": "flux-pro-1.1-ultra",
  "prompt": "A serene Japanese garden with cherry blossoms",
  "n": 1,
  "size": "1024x1024",
  "quality": "standard"
}

Parameters

ParameterTypeRequiredDescription
modelstringYesModel ID (e.g., "flux-pro-1.1-ultra", "stable-diffusion-3.5")
promptstringYesText description of the image to generate
nintegerNoNumber of images to generate (default: 1)
sizestringNoImage dimensions (e.g., "1024x1024", "1920x1080")
qualitystringNoQuality level: "standard" or "hd" (default: "standard")

Response

{
  "created": 1677652288,
  "data": [
    {
      "url": "https://example.com/generated-image.png",
      "b64_json": null
    }
  ]
}

Example: cURL

curl https://samuraiapi.in/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "flux-pro-1.1-ultra",
    "prompt": "A serene Japanese garden with cherry blossoms",
    "n": 1,
    "size": "1024x1024"
  }'

Example: Python

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://samuraiapi.in/v1"
)

response = client.images.generate(
    model="flux-pro-1.1-ultra",
    prompt="A serene Japanese garden with cherry blossoms",
    n=1,
    size="1024x1024"
)

print(response.data[0].url)

Example: Node.js

import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: 'YOUR_API_KEY',
  baseURL: 'https://samuraiapi.in/v1'
});

const response = await client.images.generate({
  model: 'flux-pro-1.1-ultra',
  prompt: 'A serene Japanese garden with cherry blossoms',
  n: 1,
  size: '1024x1024'
});

console.log(response.data[0].url);
â„šī¸

Available Models:

View all available image generation models at samuraiapi.in/models. Models include FLUX Pro, Stable Diffusion, Recraft, and more.

Image Edits

POSThttps://samuraiapi.in/v1/images/edits

Edit existing images using AI-powered image editing capabilities. Modify images with text prompts while preserving the original structure.

Request Body (multipart/form-data)

ParameterTypeRequiredDescription
imagefileYesThe image file to edit (PNG format, max 4MB)
promptstringYesText description of the desired edit
maskfileNoOptional mask image (PNG, transparent areas will be edited)
nintegerNoNumber of edited images to generate (default: 1)
sizestringNoOutput image size (e.g., "1024x1024")

Example: cURL

curl https://samuraiapi.in/v1/images/edits \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F image="@original.png" \
  -F prompt="Add a sunset in the background" \
  -F n=1 \
  -F size="1024x1024"

Example: Python

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://samuraiapi.in/v1"
)

response = client.images.edit(
    image=open("original.png", "rb"),
    prompt="Add a sunset in the background",
    n=1,
    size="1024x1024"
)

print(response.data[0].url)
â„šī¸

Note:

Image editing requires PNG format images. The image will be automatically resized if it doesn't match the specified size parameter.

Embeddings

POSThttps://samuraiapi.in/v1/embeddings

Generate vector embeddings for text, useful for semantic search, clustering, and recommendations.

🚧

Coming Soon:

Embeddings endpoint is currently in development and will be available soon.

Audio Speech

POSThttps://samuraiapi.in/v1/audio/speech

Convert text to natural-sounding speech using AI text-to-speech models.

🚧

Coming Soon:

Text-to-speech is currently in development and will be available soon.

Audio Transcriptions

POSThttps://samuraiapi.in/v1/audio/transcriptions

Transcribe audio files to text using AI speech-to-text models.

🚧

Coming Soon:

Speech-to-text is currently in development and will be available soon.

Video Generation

POSThttps://samuraiapi.in/v1/videos

Generate videos from text prompts using advanced AI video generation models including Sora, Veo, and Wan AI.

Request Body

{
  "model": "sora-2",
  "prompt": "A young man walking on the street at sunset",
  "duration": 5
}

Parameters

ParameterTypeRequiredDescription
modelstringYesModel ID (e.g., "sora-2", "veo-3.1-fast", "wan-2.1-t2v-14b")
promptstringYesText description of the video to generate
durationintegerNoVideo duration in seconds (default: 5, max: 10)

Response

{
  "created": 1677652288,
  "data": [
    {
      "url": "https://example.com/generated-video.mp4"
    }
  ]
}

Example: cURL

curl https://samuraiapi.in/v1/videos \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "sora-2",
    "prompt": "A young man walking on the street at sunset",
    "duration": 5
  }'

Example: Python

import requests

response = requests.post(
    "https://samuraiapi.in/v1/videos",
    headers={
        "Authorization": "Bearer YOUR_API_KEY",
        "Content-Type": "application/json"
    },
    json={
        "model": "sora-2",
        "prompt": "A young man walking on the street at sunset",
        "duration": 5
    }
)

video_url = response.json()["data"][0]["url"]
print(video_url)
â„šī¸

Usage Limits:

Free users: 30 video generations per week. Pro users: Unlimited video generations.

Image to Video

POSThttps://samuraiapi.in/v1/images/to-video

Animate static images into dynamic videos using AI. Transform your images into engaging video content with text prompts.

Request Body (multipart/form-data)

ParameterTypeRequiredDescription
modelstringYesModel ID (e.g., "sora-2-i2v", "veo-3.1-fast-i2v", "wan-2.1-i2v-14b-720p")
imagefileYesThe image file to animate (PNG/JPG, max 10MB)
promptstringYesText description of the desired animation
durationintegerNoVideo duration in seconds (default: 5, max: 10)

Example: cURL

curl https://samuraiapi.in/v1/images/to-video \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F model="sora-2-i2v" \
  -F image="@cat.png" \
  -F prompt="The cat starts to dance" \
  -F duration=5

Example: Python

import requests

with open("cat.png", "rb") as image_file:
    response = requests.post(
        "https://samuraiapi.in/v1/images/to-video",
        headers={"Authorization": "Bearer YOUR_API_KEY"},
        files={"image": image_file},
        data={
            "model": "sora-2-i2v",
            "prompt": "The cat starts to dance",
            "duration": 5
        }
    )

video_url = response.json()["data"][0]["url"]
print(video_url)

Example: Node.js

import fs from 'fs';
import FormData from 'form-data';

const formData = new FormData();
formData.append('model', 'sora-2-i2v');
formData.append('image', fs.createReadStream('cat.png'));
formData.append('prompt', 'The cat starts to dance');
formData.append('duration', '5');

const response = await fetch('https://samuraiapi.in/v1/images/to-video', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    ...formData.getHeaders()
  },
  body: formData
});

const data = await response.json();
console.log(data.data[0].url);
â„šī¸

Usage Limits:

Image-to-video generation shares the same weekly limits as text-to-video: 30 generations per week for free users, unlimited for Pro users.

Get Usage

GEThttps://samuraiapi.in/v1/usage

Retrieve your API usage statistics including request counts, token usage, and costs.

Example Response

{
  "usage": {
    "requests_today": 245,
    "requests_this_month": 8432,
    "tokens_used_today": 125430,
    "tokens_used_this_month": 3245678,
    "plan": "pro",
    "limits": {
      "requests_per_day": 10000,
      "requests_per_minute": 300
    }
  }
}

Using OpenAI SDK

The easiest way to use Samurai AI is with the OpenAI SDK. Simply change the base URL and API key.

Python Example

from openai import OpenAI

client = OpenAI(
    api_key="your_samurai_api_key",
    base_url="https://samuraiapi.in/v1"
)

response = client.chat.completions.create(
    model="anthropic/claude-3.7-sonnet",
    messages=[
        {"role": "user", "content": "Hello!"}
    ]
)

print(response.choices[0].message.content)

TypeScript Example

import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: process.env.SAMURAI_API_KEY,
  baseURL: 'https://samuraiapi.in/v1',
});

const response = await client.chat.completions.create({
  model: 'anthropic/claude-3.7-sonnet',
  messages: [
    { role: 'user', content: 'Hello!' }
  ],
});

console.log(response.choices[0].message.content);

Using API Directly

You can also make direct HTTP requests to the API without using any SDK.

cURL Example

curl https://samuraiapi.in/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-3.7-sonnet",
    "messages": [
      {
        "role": "user",
        "content": "Hello!"
      }
    ]
  }'

Timeout Handling

Properly handling timeouts ensures your application remains responsive even when API requests take longer than expected.

Recommended Timeouts

  • Connection timeout: 10 seconds
  • Read timeout: 60 seconds for non-streaming, 300 seconds for streaming
  • Retry strategy: Exponential backoff with 3 retries

Python Example

from openai import OpenAI
import httpx

client = OpenAI(
    api_key="your_samurai_api_key",
    base_url="https://samuraiapi.in/v1",
    timeout=httpx.Timeout(60.0, connect=10.0),
    max_retries=3
)

try:
    response = client.chat.completions.create(
        model="anthropic/claude-3.7-sonnet",
        messages=[{"role": "user", "content": "Hello!"}]
    )
except httpx.TimeoutException:
    print("Request timed out")
except Exception as e:
    print(f"Error: {e}")