Skip to main content
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_id
string
required
Agent public ID (ag_*) or internal ID
messages
array
required
Array of message objects with role and content
session_id
string
Session ID for conversation continuity
stream
boolean
Enable SSE streaming (default: false)

Message Object

FieldTypeDescription
rolestringsystem, user, or assistant
contentstringMessage 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

CodeDescription
401Missing or invalid API key
402Insufficient balance
404Agent not found
429Rate limit exceeded