Chat
The Chat API is used for conversational interactions with AI models.
Endpoint
POST https://ai-tokenhub.ai/api/v1/chat/completionsAuthorizations
BearerAuth
| Name | Type | Required | Description |
|---|---|---|---|
| Authorization | string | Yes | Bearer token authentication. Use your API key or platform auth token; virtual keys (prefixed with sk-bf-) can also be passed here. Format: Bearer $YOUR_API_KEY |
| Content-Type | string | Yes | application/json |
Request Body
application/json
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| model | string | Yes | - | Model identifier, use a model ID supported by the platform Example: "dola-seed-2-1-turbo-260628" |
| messages | object[] | Yes | - | Array of conversation messages |
| fallbacks | string[] | No | - | Fallback model list, use model IDs |
| stream | boolean | No | false | Enable streaming response |
| temperature | number | No | 0.7 | Generation temperature, range: -2 <= x <= 2 |
| frequency_penalty | number | No | 0 | Frequency penalty, range: -2 <= x <= 2 |
| presence_penalty | number | No | 0 | Presence penalty, range: -2 <= x <= 2 |
| max_tokens | integer | No | - | Maximum tokens to generate |
| max_completion_tokens | integer | No | - | Maximum completion tokens |
| logit_bias | object | No | - | Token vocabulary bias settings |
| logprobs | boolean | No | false | Whether to return token probabilities |
| metadata | object | No | - | User-defined metadata |
| modalities | string[] | No | ["text"] | Response modality types |
| parallel_tool_calls | boolean | No | true | Enable parallel tool calls |
| prompt_cache_key | string | No | - | Custom key for semantic cache |
| stop | array/string | No | - | Stop sequences |
| user | string | No | - | User identifier |
Messages Format
json
{
"messages": [
{
"role": "system",
"content": "You are a professional assistant"
},
{
"role": "user",
"content": "Please introduce yourself"
}
]
}Role Types
system: System role, used to set AI behavioruser: User role, the user's inputassistant: Assistant role, the AI's reply
Request Example
bash
curl https://ai-tokenhub.ai/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $YOUR_API_KEY" \
-d '{
"model": "dola-seed-2-1-turbo-260628",
"messages": [
{"role": "user", "content": "Hello, how are you?"}
],
"temperature": 0.7,
"max_tokens": 100
}'python
from openai import OpenAI
client = OpenAI(
api_key="$YOUR_API_KEY",
base_url="https://ai-tokenhub.ai/api/v1"
)
response = client.chat.completions.create(
model="dola-seed-2-1-turbo-260628",
messages=[
{"role": "user", "content": "Hello, how are you?"}
],
temperature=0.7,
max_tokens=100
)
print(response.choices[0].message.content)javascript
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: '$YOUR_API_KEY',
baseURL: 'https://ai-tokenhub.ai/api/v1'
});
const response = await client.chat.completions.create({
model: 'dola-seed-2-1-turbo-260628',
messages: [
{ role: 'user', content: 'Hello, how are you?' }
],
temperature: 0.7,
max_tokens: 100
});
console.log(response.choices[0].message.content);Response Example
json
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1677858242,
"model": "dola-seed-2-1-turbo-260628",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! I'm doing well, thank you for asking."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 20,
"total_tokens": 30
}
}Streaming Response
Enable stream: true for Server-Sent Events format.
Error Codes
| Code | Description |
|---|---|
| 400 | Invalid request parameters |
| 401 | Invalid API Key |
| 403 | No permission to access this model |
| 429 | Rate limit exceeded |
| 500 | Internal server error |
| 503 | Service unavailable |
Use Cases
- Customer Service: Automated responses
- Content Creation: Writing assistance
- Code Assistant: Programming help
- Education: Tutoring and feedback
