Skip to content

chat

Create a chat completion, supports streaming

POST /chat/completions
FieldTypeRequiredDescription
modelstringYesModel name
messagesArray<Message>YesMessages list
frequency_penaltynumberNo-
logit_biasobjectNo-
logprobsbooleanNoWhen true, stream must be false (OpenAI constraint)
top_logprobsintegerNo-
max_tokensintegerNo-
nintegerNoNumber of chat completion choices to generate
modalitiesArray<string (text, audio)>NoOutput modality types. Use [“text”, “audio”] for audio output
audioobjectNoAudio output configuration (when modalities includes audio)
presence_penaltynumberNo-
response_formatobjectNo-
seedintegerNo-
service_tierstring (auto, default)No-
stopstringNo-
streambooleanNo-
stream_optionsobjectNo-
temperaturenumberNo-
top_pnumberNo-
top_kintegerNoTop-k sampling parameter (non-OpenAI standard, model-specific)
toolsArray<Tool>No-
tool_choicestring (none, auto, required)No-
parallel_tool_callsbooleanNoWhether to enable parallel function calling during tool use. Only valid when tools are specified.
userstringNoUnique identifier representing end-user for abuse monitoring
reasoning_effortstring (low, medium, high)NoReasoning effort level for o1 series models (low, medium, high)
max_completion_tokensintegerNoMaximum number of tokens to generate in the completion (alternative to max_tokens, more precise)
storebooleanNoWhether to store the output for use in model distillation or evals
metadataobjectNoCustom metadata to attach to the request for tracking purposes
{
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Hello, how are you?"
}
]
}
{
"model": "qwen-plus",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is the capital of France?"
}
],
"temperature": 0.7,
"max_tokens": 100
}
{
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Tell me a story"
}
],
"stream": true,
"temperature": 0.8
}
{
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "What's the weather like in San Francisco and Tokyo?"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
],
"description": "The temperature unit to use"
}
},
"required": [
"location"
]
}
}
}
],
"tool_choice": "auto",
"temperature": 0.7
}
{
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "What's the weather in San Francisco?"
},
{
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"location\": \"San Francisco, CA\", \"unit\": \"celsius\"}"
}
}
]
},
{
"role": "tool",
"content": "{\"temperature\": 18, \"condition\": \"sunny\", \"humidity\": 65}",
"tool_call_id": "call_abc123"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": [
"location"
]
}
}
}
]
}
{
"model": "claude-sonnet-4.5",
"messages": [
{
"role": "system",
"content": "You are a knowledgeable programming tutor."
},
{
"role": "user",
"content": "How do I create a list in Python?"
},
{
"role": "assistant",
"content": "In Python, you can create a list using square brackets. For example: my_list = [1, 2, 3]"
},
{
"role": "user",
"content": "How do I add items to it?"
}
],
"max_tokens": 500,
"temperature": 0.8
}
{
"model": "gpt-4o-mini",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant that outputs in JSON format."
},
{
"role": "user",
"content": "Extract the name, age, and occupation from this text: John is 30 years old and works as a software engineer."
}
],
"response_format": {
"type": "json_object"
},
"temperature": 0.5
}
{
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Generate a user profile for a software engineer named Alice"
}
],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "user_profile",
"description": "A user profile object",
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "integer"
},
"occupation": {
"type": "string"
},
"skills": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"name",
"occupation"
]
}
}
},
"temperature": 0.7
}
{
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "What's in this image?"
},
{
"type": "image_url",
"image_url": {
"url": "https://example.com/image.jpg",
"detail": "high"
}
}
]
}
],
"max_tokens": 300
}
{
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Tell me about the weather"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get weather information",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string"
}
},
"required": [
"location"
]
}
}
},
{
"type": "function",
"function": {
"name": "get_time",
"description": "Get current time",
"parameters": {
"type": "object",
"properties": {
"timezone": {
"type": "string"
}
}
}
}
}
],
"tool_choice": {
"type": "function",
"function": {
"name": "get_weather"
}
}
}
{
"model": "grok-4-fast-reasoning",
"messages": [
{
"role": "user",
"content": "Solve this math problem: If a train travels 120 km in 2 hours, then stops for 30 minutes, then travels another 90 km in 1.5 hours, what is the average speed for the entire journey?"
}
],
"max_completion_tokens": 2000,
"reasoning_effort": "high",
"user": "user_12345"
}
{
"model": "gpt-4o-mini-audio",
"messages": [
{
"role": "user",
"content": "Tell me a short story about a robot"
}
],
"modalities": [
"text",
"audio"
],
"audio": {
"voice": "alloy",
"format": "mp3"
},
"max_tokens": 500
}
{
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Check the weather in Tokyo, Paris, and New York simultaneously"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get weather information",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string"
}
},
"required": [
"city"
]
}
}
}
],
"parallel_tool_calls": true,
"temperature": 0.7
}
{
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Explain quantum entanglement in simple terms"
}
],
"temperature": 0.8,
"max_tokens": 300,
"user": "user_abc123",
"metadata": {
"session_id": "session_xyz789",
"conversation_id": "conv_456",
"source": "mobile_app",
"version": "1.2.3"
},
"store": true
}

Successful response

FieldTypeRequiredDescription
idstringYes-
objectstringYes-
createdintegerYes-
modelstringYes-
choicesArray<ChatCompletionChoice>Yes-
usageobjectNo-
system_fingerprintstringNo-
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "gpt-4o-mini",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! I'm doing well, thank you for asking. How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 13,
"completion_tokens": 17,
"total_tokens": 30
}
}
const response = await fetch('https://api.r9s.ai/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Hello, how are you?"
}
]
})
});
const data = await response.json();
console.log(data);
import requests
url = "https://api.r9s.ai/v1/chat/completions"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
response = requests.post(url, json={
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Hello, how are you?"
}
]
}, headers=headers)
data = response.json()
print(data)
Terminal window
curl -X POST "https://api.r9s.ai/v1/chat/completions" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"Hello, how are you?"}]}'
FieldTypeRequiredDescription
modelstringYesModel name
messagesArray<Message>YesMessages list
frequency_penaltynumberNo-
logit_biasobjectNo-
logprobsbooleanNoWhen true, stream must be false (OpenAI constraint)
top_logprobsintegerNo-
max_tokensintegerNo-
nintegerNoNumber of chat completion choices to generate
modalitiesArray<string (text, audio)>NoOutput modality types. Use [“text”, “audio”] for audio output
audioobjectNoAudio output configuration (when modalities includes audio)
presence_penaltynumberNo-
response_formatobjectNo-
seedintegerNo-
service_tierstring (auto, default)No-
stopstringNo-
streambooleanNo-
stream_optionsobjectNo-
temperaturenumberNo-
top_pnumberNo-
top_kintegerNoTop-k sampling parameter (non-OpenAI standard, model-specific)
toolsArray<Tool>No-
tool_choicestring (none, auto, required)No-
parallel_tool_callsbooleanNoWhether to enable parallel function calling during tool use. Only valid when tools are specified.
userstringNoUnique identifier representing end-user for abuse monitoring
reasoning_effortstring (low, medium, high)NoReasoning effort level for o1 series models (low, medium, high)
max_completion_tokensintegerNoMaximum number of tokens to generate in the completion (alternative to max_tokens, more precise)
storebooleanNoWhether to store the output for use in model distillation or evals
metadataobjectNoCustom metadata to attach to the request for tracking purposes
FieldTypeRequiredDescription
rolestring (system, user, assistant, tool)YesMessage role
contentobjectNoMessage content. Can be null when assistant message contains tool_calls.
- user/system messages: Required, contains text or multimodal content
- assistant messages: Optional when tool_calls is present; can be null or omitted
- tool messages: Required, contains tool return results (usually JSON string)
Important: In /v1/responses API, content field must exist and cannot be null.
For /v1/chat/completions, content can be null when tool_calls is present.
namestringNoSender name
reasoning_contentstringNoReasoning content
tool_callsArray<ToolCall>NoTool calls list
tool_call_idstringNoTool call ID
FieldTypeRequiredDescription
typestring (text, image_url)Yes-
textstringNo-
image_urlobjectNo-
FieldTypeRequiredDescription
urlstringYes-
detailstring (auto, low, high)No-
FieldTypeRequiredDescription
idstringYes-
typestringYes-
functionobjectYes-
FieldTypeRequiredDescription
namestringYes-
argumentsstringNo-
FieldTypeRequiredDescription
voicestring (alloy, echo, fable, onyx, nova, shimmer)NoVoice type for audio output
formatstring (mp3, opus, aac, flac, wav, pcm)NoAudio output format
FieldTypeRequiredDescription
typestring (text, json_object, json_schema)No-
json_schemaobjectNo-
FieldTypeRequiredDescription
namestringNo-
descriptionstringNo-
schemaobjectNo-
FieldTypeRequiredDescription
include_usagebooleanNoWhether to include usage statistics
FieldTypeRequiredDescription
typestring (function)YesTool type, currently only supports function
functionobjectYes-
FieldTypeRequiredDescription
idstringYes-
objectstringYes-
createdintegerYes-
modelstringYes-
choicesArray<ChatCompletionChoice>Yes-
usageobjectNo-
system_fingerprintstringNo-
FieldTypeRequiredDescription
indexintegerYes-
messageobjectYes-
finish_reasonstring (stop, length, tool_calls, content_filter)Yes-
logprobsobjectNo-
FieldTypeRequiredDescription
prompt_tokensintegerYesNumber of tokens in the prompt (input)
prompt_tokens_detailsobjectNoDetails about prompt tokens
completion_tokensintegerYesNumber of tokens in the completion (output)
completion_tokens_detailsobjectNoDetails about completion tokens
total_tokensintegerYesTotal number of tokens (prompt + completion)