Complete API reference for integrating the AI Gateway into any application.

API Reference

Integrate the AI Gateway into any application using a simple REST API.

Authentication

Every request must include your channel's API key in the
text
X-API-Key
header. Each channel has its own API key — find it on the channel overview card. Keys use the
text
amgai_
prefix and are AES-256 encrypted at rest.
⚠️ Important: Keep your API key secret. Do not expose it in client-side browser code for public-facing sites. Use a backend proxy instead.
http
X-API-Key: amgai_your-channel-key-here

Chat Endpoint

text
POST /api/chat
Send a user message and receive an AI reply. Use a consistent
text
session_id
to maintain conversation history across requests.

Request Body (JSON)

FieldTypeRequiredDescription
text
message
stringYesThe user's message. Max 2,000 characters.
text
session_id
stringYesA unique ID for the user's conversation session. Use the same ID across requests to maintain context. Max 255 characters.
text
metadata
objectNoOptional context passed to the agent.
text
metadata.url
stringNoCurrent page URL.
text
metadata.title
stringNoCurrent page title.

Response (200 OK)

FieldTypeDescription
text
reply
stringThe AI's response message.
text
session_id
stringThe session ID echoed back from your request.
[!TIP] The
text
reply
field often contains Markdown. We recommend using a library like marked or react-markdown to render these correctly.

History Endpoint

text
GET /api/history?session_id={session_id}
Retrieve the full message history for a session. Useful for restoring chat state when a user revisits a page.

Query Parameters

ParameterTypeRequiredDescription
text
session_id
stringYesThe session ID used in
text
/api/chat
requests.

Response (200 OK)

json
{
  "messages": [
    { "role": "user", "content": "Hello!", "created_at": "2026-04-05T10:00:00Z" },
    { "role": "assistant", "content": "Hi! How can I help?", "created_at": "2026-04-05T10:00:01Z" }
  ]
}
Returns
text
{ "messages": [] }
if the session has no history or has expired.

Available Models

Each channel can be configured to use one of the models below. The model is selected when creating or editing a channel and applies to all conversations on that channel.
ModelModel IDContextMax outputSpeedBest For
Llama 3.3 70B
text
llama-3.3-70b-versatile
128K8K~180 TPSGeneral purpose, reasoning
Llama 3.1 70B
text
llama-3.1-70b-versatile
128K8K~150 TPSComplex tasks, code generation
Llama 3.2 90B
text
llama-3.2-90b-text-preview
128K8K~100 TPSLarge context tasks
Mixtral 8x7B
text
mixtral-8x7b-32768
32K32K~200 TPSFast responses, coding
Gemma 2 9B
text
gemma2-9b-it
8K4K~250 TPSLightweight, fast tasks

Code Examples

cURL

bash
curl -X POST https://ai.vindex.ai/api/chat \
  -H "Content-Type: application/json" \
  -H "X-API-Key: amgai_your-channel-key-here" \
  -d '{
    "message": "Hello! What can you help me with?",
    "session_id": "user-session-abc123"
  }'

JavaScript

javascript
const response = await fetch('https://ai.vindex.ai/api/chat', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': 'amgai_your-channel-key-here',
  },
  body: JSON.stringify({
    message: 'Hello! What can you help me with?',
    session_id: 'user-session-abc123',
  }),
});

const data = await response.json();
console.log(data.reply);

Python

python
import requests

response = requests.post(
    'https://ai.vindex.ai/api/chat',
    headers={
        'Content-Type': 'application/json',
        'X-API-Key': 'amgai_your-channel-key-here',
    },
    json={
        'message': 'Hello! What can you help me with?',
        'session_id': 'user-session-abc123',
    },
)

data = response.json()
print(data['reply'])

PHP

php
<?php

$response = file_get_contents('https://ai.vindex.ai/api/chat', false, stream_context_create([
    'http' => [
        'method'  => 'POST',
        'header'  => implode("\r\n", [
            'Content-Type: application/json',
            'X-API-Key: amgai_your-channel-key-here',
        ]),
        'content' => json_encode([
            'message'    => 'Hello! What can you help me with?',
            'session_id' => 'user-session-abc123',
        ]),
    ],
]));

$data = json_decode($response, true);
echo $data['reply'];

Error Responses

All errors return a JSON object with an
text
error
field describing what went wrong.
StatusCauseResponse
401No API key header
text
{ "error": "Missing API key" }
401Wrong or malformed API key
text
{ "error": "Invalid API key" }
403Site disabled
text
{ "error": "Site is inactive" }
403Credits exhausted
text
{ "error": "..." }
429Too many requests (per minute)
text
{ "error": "Rate limit exceeded" }
429Daily quota reached
text
{ "error": "Daily limit exceeded" }
500AI provider error
text
{ "error": "AI service error. Please try again." }

Session Management Tip

Generate a unique
text
session_id
per user session (e.g. a UUID stored in localStorage or a server-side session). The gateway uses this ID to maintain conversation context for up to 24 hours. After that, a new conversation thread will be created automatically.