Chat Completions
Create a chat completion by sending a conversation (a list of messages) to a model. The API is fully compatible with the OpenAI Chat Completions format, so you can use existing OpenAI SDKs and tools by changing the base URL.
Endpoint
POST https://api.dos.ai/v1/chat/completionsAuthentication
Include your API key in the Authorization header using the Bearer scheme:
Authorization: Bearer dos_sk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxAPI keys can be created and managed from the dashboard.
Request Headers
Authorization
Yes
Bearer YOUR_API_KEY
Content-Type
Yes
application/json
Request Body
temperature
number
No
1.0
Sampling temperature between 0 and 2. Lower values produce more focused output; higher values increase randomness.
max_tokens
integer
No
Model default
Maximum number of tokens to generate in the response.
top_p
number
No
1.0
Nucleus sampling parameter. Only tokens within the top top_p probability mass are considered.
stream
boolean
No
false
If true, the response is streamed back as Server-Sent Events (SSE).
stop
string or array
No
null
Up to 4 sequences where the model will stop generating further tokens.
tool_choice
string or object
No
"auto"
Controls which tool the model calls: "auto", "none", or a specific function.
response_format
object
No
null
Force a specific output format. Use {"type": "json_object"} for JSON mode.
frequency_penalty
number
No
0
Penalizes new tokens based on their frequency in the text so far (-2.0 to 2.0).
presence_penalty
number
No
0
Penalizes new tokens based on whether they appear in the text so far (-2.0 to 2.0).
n
integer
No
1
Number of completions to generate for each prompt.
Message Format
Each message in the messages array is an object with the following fields:
role
string
Yes
One of system, user, assistant, or tool.
content
string
Yes
The text content of the message.
name
string
No
An optional name for the participant.
tool_calls
array
No
Tool calls generated by the model (for assistant messages).
tool_call_id
string
No
The ID of the tool call this message responds to (for tool messages).
Response Body
Response Fields
id
string
Unique identifier for the completion.
object
string
Always "chat.completion".
created
integer
Unix timestamp of when the completion was created.
model
string
The model used for the completion.
choices
array
A list of completion choices.
choices[].index
integer
The index of this choice in the list.
choices[].message
object
The generated message.
choices[].finish_reason
string
Why the model stopped: "stop", "length", "tool_calls", or "content_filter".
usage
object
Token usage statistics for the request.
usage.prompt_tokens
integer
Number of tokens in the input prompt.
usage.completion_tokens
integer
Number of tokens in the generated response.
usage.total_tokens
integer
Total tokens (prompt + completion).
Streaming
When stream: true is set, the response is delivered as Server-Sent Events (SSE). Each event contains a JSON chunk:
Each
data:line contains a JSON object with adeltafield instead ofmessage.The
deltacontains incremental content as it is generated.The final chunk includes
finish_reasonandusagestatistics.The stream ends with
data: [DONE].
Tool Calling
You can provide tool (function) definitions that the model can choose to call. This enables agentic workflows where the model can request external actions.
Defining Tools
Tool Call Response
When the model decides to call a tool, the response will have finish_reason: "tool_calls" and include tool call details in the message:
Error Responses
400
Bad Request
Invalid request parameters.
401
Unauthorized
Invalid or missing API key.
402
Payment Required
Insufficient credits.
500
Internal Server Error
Unexpected server error.
503
Service Unavailable
Model temporarily unavailable.
See Error Codes for detailed troubleshooting.
Examples
Basic Chat Completion (cURL)
Streaming (cURL)
Using the OpenAI Python SDK
Since DOS AI is OpenAI-compatible, you can use the official OpenAI SDK by changing the base URL:
Using the OpenAI Node.js SDK
JSON Mode
Tool Calling Example
Last updated