curl -X POST https://api.thinnest.ai/v2/chats/openai \
-H "Authorization: Bearer $THINNESTAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"agent_id": "ag_5d2678fd_e556",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello!"
}
],
"stream": false
}'
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
Agent public ID (ag_*) or internal ID
Array of message objects with role and content
Session ID for conversation continuity
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 |