# Quick Start

XRToken is compatible with both OpenAI and Anthropic API formats. Just change `base_url` and `api_key` to get started.

## Endpoints

| Purpose | Full URL | Authentication |
| --- | --- | --- |
| Chat (OpenAI) | `https://YOUR_API_BASE/v1/chat/completions` | `Authorization: Bearer YOUR_API_KEY` |
| Chat (Anthropic) | `https://YOUR_API_BASE/v1/messages` | `x-api-key: YOUR_API_KEY` |
| Web search | `https://YOUR_API_BASE/v1/search` | `Authorization: Bearer YOUR_API_KEY` |
| Doubao Agent | `https://YOUR_API_BASE/v1/agent/chat/completions` | `Authorization: Bearer YOUR_API_KEY` |
| Agent opening / config / events | `https://YOUR_API_BASE/v1/agent/opening-questions` etc. | `Authorization: Bearer YOUR_API_KEY` |
| Model List | `https://YOUR_API_BASE/v1/models` | None required |

The `base_url` format differs by SDK:

- **OpenAI SDK:** `base_url="https://YOUR_API_BASE/v1"` (SDK appends `/chat/completions`)
- **Anthropic SDK:** `base_url="https://YOUR_API_BASE"` (SDK appends `/v1/messages`)

## Python (OpenAI SDK)

```python
from openai import OpenAI

client = OpenAI(
    base_url="https://YOUR_API_BASE/v1",
    api_key="YOUR_API_KEY"
)

response = client.chat.completions.create(
    model="doubao-seed-2.0-pro",
    messages=[{"role": "user", "content": "Hello"}]
)
print(response.choices[0].message.content)

# Streaming
stream = client.chat.completions.create(
    model="doubao-seed-2.0-pro",
    messages=[{"role": "user", "content": "Write a poem"}],
    stream=True
)
for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")
```

## Node.js (OpenAI SDK)

```javascript
import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://YOUR_API_BASE/v1',
  apiKey: 'YOUR_API_KEY',
});

const response = await client.chat.completions.create({
  model: 'doubao-seed-2.0-pro',
  messages: [{ role: 'user', content: 'Hello' }],
});
console.log(response.choices[0].message.content);

// Streaming
const stream = await client.chat.completions.create({
  model: 'doubao-seed-2.0-pro',
  messages: [{ role: 'user', content: 'Write a poem' }],
  stream: true,
});
for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content || '');
}
```

## Python (Anthropic SDK)

```python
import anthropic

client = anthropic.Anthropic(
    base_url="https://YOUR_API_BASE",
    api_key="YOUR_API_KEY"
)

message = client.messages.create(
    model="MiniMax-M2.7",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}]
)
print(message.content[0].text)

# Streaming
with client.messages.stream(
    model="MiniMax-M2.7",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Write a poem"}],
) as stream:
    for text in stream.text_stream:
        print(text, end="")
```

## cURL

**OpenAI format:**

```bash
curl -X POST https://YOUR_API_BASE/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "doubao-seed-2.0-pro",
    "messages": [{"role": "user", "content": "Hello"}],
    "stream": false
  }'
```

**Anthropic format:**

```bash
curl -X POST https://YOUR_API_BASE/v1/messages \
  -H "x-api-key: YOUR_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "MiniMax-M2.7",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Hello"}]
  }'
```

## For agents

Do not paste HTML pages into the chat. Send the prompt below; the agent reads the docs index, then fetches `.md` pages as needed. Append `.md` to any docs URL for that page's Markdown.

```
Read https://xrtoken.ai/llms.txt first. It is the public XRToken API docs index. Fetch the .md links you need; do not assume unlisted endpoints exist.
```
