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 header. Each channel has its own API key — find it on the channel overview card. Keys use the prefix and are AES-256 encrypted at rest.
text
text
⚠️ 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
Chat Endpoint
text
Send a user message and receive an AI reply. Use a consistent to maintain conversation history across requests.
text
Request Body (JSON)
| Field | Type | Required | Description |
|---|---|---|---|
text | string | Yes | The user's message. Max 2,000 characters. |
text | string | Yes | A unique ID for the user's conversation session. Use the same ID across requests to maintain context. Max 255 characters. |
text | object | No | Optional context passed to the agent. |
text | string | No | Current page URL. |
text | string | No | Current page title. |
Response (200 OK)
| Field | Type | Description |
|---|---|---|
text | string | The AI's response message. |
text | string | The session ID echoed back from your request. |
[!TIP] Thefield often contains Markdown. We recommend using a library like marked or react-markdown to render these correctly.text
History Endpoint
text
Retrieve the full message history for a session. Useful for restoring chat state when a user revisits a page.
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
text | string | Yes | The session ID used in text |
Response (200 OK)
json
Returns if the session has no history or has expired.
text
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.
| Model | Model ID | Context | Max output | Speed | Best For |
|---|---|---|---|---|---|
| Llama 3.3 70B | text | 128K | 8K | ~180 TPS | General purpose, reasoning |
| Llama 3.1 70B | text | 128K | 8K | ~150 TPS | Complex tasks, code generation |
| Llama 3.2 90B | text | 128K | 8K | ~100 TPS | Large context tasks |
| Mixtral 8x7B | text | 32K | 32K | ~200 TPS | Fast responses, coding |
| Gemma 2 9B | text | 8K | 4K | ~250 TPS | Lightweight, fast tasks |
Code Examples
cURL
bash
JavaScript
javascript
Python
python
PHP
php
Error Responses
All errors return a JSON object with an field describing what went wrong.
text
| Status | Cause | Response |
|---|---|---|
| 401 | No API key header | text |
| 401 | Wrong or malformed API key | text |
| 403 | Site disabled | text |
| 403 | Credits exhausted | text |
| 429 | Too many requests (per minute) | text |
| 429 | Daily quota reached | text |
| 500 | AI provider error | text |
Session Management Tip
Generate a unique 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.
text