# Text & Chat APIs (OpenAI / Claude)

Brioi supports both **OpenAI-compatible formats** (Responses and Chat Completions) and the **native Anthropic Claude format** (Messages). Use each model family's native endpoint to preserve reasoning traces, prompt caching, and tool-calling capabilities:

| Model Family | Recommended Endpoint | Why |
|---|---|---|
| GPT series, Kimi, GLM, Grok | `POST /v1/responses` or `POST /v1/chat/completions` | Native support for reasoning controls, tool calling, and context compaction |
| Claude series | `POST /v1/messages` | Full support for extended thinking (`thinking`), Prompt Caching (`cache_control`), and `anthropic-beta` |
| Gemini series | [Gemini Text Models (Native Format)](https://docs.brioi.com/english/2552270m0.md) | Full support for `thinkingConfig`, `responseSchema`, and `thoughtSignature` |

> Available models and group permissions depend on the live `GET /v1/models` response for your API key. Image, video, and TTS models cannot be called through the text endpoints on this page.

## Base URL & Authentication

| Client / SDK | Base URL | Authentication |
|---|---|---|
| Official OpenAI SDK / compatible clients | `https://vip.brioi.com/v1` | `Authorization: Bearer YOUR_API_KEY` |
| Official Anthropic SDK / Claude Code | `https://vip.brioi.com` (**do not** append `/v1`) | `x-api-key: YOUR_API_KEY` or `Authorization: Bearer YOUR_API_KEY` |
| Raw HTTP / cURL | `https://vip.brioi.com` + full path below | Same as the corresponding endpoint |

## OpenAI Responses API (Recommended for GPT)

`POST https://vip.brioi.com/v1/responses` is built for latest-generation GPT reasoning and coding models (such as `gpt-6.2-sol`, `gpt-6.1-sol`, and `gpt-6-astra`), supporting stateful multi-turn continuation, structured outputs, and function tools.

```bash
curl -X POST "https://vip.brioi.com/v1/responses" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-6.1-sol",
    "input": "Summarize zero-knowledge proofs in three sentences",
    "reasoning": { "effort": "medium" }
  }'
```

- **Streaming:** Pass `"stream": true` in the request body to receive a standard SSE event stream.
- **Context compaction:** Supports `POST https://vip.brioi.com/v1/responses/compact` for long-session coding agents such as Codex to compact conversation history.

### OpenAI Python SDK Example

```python
from openai import OpenAI

client = OpenAI(
    base_url="https://vip.brioi.com/v1",
    api_key="YOUR_API_KEY",
)

resp = client.responses.create(
    model="gpt-6.1-sol",
    input="Summarize zero-knowledge proofs in three sentences",
)
print(resp.output_text)
```

## OpenAI Chat Completions API

`POST https://vip.brioi.com/v1/chat/completions` is compatible with general AI apps, translation plugins, and IDE coding assistants.

```bash
curl -X POST "https://vip.brioi.com/v1/chat/completions" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-6.1-sol",
    "messages": [
      { "role": "system", "content": "Reply concisely." },
      { "role": "user", "content": "Give the average and worst-case time complexity of quicksort." }
    ],
    "stream": false
  }'
```

```typescript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://vip.brioi.com/v1",
  apiKey: process.env.BRIOI_API_KEY,
});

const completion = await client.chat.completions.create({
  model: "gpt-6.1-sol",
  messages: [{ role: "user", content: "Hello" }],
});
console.log(completion.choices[0].message.content);
```

## Anthropic Native Messages API

`POST https://vip.brioi.com/v1/messages` implements the Anthropic Messages specification. Authenticate with `x-api-key: YOUR_API_KEY` (paired with `anthropic-version: 2023-06-01`) or `Authorization: Bearer YOUR_API_KEY`; `max_tokens` is required.

```bash
curl -X POST "https://vip.brioi.com/v1/messages" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-5-5",
    "max_tokens": 2048,
    "messages": [
      { "role": "user", "content": "Explain idiomatic usage of context.Context in Go." }
    ]
  }'
```

- **Extended thinking & beta headers:** Supports standard Anthropic `thinking`, explicit Prompt Caching (`cache_control`), and `anthropic-beta` request headers.
- **Token groups:** For coding workflows and Claude Code, choose `Claude | CCMAX | 满血` (full-capability CCMAX), `Claude｜Kiro｜满血` (full-capability Kiro), `Claude | Kiro | 特价` (discounted Kiro), or `auto`. The `Claude｜对话` (chat-only) group is intended strictly for conversational bots and chat plugins and does not support coding tool calls.

### Anthropic Python SDK Example

```python
import anthropic

client = anthropic.Anthropic(
    base_url="https://vip.brioi.com",
    api_key="YOUR_API_KEY",
)

message = client.messages.create(
    model="claude-sonnet-5-5",
    max_tokens=2048,
    messages=[{"role": "user", "content": "Hello"}],
)
print(message.content[0].text)
```

## Using with Claude Code (CLI)

Create an API key on the [Brioi API Keys page](https://vip.brioi.com/keys) under `Claude | CCMAX | 满血`, `Claude｜Kiro｜满血`, or `auto`, then configure Claude Code using either option:

1. **One-click import via CC Switch:** Open the action menu on the right side of your key row, choose **CC Switch**, select **Claude** as the target app, and import and activate the profile.
2. **Write `~/.claude/settings.json` directly:**

```json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://vip.brioi.com",
    "ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY"
  }
}
```

Do not append `/v1` to `ANTHROPIC_BASE_URL`. To configure the Claude Desktop app, see the [Claude Desktop (CC Switch) Setup Guide](https://docs.brioi.com/english/2552268m0.md).

## Common Errors

| HTTP Status | Common Cause & Resolution |
|---:|---|
| `400` | Invalid JSON payload or parameters (for example, omitting `max_tokens` on `/v1/messages`, or passing an image/video model ID to a chat endpoint). |
| `401` | Missing, invalid, or disabled API key. |
| `403` | Insufficient account balance or key quota, or the API key's group does not include the target model. |
| `404` | Malformed endpoint path—most commonly setting `https://vip.brioi.com/v1` in the Anthropic SDK (resulting in `/v1/v1/messages`) or omitting `/v1` in the OpenAI SDK. |
| `429` | Rate limit exceeded; retry with exponential backoff. |
| `503` | Service temporarily unavailable. |
| `500`, `502` | Transient upstream error; if a streaming response drops mid-flight, inspect the `X-Oneapi-Request-Id` header for diagnostics. |

