Create Chat (OpenAI Compatible)
OpenAI-compatible chat completions endpoint for drop-in integration.
POST
/v2/chats/openaiOpenAI-compatible chat completions. Redirects to /v1/chat/completions.
No parameters for this endpoint.
Overview
This endpoint provides OpenAI-compatible chat completions, allowing you to use thinnestAI agents as a drop-in replacement for OpenAI's API. It redirects to POST /v1/chat/completions.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
agent_id | string | Yes | Agent public ID (ag_*) or internal ID |
messages | array | Yes | Array of message objects with role and content |
session_id | string | No | Session ID for conversation continuity |
stream | boolean | No | Enable SSE streaming (default: false) |
Message Object
| Field | Type | Description |
|---|---|---|
role | string | system, user, or assistant |
content | string | Message content |
Response 200
{
"id": "chatcmpl-abc123",
"agent_id": "ag_5d2678fd_e556",
"session_id": "sess_xyz789",
"content": "Hello! How can I help you today?",
"usage": {
"prompt_tokens": 25,
"completion_tokens": 10,
"total_tokens": 35
}
}Streaming Response
When stream: true, returns Server-Sent Events:
data: {"type": "content", "data": "Hello"}
data: {"type": "content", "data": "! How can"}
data: {"type": "content", "data": " I help you?"}
data: {"type": "done", "session_id": "sess_xyz789", "metrics": {...}}SDK Usage
Python (OpenAI SDK)
from openai import OpenAI
client = OpenAI(
base_url="https://api.thinnest.ai/v1",
api_key="ak_your_agent_api_key"
)
response = client.chat.completions.create(
model="ag_5d2678fd_e556", # agent_id as model
messages=[
{"role": "user", "content": "Hello!"}
]
)
print(response.choices[0].message.content)JavaScript (OpenAI SDK)
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://api.thinnest.ai/v1',
apiKey: 'ak_your_agent_api_key',
});
const response = await client.chat.completions.create({
model: 'ag_5d2678fd_e556',
messages: [{ role: 'user', content: 'Hello!' }],
});
console.log(response.choices[0].message.content);Errors
| Code | Description |
|---|---|
401 | Missing or invalid API key |
402 | Insufficient balance |
404 | Agent not found |
429 | Rate limit exceeded |