> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dimilinks.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 快速开始

> 5 分钟跑通一次 Claude 对话调用。

本页用一次 `chat/completions` 调用做最小演示。把示例里的模型名换成图片或视频模型，就能切换到对应的 API。

## 1. 准备 API Key

在控制台创建一把 Bearer 密钥，保存为环境变量。所有请求都从服务端发起，不要把密钥放进浏览器或客户端安装包。

```bash theme={null}
export DIMILINKS_API_KEY="sk-..."
```

```http theme={null}
Authorization: Bearer <DIMILINKS_API_KEY>
Content-Type: application/json
```

## 2. 调用 Claude 对话（OpenAI 兼容入口）

```bash theme={null}
curl "https://dimilinks.com/v1/chat/completions" \
  -H "Authorization: Bearer $DIMILINKS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-6",
    "messages": [
      {"role": "system", "content": "你是一个简洁的中文助手。"},
      {"role": "user", "content": "用一句话解释什么是冥王星。"}
    ]
  }'
```

返回（节选）：

```json theme={null}
{
  "id": "chatcmpl_xxx",
  "object": "chat.completion",
  "model": "claude-sonnet-4-6",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "冥王星是太阳系外缘的一颗矮行星，曾被列为第九大行星。"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 32,
    "completion_tokens": 24,
    "total_tokens": 56
  }
}
```

把 `model` 换成 `gpt-5.5`、`gpt-5.4-mini`、`grok-4.20-fast` 等，就可以调用其他文本模型；密钥不变。

## 3. 用 Anthropic 原生协议（推荐 Claude SDK / Claude Code）

如果你在用 Anthropic 官方 SDK 或 Claude Code，请用独立的 base URL `https://api-direct.dimilinks.com/`：

```bash theme={null}
curl "https://api-direct.dimilinks.com/v1/messages" \
  -H "Authorization: Bearer $DIMILINKS_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-6",
    "max_tokens": 256,
    "messages": [
      {"role": "user", "content": "你好"}
    ]
  }'
```

详见 [Anthropic Messages](/api-reference/chat/anthropic-messages)。

## 4. 切换到流式输出

```bash theme={null}
curl "https://dimilinks.com/v1/chat/completions" \
  -H "Authorization: Bearer $DIMILINKS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-6",
    "stream": true,
    "messages": [
      {"role": "user", "content": "写一首关于深海的四行小诗"}
    ]
  }'
```

服务端会以 `text/event-stream` 推回一连串 `data: {...}` 增量事件，最后以 `data: [DONE]` 结束。详见 [Chat completions](/api-reference/chat/completions)。

## 5. 下一步

* 在 Claude Code 中接入 Claude：[Claude Code](/api-reference/integrations/claude-code)
* 在 Codex CLI 中接入 GPT：[Codex CLI](/api-reference/integrations/codex-cli)
* 在 Cursor / Continue / Zed / Cherry Studio 等 IDE 中配置：[VS Code 与其他 IDE](/api-reference/integrations/vscode-and-ides)
* 在控制台一键导入到 CC Switch / Cherry Studio：[CC Switch / Cherry Studio 一键导入](/api-reference/integrations/ccswitch)
* 提交图片任务：[Create image generation](/api-reference/images/gpt-image-2/generation)
* 提交视频任务：[Create video generation](/api-reference/videos/grok-imagine-video/generation)
* 查询任务进度：[Retrieve image task](/api-reference/images/gpt-image-2/tasks)
