# Tổng quan API

> URL cơ sở, cách xác thực và ví dụ tích hợp nhanh bằng Python, Node.js, curl cho API LLMoxy.

LLMoxy cung cấp giao diện Anthropic Messages API hoàn toàn tương thích. Chỉ cần thay đổi URL cơ sở là có thể sử dụng SDK chính thức ngay lập tức.

## URL cơ sở

```txt
https://llmoxy.com/v1
```

> **MẸO**
> Các công cụ như Claude Code sử dụng địa chỉ **không có** `/v1`, tức là `https://llmoxy.com`. Khi gọi SDK thì có `/v1`.

## Cách xác thực

### Cách 1: x-api-key (khuyến nghị)

```http
x-api-key: YOUR_API_KEY
```

### Cách 2: Authorization

```http
Authorization: Bearer YOUR_API_KEY
```

## Trải nghiệm nhanh

### Python

```python
from anthropic import Anthropic

client = Anthropic(
api_key="YOUR_API_KEY",
base_url="https://llmoxy.com/v1"
)

message = client.messages.create(
model="claude-opus-5-5",
max_tokens=1024,
messages=[
{"role": "user", "content": "Xin chào!"}
]
)

print(message.content[0].text)
```

### Node.js

```js
import Anthropic from '@anthropic-ai/sdk';

const client = new Anthropic({
apiKey: 'YOUR_API_KEY',
baseURL: 'https://llmoxy.com/v1'
});

const message = await client.messages.create({
model: 'claude-opus-5-5',
max_tokens: 1024,
messages: [
{ role: 'user', content: 'Xin chào!' }
]
});

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

### Tương thích OpenAI (Chat Completions)

#### curl

```bash
curl https://llmoxy.com/v1/chat/completions \
  -H "Authorization: Bearer <LLMOXY_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-4.7",
    "messages": [
      { "role": "user", "content": "Say hello in one short sentence." }
    ]
  }'
```

#### TypeScript

```ts
import OpenAI from "openai";

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

const response = await client.chat.completions.create({
  model: "grok-4.7",
  messages: [{ role: "user", content: "Write a haiku about routers." }],
});

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

#### Python

```py
from openai import OpenAI

client = OpenAI(
    api_key="<LLMOXY_API_KEY>",
    base_url="https://llmoxy.com/v1",
)

response = client.chat.completions.create(
    model="grok-4.7",
    messages=[{"role": "user", "content": "Write a haiku about routers."}],
)

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

## Đầu ra luồng

Đặt `stream: true` trong yêu cầu Chat hoặc Responses, LLMoxy sẽ trả về luồng SSE tương thích OpenAI.

```bash
curl https://llmoxy.com/v1/chat/completions \
  -H "Authorization: Bearer <LLMOXY_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-4.7",
    "stream": true,
    "messages": [
      { "role": "user", "content": "Count from one to five." }
    ]
  }'
```

## Các mô hình được hỗ trợ

### Dòng Claude (nhóm khả dụng: Claude)

| Mô hình | Mô tả |
| --- | --- |
| claude-fable-5-2 | Hiệu năng mạnh nhất |
| claude-opus-5-5 | Lựa chọn cân bằng |

### Dòng Gemini (nhóm khả dụng: Gemini)

| Mô hình | Mô tả |
| --- | --- |
| gemini-4-argon | Hiệu năng mạnh nhất |
| gemini-3.8-flash | Phản hồi nhanh |

> **Danh sách mô hình mới nhất**
> Các mô hình khả dụng cụ thể vui lòng tham khảo [Quảng trường mô hình chính thức](https://llmoxy.com/).

## Cách tính phí

Tính phí theo lượng token thực tế đã dùng (bao gồm ghi và đọc bộ nhớ đệm), giá khác nhau tùy mô hình. Xem chi tiết tại [Nhóm và định giá](https://vi.llmoxy.com/docs/get-started/recharge-and-pricing).

## Bước tiếp theo

- [Tài liệu chi tiết định dạng Anthropic](https://vi.llmoxy.com/docs/api-reference/anthropic-format) — tham số yêu cầu, định dạng phản hồi, ví dụ mã
- [Chat Completions](https://vi.llmoxy.com/docs/api-reference/chat-completions) — định dạng yêu cầu tương thích OpenAI
- [Định tuyến, tính phí và lỗi](https://vi.llmoxy.com/docs/api-reference/routing-billing-errors) — tìm hiểu phí và mã lỗi

Đây là bản markdown của https://vi.llmoxy.com/docs/api-reference/api-overview.
