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

# 快速开始

## Siflow Model Inference API 快速开始

Siflow 为开发者和企业提供统一的 Model API 平台。平台兼容 OpenAI 风格接口，支持大语言模型、视觉/多模态模型、代码生成模型和推理模型；所有模型均可直接调用，并按量计费。

### 1. 登录

* 访问 [Siflow Model Inference 控制台](https://console.siflow.cn/maas-api/overview)，并点击右上角的 **登录**。
* 您可以使用短信、邮箱或 Google OAuth 登录。

### 2. 选择并测试模型

* 在 [模型广场](https://console.siflow.cn/maas-api/model_plaza) 中查看模型、上下文窗口、价格和示例代码。
* 点击 **立即体验** 会打开已选中该模型的 [体验中心](https://console.siflow.cn/maas-api/trial_center)，方便您在接入代码前先测试提示词和参数。

### 3. 查看用量

* 登录后，您可以在 [服务概览](https://console.siflow.cn/maas-api/overview) 页面查看用量数据，包括 **token 消耗** 和 **消费金额** 的今日、本周、本月及累计统计。
* 页面中的 **最近使用** 会按模型展示近期调用情况，包括 token 消耗和消费金额。

### 4. 通过 Siflow Model Inference API 调用模型

#### 4.1 创建 API 密钥

* 进入 [API 密钥管理](https://console.siflow.cn/maas-api/api_keys) 页面，并点击 **创建 API 密钥**。
* 列表中每个密钥都会显示其创建时间、最近使用时间和速率限制等信息。有关费用额度与速率限制的更多信息，请参阅 [API 密钥指南](/products/model-inference/console/api-keys)。
* 建议将密钥存储在环境变量中，以便在本地开发和服务器之间一致地管理：

```bash theme={null}
export API_KEY="YOUR_API_KEY"
```

#### 4.2 通过 REST 调用

* 您可以通过标准 HTTP 请求调用模型。下面是一个流式 Chat Completions 示例：

```bash theme={null}
curl -N https://api.siflow.cn/model-api/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "Qwen/Qwen3-32B",
    "stream": true,
    "messages": [
      {"role": "user", "content": "What new opportunities might reasoning models bring to the market?"}
    ]
  }'
```

> **注意**\
> 上面的示例会直接输出原始流式响应。由于该 API 使用 Server-Sent Events（SSE），您会看到多行 `data: {...}` JSON，直接阅读不太方便。\
> 如果您只想查看拼接后的文本内容，可以像下面这样配合 `jq`（轻量级 JSON 处理器）处理响应：
>
> ```bash theme={null}
> # Read each SSE line, extract choices[0].delta.content, and print only the accumulated answer text.
> curl -N https://api.siflow.cn/model-api/chat/completions \
>   -H "Authorization: Bearer $API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "model": "Qwen/Qwen3-32B",
>     "stream": true,
>     "messages": [{"role": "user", "content": "What new opportunities might reasoning models bring to the market?"}]
>   }' 2>/dev/null | while IFS= read -r line; do
>   if [[ "$line" == data:* ]]; then
>     json="${line#data: }"
>     if [[ "$json" != "[DONE]" ]]; then
>       echo -n "$(echo "$json" | jq -r '.choices[0].delta.content // empty')"
>     fi
>   fi
> done
> echo
> ```
>
> 该脚本需要在您的机器上安装 `jq`（例如，在 macOS 上使用 `brew install jq`，在 Debian/Ubuntu 上使用 `apt-get install jq`）。

* 提示：
  * 如果您希望在单个响应中接收完整结果，请将 `stream` 设置为 `false`。
  * 对于其他任务（如文生图），请参阅文档或模型的详情页面，以获取相应的 API 和参数。

#### 4.3 通过 OpenAI 兼容的 Python SDK 调用

* 平台兼容官方 OpenAI Python SDK。请先安装 Python 3.7.1+，然后执行：

```bash theme={null}
pip install --upgrade openai
```

* 示例（支持 `reasoning` 字段的流式输出）：

```python theme={null}
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("API_KEY") or "YOUR_API_KEY",
    base_url="https://api.siflow.cn/model-api"
)

response = client.chat.completions.create(
    model="Qwen/Qwen3-32B",
    messages=[
        {"role": "user", "content": "What new opportunities might reasoning models bring to the market?"}
    ],
    stream=True
)

for chunk in response:
    if not chunk.choices:
        continue
    delta = chunk.choices[0].delta
    if getattr(delta, "content", None):
        print(delta.content, end="", flush=True)
    if getattr(delta, "reasoning", None):
        print(delta.reasoning, end="", flush=True)
```

* 说明：
  * 如果您不需要流式输出，请移除 `stream=True`，改为读取 `response.choices[0].message.content`。
  * 请根据您的业务场景，从 [模型广场](https://console.siflow.cn/maas-api/model_plaza) 中选择合适的 `model` 名称和参数。
