API reference
Create chat completion
POST /v1/chat/completions generates the next assistant message for a conversation, as JSON or as a stream.
Generates the next assistant message for a conversation, in the OpenAI Chat Completions format. Supports streaming, tool calling, and JSON output.
Request body
modelstringrequiredModel ID. The only accepted value is
deepseek-flash.messagesarrayrequiredThe conversation so far, oldest first.
rolestringrequiredsystem,user,assistant, ortool.contentstring | array | nullrequiredThe message text, or an array of
{"type": "text"}parts. Image parts are rejected with400 unsupported_content. May benullon an assistant message that only carriestool_calls.tool_callsarrayOn an
assistantmessage: the tool calls the model made, sent back unchanged.tool_call_idstringOn a
toolmessage: theidof the tool call this result answers.
max_tokensintegerOutput cap, 1 to 384,000. Defaults to 8,192 when omitted. A larger value is rejected with
400 max_tokens_exceeded, never silently reduced. Reasoning tokens count toward it.max_completion_tokensintegerAlias of
max_tokens. If you send both, the smaller value applies.streambooleanSend the response as Server-Sent Events. Defaults to
false.stream_optionsobjectStreaming options.
include_usagebooleanSend a final chunk with token usage before
[DONE].
toolsarrayFunction definitions the model may call:
{"type": "function", "function": {name, description, parameters}}.tool_choicestring | objectauto,none,required, or a specific function.response_formatobject{"type": "json_object"}makes the model return a valid JSON object.temperature, top_p, stop, presence_penalty, frequency_penalty—Sampling parameters, forwarded to the model unchanged.
Example request
curl https://api.larasrouter.com/v1/chat/completions \
-H "Authorization: Bearer $LARAS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-flash",
"messages": [
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "Name three uses of a hash map."}
],
"max_tokens": 1024
}'
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.larasrouter.com/v1",
api_key=os.environ["LARAS_API_KEY"],
)
response = client.chat.completions.create(
model="deepseek-flash",
messages=[
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "Name three uses of a hash map."},
],
max_tokens=1024,
)
print(response.choices[0].message.content)
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.larasrouter.com/v1",
apiKey: process.env.LARAS_API_KEY,
});
const response = await client.chat.completions.create({
model: "deepseek-flash",
messages: [
{ role: "system", content: "You are a concise assistant." },
{ role: "user", content: "Name three uses of a hash map." },
],
max_tokens: 1024,
});
console.log(response.choices[0].message.content);
Response body
idstringCompletion ID.
objectstringchat.completion, orchat.completion.chunkfor stream chunks.createdintegerUnix timestamp in seconds.
modelstringThe model that answered.
choicesarrayOne choice.
message.contentstring | nullThe answer text.
message.reasoning_contentstring | nullThe model’s reasoning, when it produced any. Billed as output.
message.tool_callsarrayTool calls the model wants you to run.
finish_reasonstringstop,length(output cap reached), ortool_calls.
usageobjectToken counts the charge is computed from.
prompt_tokensintegerAll input tokens.
prompt_cache_hit_tokensintegerInput tokens served from cache, billed at $0.010 / 1M.
prompt_cache_miss_tokensintegerInput tokens not in cache, billed at $0.400 / 1M.
completion_tokensintegerOutput tokens, reasoning included, billed at $1.600 / 1M.
total_tokensintegerInput plus output.
{
"id": "chatcmpl-…",
"object": "chat.completion",
"created": 1760241600,
"model": "deepseek-flash",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "1. Caching results by key…",
"reasoning_content": "The user wants three uses…"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 24,
"completion_tokens": 180,
"total_tokens": 204,
"prompt_cache_hit_tokens": 0,
"prompt_cache_miss_tokens": 24
}
}
Streaming
With "stream": true the response is a stream of chat.completion.chunk events, ending with data: [DONE]. Set stream_options.include_usage to receive token usage in a final chunk. See Streaming.
data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant","content":""}}]}
data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"1. Caching"}}]}
data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[],"usage":{"prompt_tokens":24,"completion_tokens":180,"total_tokens":204,"prompt_cache_hit_tokens":0,"prompt_cache_miss_tokens":24}}
data: [DONE]
Responses
stream is true.X-Laras-Request-IDstring — Billing identity of the request (UUID). Quote it when you contact support about a charge.
| Code | Type | Meaning |
|---|---|---|
invalid_request | invalid_request_error | The body is not valid JSON or names no model. |
max_tokens_exceeded | invalid_request_error | max_tokens or max_completion_tokens is above 384,000. |
unsupported_content | invalid_request_error | A message contains an image or another non-text part. |
| Code | Type | Meaning |
|---|---|---|
invalid_api_key | invalid_request_error | The key is missing, malformed, revoked, or unknown. |
| Code | Type | Meaning |
|---|---|---|
insufficient_credit | insufficient_quota | Available balance is $0.00 or below. Top up. |
key_budget_exceeded | insufficient_quota | The request would take the key past its monthly budget. |
chat:write scope.| Code | Type | Meaning |
|---|---|---|
insufficient_scope | insufficient_permissions | The key cannot call this endpoint. |
| Code | Type | Meaning |
|---|---|---|
model_not_found | invalid_request_error | Use deepseek-flash. |
| Code | Type | Meaning |
|---|---|---|
request_too_large | invalid_request_error | Trim the conversation or tool output. |
Retry-After.Retry-Afterinteger — Seconds to wait before retrying.
| Code | Type | Meaning |
|---|---|---|
rate_limit_exceeded | rate_limit_exceeded | More than 300 requests in a minute on this key. |
concurrency_limit_exceeded | rate_limit_exceeded | More than 16 requests in flight on this key. |
| Code | Type | Meaning |
|---|---|---|
provider_unavailable | api_error | Retry with backoff. |
| Code | Type | Meaning |
|---|---|---|
billing_unavailable | api_error | Retry later. You were not charged. |