---
title: "API reference"
description: "Current inference gateway contract, authentication, and response conventions."
date: "2026-11-20"
modified: "2026-11-20"
reviewed: "2026-11-20"
---

# API reference

> Current inference gateway contract, authentication, and response conventions.

Published on: 2026-11-20

Last updated on: 2026-11-20

This page covers the **current public inference surface** that is backed by the app as of **Wednesday, July 22, 2026**.

Today, the supported contract is the **OpenAI-compatible memory inference gateway** plus the agent-scoped inference variant.

## Machine-Readable Resources

Agents and developer tools can discover Achiral's API surface from:

- [OpenAPI specification](https://achiral.ai/openapi.json)
- [Well-known OpenAPI description](https://achiral.ai/.well-known/achiral-memory-api-openapi.json)
- [API catalog](https://achiral.ai/.well-known/api-catalog)
- [Auth.md agent authentication discovery](https://achiral.ai/auth.md)
- [LLM index](https://achiral.ai/llms.txt)
- [Achiral CLI](https://www.npmjs.com/package/@achiral/cli)
- [Achiral CLI source](https://github.com/Achiral-AI/achiral.cli)
- [Authenticated MCP server](https://mcp.achiral.ai)
- [MCP discovery endpoint](https://mcp.achiral.ai/mcp)
- [Well-known MCP manifest](https://mcp.achiral.ai/.well-known/achiral-mcp.json)
- [MCP public tool schemas](https://mcp.achiral.ai/.well-known/achiral-mcp-tools.json)
- [MCP protected resource metadata](https://mcp.achiral.ai/.well-known/oauth-protected-resource)

## Base URL

Use your organization's workspace endpoint for memory-aware inference, for example:

- `https://your-org-slug.achiral.ai/v1`

The product also exposes a memory endpoint to admins when they create **Context Access Tokens**.

Custom domains use the same `/v1` path on the approved hostname when custom-domain setup is active.

## Authentication

Authenticate requests with a **Context Access Token**.

Use the token in the Authorization header:

```bash
export ACHIRAL_TOKEN="acm_..."
curl https://your-org-slug.achiral.ai/v1/models \
  -H "Authorization: Bearer $ACHIRAL_TOKEN"
```

Context Access Tokens are created by an **owner or admin** in the organization settings UI.

The current token scopes exposed in the product are:

- `knowledge:read`
- `insights:read`
- `actions:request`
- `inference:chat`

For the inference routes on this page, the token needs the `inference:chat` scope.

## Rate Limiting

API requests are rate-limited based on your plan and, where applicable, the credential's [Memory API environment](/docs/memory/api/environments):

| Plan bucket     | Limit model                       |
| --------------- | --------------------------------- |
| Free            | Lowest message and storage limits |
| Spark           | Small-team paid limits            |
| Seed / Rise     | Higher message and storage limits |
| Boost and above | Contract-specific API limits      |

Your actual limits may also include abuse controls, contract limits, per-route limits, and organization-specific overrides. Provisional environment limits are not public API entitlements.

### Rate Limit Headers

Environment-aware API responses use standard rate-limit fields:

| Header                | Meaning                                         |
| --------------------- | ----------------------------------------------- |
| `RateLimit-Limit`     | Request limit for the applicable policy window. |
| `RateLimit-Remaining` | Requests remaining in the current window.       |
| `RateLimit-Reset`     | Seconds until the current window resets.        |

Some existing routes may continue to return the legacy `X-RateLimit-Limit`, `X-RateLimit-Remaining`, and `X-RateLimit-Reset` names during migration. Clients should prefer the standard fields when both are present.

### Exceeding Limits

When rate limited, you receive `429 Too Many Requests`. The `Retry-After` response header gives the minimum number of seconds to wait before retrying. The response body may repeat that value for client convenience:

```http
HTTP/1.1 429 Too Many Requests
Retry-After: 30
Content-Type: application/json

{
  "error": {
    "message": "Rate limit exceeded",
    "type": "rate_limit_error",
    "retry_after": 30
  }
}
```

Do not retry before `Retry-After`. Apply exponential backoff with jitter when repeated requests remain limited.

## Inference API

### Chat Completions

OpenAI-compatible chat completions endpoint for organization-scoped memory inference.

**Endpoint**: `POST /v1/chat/completions`

```bash
curl https://your-org-slug.achiral.ai/v1/chat/completions \
  -H "Authorization: Bearer $ACHIRAL_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "chiro",
    "messages": [
      {"role": "user", "content": "Summarize what changed in our workspace today."}
    ],
    "temperature": 0.7,
    "max_tokens": 500
  }'
```

**Response**:

```json
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1699564800,
  "model": "chiro",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Machine learning is a subset of artificial intelligence..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 150,
    "total_tokens": 175
  }
}
```

### Agent-scoped Chat Completions

Use the agent-scoped route when you want the request to run inside a specific agent boundary.

**Endpoint**: `POST /v1/agents/{agentSlug}/chat/completions`

```bash
curl https://your-org-slug.achiral.ai/v1/agents/release-readiness/chat/completions \
  -H "Authorization: Bearer $ACHIRAL_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "chiro",
    "messages": [
      {"role": "user", "content": "Prepare the next rollout review with prior migration context."}
    ]
  }'
```

You may also see agent-scoped examples in the app that use the `X-Achiral-Agent` header.

### Request Parameters

#### Common Parameters

| Parameter           | Type    | Description                        | Default  |
| ------------------- | ------- | ---------------------------------- | -------- |
| `model`             | string  | Model identifier                   | Required |
| `temperature`       | float   | Sampling temperature (0-2)         | 1.0      |
| `max_tokens`        | integer | Maximum tokens to generate         | 2048     |
| `top_p`             | float   | Nucleus sampling threshold         | 1.0      |
| `frequency_penalty` | float   | Penalize repeated tokens (-2 to 2) | 0.0      |
| `presence_penalty`  | float   | Penalize token presence (-2 to 2)  | 0.0      |
| `stop`              | array   | Stop sequences                     | null     |
| `stream`            | boolean | Stream response tokens             | false    |

## Streaming API

The current inference gateway supports streaming on the chat completions route.

### Server-Sent Events

Stream responses using SSE:

```bash
curl https://your-org-slug.achiral.ai/v1/chat/completions \
  -H "Authorization: Bearer $ACHIRAL_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "chiro",
    "messages": [{"role": "user", "content": "Hello!"}],
    "stream": true
  }'
```

**Response**:

```http
data: {"id":"chatcmpl-123","choices":[{"delta":{"content":"Hello"}}]}

data: {"id":"chatcmpl-123","choices":[{"delta":{"content":"!"}}]}

data: {"id":"chatcmpl-123","choices":[{"delta":{"content":" How"}}]}

data: [DONE]
```

### JavaScript Example

```javascript
const response = await fetch(
  "https://your-org-slug.achiral.ai/v1/chat/completions",
  {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.ACHIRAL_TOKEN}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      model: "chiro",
      messages: [{ role: "user", content: "Hello!" }],
      stream: true,
    }),
  },
);

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

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

  const chunk = decoder.decode(value);
  const lines = chunk.split("\n").filter((line) => line.trim());

  for (const line of lines) {
    if (line.startsWith("data: ")) {
      const data = line.slice(6);
      if (data === "[DONE]") break;
      const json = JSON.parse(data);
      console.log(json.choices[0].delta.content);
    }
  }
}
```

## Model Management

### List Models

**Endpoint**: `GET /v1/models`

```bash
curl https://your-org-slug.achiral.ai/v1/models \
  -H "Authorization: Bearer $ACHIRAL_TOKEN"
```

**Response**:

```json
{
  "object": "list",
  "data": [
    {
      "id": "chiro",
      "object": "model",
      "created": 1699564800,
      "owned_by": "achiral",
      "context_length": 8192
    }
  ]
}
```

The gateway currently advertises a single client-facing model id: `chiro`.

## Health Check

Use the health route for a basic liveness check.

**Endpoint**: `GET /v1/health`

```bash
curl https://your-org-slug.achiral.ai/v1/health
```

## Error Handling

### Error Response Format

```json
{
  "error": {
    "message": "Invalid API key",
    "type": "authentication_error",
    "code": "invalid_api_key"
  }
}
```

### HTTP Status Codes

| Code | Description                                           |
| ---- | ----------------------------------------------------- |
| 200  | Success                                               |
| 400  | Bad Request - Invalid parameters                      |
| 401  | Unauthorized - Invalid or missing API key             |
| 403  | Forbidden - Insufficient permissions                  |
| 404  | Not Found - Resource doesn't exist                    |
| 429  | Too Many Requests - Rate limit exceeded               |
| 500  | Internal Server Error                                 |
| 503  | Service Unavailable - Service temporarily unavailable |

### Error Types

- `authentication_error`: Invalid API key
- `authorization_error`: Insufficient permissions
- `invalid_request_error`: Invalid parameters
- `rate_limit_error`: Rate limit exceeded
- `model_error`: Model loading or inference error
- `server_error`: Internal server error

## SDK Examples

### Python (OpenAI SDK)

```python
import os

from openai import OpenAI

client = OpenAI(
    api_key=os.environ["ACHIRAL_TOKEN"],
    base_url="https://your-org-slug.achiral.ai/v1"
)

response = client.chat.completions.create(
    model="chiro",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hello!"}
    ]
)

print(response.choices[0].message.content)
```

### Node.js

```javascript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.ACHIRAL_TOKEN,
  baseURL: "https://your-org-slug.achiral.ai/v1",
});

const response = await client.chat.completions.create({
  model: "chiro",
  messages: [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user", content: "Hello!" },
  ],
});

console.log(response.choices[0].message.content);
```

### cURL

```bash
curl https://your-org-slug.achiral.ai/v1/chat/completions \
  -H "Authorization: Bearer $ACHIRAL_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "chiro",
    "messages": [
      {"role": "user", "content": "Hello!"}
    ]
  }'
```

## Continue from here

- [Custom domains](/docs/organization/custom-domains): review hosted custom-domain setup.
- [Getting Started](/docs/getting-started/): set up the workspace before making the first API call.
- [Memory API](/docs/memory/api): see the broader memory-related surface.
- [Agents](/docs/agents): use agent-scoped memory and runtime calls.

## Learn more

- Explore Features: https://achiral.ai/features
- View Pricing: https://achiral.ai/pricing
