# Integration Guide & Assistant Conventions

Welcome to **Tokenlio Developer Docs**. Tokenlio provides a unified, enterprise-grade AI API gateway compatible with standard OpenAI, Anthropic, and Google protocols.

Access frontier models like `openai/gpt-6-astra`, `anthropic/claude-opus-5.5`, and `deepseek/deepseek-v4-pro` through a single endpoint with automated failover and transparent billing.

---

## Video API

Choose either interface independently. Use the request and response format for the selected API.

### Seedance Native API (v3)

- **Start integrating**: [Quick start](/api/seedance/) · [Request conventions](/api/seedance/conventions) · [Models and inputs](/api/seedance/models)
- **Video generation**: [Create video tasks](/api/seedance/generation) · [Query and manage tasks](/api/seedance/tasks) · [Generation callbacks](/api/seedance/callbacks)
- **Materials and person verification**: [Material groups and assets](/api/seedance/assets) · [Person verification](/api/seedance/verification)
- **Integration and troubleshooting**: [Errors, retries and recovery](/api/seedance/errors) · [Agent integration guide](/api/seedance/agent)

### Unified Video API (v1)

- [Tasks, billing & private downloads](/api/videos)
- [Seedance 2.0](/api/videos/seedance-2-0)
- [Seedance 2.0 Fast](/api/videos/seedance-2-0-fast)
- [Seedance 2.0 Mini](/api/videos/seedance-2-0-mini)
- [Seedance 2.5](/api/videos/seedance-2-5)
- [Grok Imagine Video · Generation & editing](/api/videos/grok-imagine-video)
- [Grok Imagine Video 1.5 · Generation](/api/videos/grok-imagine-video-1-5)
- [Wan 3.0](/api/videos/wan3-0-video)
- [Wan 3.0 Prime](/api/videos/wan3-0-video-prime)
- [HappyHorse 1.0](/api/videos/happyhorse-1-0)
- [HappyHorse 1.1](/api/videos/happyhorse-1-1)
### Image API

- [GPT Image 2.5: image generation and editing](/api/images/gpt-image-2-5)
- [Nano Banana 2.1: generation and reference editing](/api/images/gemini-nano-banana-2-1)
- [Seedream 5.5: generation, transparent PNG and layers](/api/images/seedream-5-5)
- [Seedream 5.0 Flash image API](/api/images/seedream-5-0-flash)
- [Seedream 5.0 Pro image API](/api/images/seedream-5-0-pro)
- [Seedream 5.0 Lite image API](/api/images/seedream-5-0-lite)

## ⚡ Quick Endpoints & Base URLs

| Protocol / Usage | Base URL | Auth Header Format |
| :--- | :--- | :--- |
| **OpenAI Compatible** (`/v1`) | `https://api.tokenlio.ai` | `Authorization: Bearer <TOKENLIO_API_KEY>` |
| **Anthropic Compatible** (`/v1/messages`) | `https://api.tokenlio.ai` | `x-api-key: <TOKENLIO_API_KEY>` or Bearer |
| **Developer Console** | `https://api.tokenlio.ai` | Web session / SSO |
| **Model Marketplace** | `https://api.tokenlio.ai/marketplace` | Publicly browsable |

::: tip HTTP Base URL and SDK configuration are different
For raw HTTP (`curl` / `fetch`), use `https://api.tokenlio.ai` as the Base URL and include `/v1` in each endpoint path. Set OpenAI Python/Node SDK `base_url` / `baseURL` to `https://api.tokenlio.ai/v1` because those SDKs append resource paths. Anthropic SDK / Claude Code uses the origin `https://api.tokenlio.ai` and adds its own versioned path. Do not append the version twice.
:::

---

## 🛠️ Tool & Assistant Setup (Cursor, Claude Code, Windsurf)

You can drop Tokenlio directly into your favorite development tools without custom plugins:

### 1. Cursor IDE Setup
Navigate to **Cursor Settings** ➔ **Models** ➔ **OpenAI API Key**:
1. Check **Override OpenAI Base URL**.
2. Set Base URL: `https://api.tokenlio.ai`
3. Enter your Tokenlio API Key (`sk-tokenlio-...`).
4. Add desired model IDs: `openai/gpt-6-astra`, `anthropic/claude-opus-5.5`, `deepseek/deepseek-v4-pro`.

### 2. Claude Code CLI Setup
In your terminal or `.bashrc` / `.zshrc`:
```bash
export ANTHROPIC_BASE_URL="https://api.tokenlio.ai"
export ANTHROPIC_AUTH_TOKEN="sk-tokenlio-your-key-here"
export ANTHROPIC_MODEL="anthropic/claude-opus-5.5"
```

### 3. Continue / VS Code Setup
In your `~/.continue/config.json`:
```json
{
  "models": [
    {
      "title": "Tokenlio GPT-6 Astra",
      "provider": "openai",
      "model": "openai/gpt-6-astra",
      "apiKey": "sk-tokenlio-your-key",
      "apiBase": "https://api.tokenlio.ai"
    },
    {
      "title": "Tokenlio Claude Opus 5.5",
      "provider": "openai",
      "model": "anthropic/claude-opus-5.5",
      "apiKey": "sk-tokenlio-your-key",
      "apiBase": "https://api.tokenlio.ai"
    }
  ]
}
```

---

## 🚀 SDK Integration Examples

### Python (OpenAI SDK)

```python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.tokenlio.ai/v1",
    api_key=os.environ.get("TOKENLIO_API_KEY", "sk-tokenlio-your-key")
)

# Chat completion with streaming
response = client.chat.completions.create(
    model="openai/gpt-6-astra",
    messages=[
        {"role": "system", "content": "You are an expert systems engineer."},
        {"role": "user", "content": "Explain Anycast routing resilience in 3 sentences."}
    ],
    stream=True
)

for chunk in response:
    content = chunk.choices[0].delta.content or ""
    print(content, end="", flush=True)
print()
```

### Node.js / TypeScript

```typescript
import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://api.tokenlio.ai/v1',
  apiKey: process.env.TOKENLIO_API_KEY || 'sk-tokenlio-your-key',
});

async function main() {
  const stream = await client.chat.completions.create({
    model: 'anthropic/claude-opus-5.5',
    messages: [{ role: 'user', content: 'Generate a TypeScript union validator.' }],
    stream: true,
  });

  for await (const chunk of stream) {
    process.stdout.write(chunk.choices[0]?.delta?.content || '');
  }
}

main();
```

### cURL (Anthropic Messages API Compatible)

```bash
curl https://api.tokenlio.ai/v1/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: sk-tokenlio-your-key" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "anthropic/claude-opus-5.5",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "Hello, Claude via Tokenlio!"}
    ]
  }'
```

---

## 🔍 Context Endpoints for LLMs & Agents

Like modern developer documentation, Tokenlio exposes machine-readable indexes for automated AI agents and web crawlers:

* **`/llms.txt`**: Standard documentation index and routing table for LLM agent discovery.
* **[Model marketplace](https://api.tokenlio.ai/marketplace)**: Real-time publicly accessible model catalog with full context limits, multi-level prompt caching rates, and input/output pricing.

---

## ⚠️ Common Status Codes & Troubleshooting

| HTTP Code | Error Reason | Resolution |
| :--- | :--- | :--- |
| **401 Unauthorized** | Invalid key format or revoked key | Ensure API key begins with `sk-tokenlio-` and is active in your Workspace. |
| **402 Payment Required** | Workspace balance exhausted | Top up your workspace balance in the [Tokenlio Console](https://api.tokenlio.ai). |
| **404 Model Not Found** | Incorrect model ID or unsupported route | Browse [Models Catalog](https://api.tokenlio.ai/marketplace) for exact IDs (e.g. `openai/gpt-6-astra`). |
| **429 Too Many Requests** | Upstream rate limit or concurrency peak | Tokenlio automatically fails over across 28 PoP nodes within 10ms. Retry with backoff if sustained. |

---

## 🧭 Next Steps

- [Video API: Seedance 2.0 & 2.5](/api/videos) — Model parameters, asynchronous tasks, fixed billing and private downloads.

- [Quick Start Guide](/guide/quick-start) - From account signup to first request in 3 minutes.
- [Authentication](/guide/authentication) - Manage API keys, permissions, and team workspace isolation.
- [Models & Pricing Matrix](https://api.tokenlio.ai/marketplace) - Browse all supported models and prompt cache discounts.
