Create Chat (OpenAI Compatible)

OpenAI-compatible chat completions endpoint for drop-in integration.

POST/v2/chats/openai

OpenAI-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

FieldTypeRequiredDescription
agent_idstringYesAgent public ID (ag_*) or internal ID
messagesarrayYesArray of message objects with role and content
session_idstringNoSession ID for conversation continuity
streambooleanNoEnable 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

On this page