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

# 快速开始

> 设置密钥与模型，查询权限并完成第一次对话请求。

下面用 Bash 和 cURL 验证一次完整调用。使用现成软件时，可直接打开[客户端教程](https://apione.ai/docs/guides/clients.md)。

## 1. 创建密钥

在 [API 密钥页](https://apione.ai/zh/app/api-keys)创建密钥，选择可用分组与模型权限，并保存完整密钥。以下命令适用于 macOS、Linux 或其他 Bash 环境。

![APIONE API Key 页面概览](https://mintcdn.com/apione/pAFvFGkbmcRZirTZ/images/ui/api-keys-overview.png?fit=max\&auto=format\&n=pAFvFGkbmcRZirTZ\&q=85\&s=286a882ab53c81ad3bd16d56c6487dc9)

API Key 页面集中展示 Base URL、接入协议、折扣分组与模型价格。

```bash theme={null}
export APIONE_API_KEY="YOUR_APIONE_KEY"
```

将 `YOUR_APIONE_KEY` 替换为真实密钥，只在自己的终端或服务端保存。

## 2. 查询并选择模型

```bash theme={null}
curl --fail-with-body --max-time 120 https://api.apione.ai/v1/models \
  -H "Authorization: Bearer $APIONE_API_KEY"
```

从响应的 `data[].id` 复制一个支持 Chat Completions 的模型 ID，再设置环境变量。也可以在[模型目录](https://apione.ai/zh/models)查看模型协议和参数。

```bash theme={null}
export APIONE_MODEL="YOUR_APIONE_MODEL_ID"
```

将 `YOUR_APIONE_MODEL_ID` 替换为实际 ID，保留大小写。模型未出现在当前密钥的列表中时，先检查密钥权限和分组。

## 3. 发送第一次请求

```bash theme={null}
curl --fail-with-body --max-time 120 https://api.apione.ai/v1/chat/completions \
  -H "Authorization: Bearer $APIONE_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"model\":\"$APIONE_MODEL\",\"messages\":[{\"role\":\"user\",\"content\":\"用一句话解释 API 网关。\"}]}"
```

## Windows PowerShell 快速验证

Windows 用户可在 PowerShell 中执行下面的步骤。先在 [APIONE 控制台](https://apione.ai/zh/app)确认可用额度，再创建密钥。

```powershell theme={null}
$env:APIONE_API_KEY = "YOUR_APIONE_KEY"
$apioneHeaders = @{ Authorization = "Bearer $env:APIONE_API_KEY" }
$apioneModels = Invoke-RestMethod `
  -Uri "https://api.apione.ai/v1/models" `
  -Headers $apioneHeaders -TimeoutSec 30
$apioneModels.data | Select-Object id
```

从列表复制一个支持 Chat Completions 的模型 ID，替换下方占位符，然后发送请求。

```powershell theme={null}
$env:APIONE_MODEL = "YOUR_APIONE_MODEL_ID"
$apioneBody = @{
  model = $env:APIONE_MODEL
  messages = @(
    @{ role = "user"; content = "Reply only OK." }
  )
  stream = $false
} | ConvertTo-Json -Depth 6

$apioneReply = Invoke-RestMethod `
  -Uri "https://api.apione.ai/v1/chat/completions" `
  -Method Post -Headers $apioneHeaders `
  -ContentType "application/json; charset=utf-8" `
  -Body ([System.Text.Encoding]::UTF8.GetBytes($apioneBody)) `
  -TimeoutSec 120
$apioneReply.choices[0].message.content
$apioneReply.usage
```

先看到模型列表，再看到回复，说明这两步请求分别成功。客户端还需要单独验证流式输出、工具调用等实际使用的能力。出现错误时保留 HTTP 状态码和响应正文，按[错误排查](https://apione.ai/docs/support/errors.md)处理。

## 4. 检查结果与用量

成功时，从 `choices[0].message.content` 读取回复，从 `usage` 查看 Token 用量。下面只展示响应中的部分结构，文字和数值由实际调用决定：

```json theme={null}
{
  "choices": [{"message": {"role": "assistant", "content": "模型返回的文本"}}],
  "usage": {"prompt_tokens": 20, "completion_tokens": 30, "total_tokens": 50}
}
```

到[控制台](https://apione.ai/zh/app)核对请求明细与费用；API 的用量字段不能单独代替账单。

| 遇到的问题 | 先检查 |
| - | - |
| 401 | 密钥是否完整、有效，是否只发送一种鉴权凭证 |
| 403 或模型不可用 | 模型 ID、密钥权限及分组 |
| 404 | 完整请求地址中是否重复了 `/v1` |
| 402 / 429 | [余额、费用与并发限制](https://apione.ai/docs/account/usage.md) |

下一步：[Python 与 Node.js](https://apione.ai/docs/guides/sdks.md)、[流式输出](https://apione.ai/docs/models/streaming.md)、[错误排查](https://apione.ai/docs/support/errors.md)。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.