Skip to main content
POST
/
chat
/
completions
curl https://www.samuraiapi.in/v1/chat/completions \
  -H "Authorization: Bearer $SAMURAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "What is the capital of Japan?"}
    ],
    "temperature": 0.7,
    "max_tokens": 150
  }'
{
  "id": "chatcmpl-abc123xyz",
  "object": "chat.completion",
  "created": 1715000000,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Tokyo is the capital of Japan. It is also the most populous metropolitan area in the world."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 28,
    "completion_tokens": 22,
    "total_tokens": 50
  }
}
model
string
required
The model ID to use. See the Models reference for all available IDs.Popular values: gpt-4o, gpt-4o-mini, claude-3-5-sonnet-20241022, gemini-2.0-flash, deepseek-chat
messages
array
required
Array of conversation messages. Each message has a role (system, user, assistant) and content.
temperature
number
default:"1"
Sampling temperature from 0 to 2. Lower = more deterministic, higher = more creative.
max_tokens
integer
Maximum tokens to generate. If omitted, uses the model’s default.
stream
boolean
default:"false"
If true, streams partial tokens via Server-Sent Events. See Streaming.
top_p
number
default:"1"
Nucleus sampling. Only sample from top p probability mass. Use temperature OR top_p, not both.
frequency_penalty
number
default:"0"
Penalizes tokens based on how often they appear in the text so far. Range: -2.0 to 2.0.
presence_penalty
number
default:"0"
Penalizes tokens based on whether they have appeared at all so far. Range: -2.0 to 2.0.
stop
string | array
Up to 4 stop sequences. The API will stop generating further tokens when it encounters any of these.
n
integer
default:"1"
Number of completions to generate. Each counts toward your usage.
user
string
A unique identifier for your end-user. Helps with abuse monitoring.
curl https://www.samuraiapi.in/v1/chat/completions \
  -H "Authorization: Bearer $SAMURAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "What is the capital of Japan?"}
    ],
    "temperature": 0.7,
    "max_tokens": 150
  }'
{
  "id": "chatcmpl-abc123xyz",
  "object": "chat.completion",
  "created": 1715000000,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Tokyo is the capital of Japan. It is also the most populous metropolitan area in the world."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 28,
    "completion_tokens": 22,
    "total_tokens": 50
  }
}