# 知格科技 API 文档

通过统一的 API 接入对话、图片与视频生成，可用于应用开发及智能体工具对接。

- 文档地址：[API 文档](https://zhigekeji.com/docs)
- Base URL：`https://zhigekeji.com/api/v1`
- 认证方式：`Authorization: Bearer <API_KEY>`
- JSON 请求使用 `Content-Type: application/json`
- 在[控制台创建 API Key](https://zhigekeji.com/console/api-keys)，示例中的密钥和素材地址均需自行替换。

## 对话补全

兼容 OpenAI `/v1/chat/completions` 格式，调用 LLM 模型进行对话。支持流式（SSE）和非流式两种模式，支持多模态消息（参考图）。

### 请求参数

| 参数 | 类型 | 必填 | 说明 |
| --- | --- | --- | --- |
| `model` | string | 是 | 模型名称，以模型列表返回的 name 为准 |
| `messages` | array | 是 | 消息数组，支持纯文本和多模态格式 |
| `stream` | boolean | 否 | 是否流式返回，默认 `false` |
| `temperature` | number | 否 | 生成温度，0-2 |
| `max_tokens` | integer | 否 | 最大生成 token 数 |
| `top_p` | number | 否 | Top-P 采样参数 |

### 纯文本对话

```http
POST https://zhigekeji.com/api/v1/chat/completions
Authorization: Bearer sk-xxxx...
Content-Type: application/json

{
  "model": "Qwen3-27B",
  "messages": [
    {"role": "system", "content": "你是一个有帮助的助手"},
    {"role": "user", "content": "你好，请介绍一下自己"}
  ],
  "stream": false
}
```

### 带参考图的多模态对话

在 `messages` 中使用 `image_url` 类型传入图片，支持 URL 和 base64 格式：

```http
POST https://zhigekeji.com/api/v1/chat/completions
Authorization: Bearer sk-xxxx...
Content-Type: application/json

{
  "model": "Qwen3-27B",
  "messages": [
    {
      "role": "user",
      "content": [
        {"type": "text", "text": "请描述这张图片的内容"},
        {"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}}
      ]
    }
  ]
}
```

使用 base64 格式：

```json
"content": [
  {"type": "text", "text": "请描述这张图片"},
  {"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,/9j/4AAQ..."}}
]
```

非流式返回示例：

```json
{
  "id": "chatcmpl-a1b2c3d4",
  "object": "chat.completion",
  "created": 1716652800,
  "model": "Qwen3-27B",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "你好！我是一个AI助手..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 20,
    "completion_tokens": 50,
    "total_tokens": 70
  }
}
```

流式返回（`stream: true`）使用 SSE 格式，每个 chunk 兼容 OpenAI `chat.completion.chunk` 格式，最终以 `data: [DONE]` 结束。
