Chat API

Stream conversational AI responses with support for multiple models

Model switching — zero code changes

All 60+ models use the same POST /v1/chat/completions format. Just change the "model" field and your app keeps working.

Available models (60+)

Anthropic (Claude)
claude-opus-4-6claude-sonnet-4-5claude-haiku-4-5
OpenAI
gpt-4.1gpt-4oo3o4-minigpt-4o-mini
Google
gemini-2.5-progemini-2.5-flashgemini-2.0-flash
Meta
llama-4-maverickllama-4-scoutllama-3.3-70b
DeepSeek
deepseek-r1deepseek-v3
Mistral
mistral-large-2mistral-nemo
Others
qwen3-235bamazon-nova-prohosted-<id> (your own GPU tunnel)
POST

https://api.tarqaai.com/api/v1/chat/completions

Request Body
{
  "model": "gemini-2.5-flash",
  "messages": [
    { "role": "system", "content": "You are a helpful assistant." },
    { "role": "user", "content": "Explain quantum mechanics." }
  ],
  "stream": false
}

Response format

200 OK — Non-streaming
{
  "id": "chatcmpl-abc123xyz",
  "object": "chat.completion",
  "created": 1751760000,
  "model": "gemini-2.5-flash",
  "choices": [
    {
      "index": 0,
      "message": { "role": "assistant", "content": "Quantum mechanics is a branch of physics..." },
      "finish_reason": "stop"
    }
  ],
  "usage": { "prompt_tokens": 28, "completion_tokens": 142, "total_tokens": 170 }
}

Streaming (SSE)

Set "stream": true to receive Server-Sent Events. Each event is a JSON delta; the stream ends with [DONE].

Streaming Response — SSE
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}

data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Quantum"},"finish_reason":null}]}

data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":" mechanics"},"finish_reason":null}]}

data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]
Consuming the stream — JavaScript
const response = await fetch(`${BASE_URL}/v1/chat/completions`, {
  method: 'POST',
  headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json' },
  body: JSON.stringify({
    model: 'gemini-2.5-flash',
    messages: [{ role: 'user', content: 'Explain quantum mechanics.' }],
    stream: true,
  }),
});

const reader = response.body.getReader();
const decoder = new TextDecoder();

while (true) {
  const { done, value } = await reader.read();
  if (done) break;

  const lines = decoder.decode(value).split('\n');
  for (const line of lines) {
    if (!line.startsWith('data: ') || line === 'data: [DONE]') continue;
    const chunk = JSON.parse(line.slice(6));
    const text = chunk.choices[0]?.delta?.content ?? '';
    process.stdout.write(text); // or update your UI
  }
}
Features

Real-time streaming · automatic usage tracking and analytics · switch models without changing code · conversation history support