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 openaiConfiguration
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_KEYSecurity Best Practice:
Remember to handle your API key securely, preferably using environment variables. Do not commit keys directly into your codebase.
Chat Completions
https://samuraiapi.in/v1/chat/completionsCreate 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
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | The model ID to use for completion |
| messages | array | Yes | Array of message objects with role and content |
| max_tokens | integer | No | Maximum tokens to generate (default: 1024) |
| temperature | number | No | Sampling temperature 0-2 (default: 0.7) |
| stream | boolean | No | Enable 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
https://samuraiapi.in/v1/modelsRetrieve 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.
Invalid or missing API key
Insufficient permissions (e.g., trying to use Pro models on Free plan)
Rate limit exceeded
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.
| Plan | Requests/Minute | Requests/Day | Tokens/Request |
|---|---|---|---|
| Free | 60 | 1,000 | 4,096 |
| Pro | 300 | 10,000 | 32,768 |
Pricing
Simple, transparent pricing based on your usage. No hidden fees.
Free
- Access to 100+ HuggingFace models
- 1,000 requests per day
- Basic analytics dashboard
- Community support
Pro
- 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
Model Selection
You specify the model in your request (e.g., "anthropic/claude-3.7-sonnet")
Automatic Routing
Our system identifies the provider and routes your request accordingly
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
Web Search
Enable models to search the web for real-time information. This feature is coming soon and will allow AI models to access current information beyond their training data.
Coming Soon:
Web search integration is currently in development. Join our waitlist to be notified when it launches.
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/v1Streaming
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 Type | Free Plan | Pro Plan |
|---|---|---|
| Requests per minute | 60 | 300 |
| Requests per day | 1,000 | 10,000 |
| Max tokens per request | 4,096 | 32,768 |
| Max concurrent requests | 5 | 20 |
Parameters
Common parameters supported across all chat completion endpoints.
| Parameter | Type | Default | Description |
|---|---|---|---|
| temperature | number | 0.7 | Controls randomness (0-2) |
| max_tokens | integer | 1024 | Maximum tokens to generate |
| top_p | number | 1.0 | Nucleus sampling threshold |
| frequency_penalty | number | 0.0 | Penalize repeated tokens (-2 to 2) |
| presence_penalty | number | 0.0 | Penalize new tokens (-2 to 2) |
| stop | array | null | Stop sequences |
Image Generation
https://samuraiapi.in/v1/images/generationsGenerate 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
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Model ID (e.g., "flux-pro-1.1-ultra", "stable-diffusion-3.5") |
| prompt | string | Yes | Text description of the image to generate |
| n | integer | No | Number of images to generate (default: 1) |
| size | string | No | Image dimensions (e.g., "1024x1024", "1920x1080") |
| quality | string | No | Quality 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
https://samuraiapi.in/v1/images/editsEdit existing images using AI-powered image editing capabilities. Modify images with text prompts while preserving the original structure.
Request Body (multipart/form-data)
| Parameter | Type | Required | Description |
|---|---|---|---|
| image | file | Yes | The image file to edit (PNG format, max 4MB) |
| prompt | string | Yes | Text description of the desired edit |
| mask | file | No | Optional mask image (PNG, transparent areas will be edited) |
| n | integer | No | Number of edited images to generate (default: 1) |
| size | string | No | Output 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
https://samuraiapi.in/v1/embeddingsGenerate 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
https://samuraiapi.in/v1/audio/speechConvert 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
https://samuraiapi.in/v1/audio/transcriptionsTranscribe 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
https://samuraiapi.in/v1/videosGenerate 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
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Model ID (e.g., "sora-2", "veo-3.1-fast", "wan-2.1-t2v-14b") |
| prompt | string | Yes | Text description of the video to generate |
| duration | integer | No | Video 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
https://samuraiapi.in/v1/images/to-videoAnimate static images into dynamic videos using AI. Transform your images into engaging video content with text prompts.
Request Body (multipart/form-data)
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Model ID (e.g., "sora-2-i2v", "veo-3.1-fast-i2v", "wan-2.1-i2v-14b-720p") |
| image | file | Yes | The image file to animate (PNG/JPG, max 10MB) |
| prompt | string | Yes | Text description of the desired animation |
| duration | integer | No | Video 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=5Example: 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
https://samuraiapi.in/v1/usageRetrieve 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}")