API reference
Chat Completions
Chat Completions is the platform's most commonly used endpoint for multi-turn conversations and text generation. It is fully compatible with the OpenAI API format and can be called through the official SDK.
Endpoint address
POST https://api.yomiapi.com/v1/chat/completions
Request headers:
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
Request parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model ID, such as deepseek-v4-flash, claude-sonnet-5 |
messages | array | Yes | Message array containing the conversation history |
temperature | number | No | Sampling temperature from 0 to 2; default 1 |
max_tokens | number | No | Maximum number of generated tokens |
stream | boolean | No | Whether to stream output; default false |
top_p | number | No | Nucleus-sampling parameter from 0 to 1 |
The endpoint also supports the remaining standard OpenAI Chat Completions parameters (such as stop, frequency_penalty). Include them as needed.
messages format
Each message contains role and content.system defines the AI's role and behavior, user is user input, and assistant contains previous model replies:
[
{"role": "system", "content": "You are a helpful assistant"},
{"role": "user", "content": "Hello"},
{"role": "assistant", "content": "Hello! How can I help you?"},
{"role": "user", "content": "Please introduce yourself"}
]
Code examples
Python
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.yomiapi.com/v1"
)
response = client.chat.completions.create(
model="deepseek-v4-flash",
messages=[
{"role": "system", "content": "You are a helpful assistant"},
{"role": "user", "content": "Hello, please introduce yourself"}
],
temperature=0.7,
max_tokens=1000
)
print(response.choices[0].message.content)
Node.js
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'YOUR_API_KEY',
baseURL: 'https://api.yomiapi.com/v1'
});
async function main() {
const response = await client.chat.completions.create({
model: 'deepseek-v4-flash',
messages: [
{ role: 'system', content: 'You are a helpful assistant' },
{ role: 'user', content: 'Hello, please introduce yourself' }
],
temperature: 0.7,
max_tokens: 1000
});
console.log(response.choices[0].message.content);
}
main();
cURL
curl https://api.yomiapi.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "deepseek-v4-flash",
"messages": [
{"role": "system", "content": "You are a helpful assistant"},
{"role": "user", "content": "Hello, please introduce yourself"}
],
"temperature": 0.7,
"max_tokens": 1000
}'
Response format
{
"id": "chatcmpl-xxx",
"object": "chat.completion",
"created": 1234567890,
"model": "deepseek-v4-flash",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! I am an AI assistant..."
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 100,
"total_tokens": 125
}
}
The reply is in choices[0].message.content;finish_reason is stop indicates normal completion, while length indicates truncation at the max_tokens limit.
usage contains the token counts used for billing. Input and output tokens are charged separately, with prices varying by model. Record usage in your application to reconcile usage.Streaming output
Set stream: true to receive incremental responses in Server-Sent Events (SSE) format:
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","choices":[{"delta":{"content":"Hello"}}]}
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","choices":[{"delta":{"content":" world"}}]}
data: [DONE]
When using the SDK, read each increment:
response = client.chat.completions.create(
model="deepseek-v4-flash",
messages=[{"role": "user", "content": "Write a poem"}],
stream=True
)
for chunk in response:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
Multimodal input
Multimodal models (such as claude-sonnet-5, gpt-5.6-sol) can receive a mix of text, images and other content parts in content, using the same /v1/chat/completions endpoint described here. See Image understanding (vision) and Video understanding for the exact format.
Recommendations
- System prompt: Use the
systemrole to set the AI's identity, tone and output format. This is more stable than repeating the requirements in everyusermessage. - Context management: Include historical messages in multi-turn conversations. Trim or summarize older content when the conversation grows long to save tokens.
- Streaming: For long text generated for end users, enable
streamto substantially reduce time to first token. - Error handling: See API overview and authentication for error codes and retry strategies.
