快速入门
知格科技 API 使用简单,只需三步即可开始:
- 注册账号并获取 API Key
- 将
base_url替换为https://zhigekeji.com/api - 使用 API Key 作为
Bearer Token发起请求
curl https://zhigekeji.com/api/v1/chat/completions \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.6",
"messages": [
{"role": "user", "content": "一个穿着棒球服的少女,树下"}
]
}'
认证方式
所有模型推理接口使用 API 密钥认证,在请求头中添加 Authorization: Bearer sk-xxxx...。
Authorization: Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
API 密钥以 sk- 开头,可在控制台的 API 密钥管理 页面创建和查看。
API 密钥管理
在 控制台 - API 密钥 页面可以创建、查看和管理密钥。
创建密钥
点击「创建密钥」按钮,输入名称和速率限制即可生成。密钥格式为 sk-xxxx...,创建后请立即复制保存。
sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
OpenAI 兼容接口说明
平台提供与 OpenAI API 格式完全兼容的接口,可直接使用 OpenAI SDK 或任何兼容客户端调用。支持 LLM 对话补全(含多模态参考图)和 ComfyUI 工作流图片/视频生成。
核心流程:获取模型列表 → 调用对话补全或图片生成接口 → 获取结果
| 项目 | 值 |
|---|---|
| Base URL | https://zhigekeji.com/api/v1 |
| 认证方式 | Bearer Token(API Key 或登录 Token) |
| Content-Type | application/json |
模型列表
获取所有可用的模型,兼容 OpenAI /v1/models 格式。包含 LLM 对话模型和 生图模型。
GET https://zhigekeji.com/api/v1/models Authorization: Bearer sk-xxxx...
返回示例:
{
"object": "list",
"data": [
{
"object": "model",
"owned_by": "zhigekeji",
"name": "Qwen3-27B",
"description": "通义千问3 27B 对话模型",
"type": "text"
},
{
"object": "model",
"owned_by": "zhigekeji",
"name": "ernie-image",
"description": "二次元风格图片生成",
"type": "image"
}
]
}
对话补全
兼容 OpenAI /v1/chat/completions 格式,调用 LLM 模型进行对话。支持流式(SSE)和非流式两种模式,支持多模态消息(参考图)。
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 模型名称,对应 ModelConfig 中的 name |
messages | array | 是 | 消息数组,支持纯文本和多模态格式 |
stream | boolean | 否 | 是否流式返回,默认 false |
temperature | number | 否 | 生成温度,0-2 |
max_tokens | integer | 否 | 最大生成 token 数 |
top_p | number | 否 | Top-P 采样参数 |
纯文本对话
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 格式:
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 格式:
"content": [
{"type": "text", "text": "请描述这张图片"},
{"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,/9j/4AAQ..."}}
]
非流式返回示例:
{
"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] 结束。
图片生成
兼容 OpenAI /v1/images/generations 格式,直接传入提示词生成图片。支持参考图,传入后系统会自动反推图片中人物/场景描述并融合到提示词中。
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 模型名,如 ernie-image |
prompt | string | 是 | 图片描述提示词,最长 4000 字符 |
size | string | 否 | 图片尺寸,如 512x768 |
response_format | string | 否 | 返回格式:url(默认)或 b64_json |
images | string[] | 否 | 参考图片数组,每项为 URL 或 base64 编码字符串 |
prompt_mode | string | 否 | 提示词处理模式:optimize(完整优化)或 不填(默认:不优化) |
基础图片生成
POST https://zhigekeji.com/api/v1/images/generations
Authorization: Bearer sk-xxxx...
Content-Type: application/json
{
"model": "ernie-image",
"prompt": "一个穿着棒球服的少女,树下",
"size": "512x768",
"response_format": "url"
}
带参考图的图片生成
传入参考图后,系统会自动使用多模态 AI 分析图片内容,将反推出的描述提示词与原始 prompt 融合:
POST https://zhigekeji.com/api/v1/images/generations
Authorization: Bearer sk-xxxx...
Content-Type: application/json
{
"model": "ernie-image",
"prompt": "一个穿着棒球服的少女,树下",
"images": [
"https://example.com/reference.jpg"
],
"size": "512x768"
}
返回示例:
{
"created": 1716652800,
"data": [
{
"url": "http://host/view?filename=00001_.png"
}
]
}
异步图片生成
适用于需要批量生成或对响应时间不敏感的场景。接口立即返回 task_id,图片生成在后台异步执行,通过状态查询接口获取结果。
POST https://zhigekeji.com/api/v1/images/generations/async
Authorization: Bearer sk-xxxx...
Content-Type: application/json
{
"model": "ernie-image",
"prompt": "一个穿着棒球服的少女,树下",
"images": [
"https://example.com/reference.jpg"
],
"prompt_mode": "add",
"size": "512x768"
}
请求参数与同步接口相同,立即返回:
{
"created": 1716652800,
"task_id": "42",
"status": "pending",
"object": "image_generation.task"
}
生图状态查询
通过异步接口返回的 task_id 查询图片生成状态和结果。
GET https://zhigekeji.com/api/v1/images/generations/status?task_id=42 Authorization: Bearer sk-xxxx...
状态码说明
| status | 说明 |
|---|---|
pending | 任务排队中 |
running | 正在生成 |
completed | 生成完成 |
failed | 生成失败 |
完成状态返回示例
{
"task_id": "42",
"status": "completed",
"created_at": "2026-07-08T10:00:00Z",
"completed_at": "2026-07-08T10:01:30Z",
"data": [
{
"url": "http://host/view?filename=00001_.png"
}
]
}
图片风格反推
分析图片的视觉风格和画质特征,生成可用于 AI 绘图的风格提示词。传入图片后,返回一段风格描述提示词,用该提示词可以生成同样风格和画质的图片。
POST https://zhigekeji.com/api/v1/images/prompt Authorization: Bearer sk-xxxx... Content-Type: application/json
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
images | string[] | 是 | 图片数组,每项为 URL 或 base64 编码字符串,至少1张 |
请求示例
{
"images": [
"https://example.com/style-reference.jpg"
]
}
返回示例
{
"prompt": "cel shading, clean lineart, vibrant colors, high contrast, anime style, smooth shading, HD, detailed"
}
- 返回的
prompt为英文逗号分隔的风格关键词,可直接用于 AI 绘图提示词 - 分析维度包括:绘画风格、线条特征、色彩风格、光影特点、画面质感、渲染品质、构图风格
- 不描述图片具体内容(人物长相、服装、动作、场景等),仅描述风格和画质
- 支持 URL 和 base64 两种图片格式,base64 字符串会自动补全
data:image/jpeg;base64,前缀
OpenAI SDK 接入
由于接口完全兼容 OpenAI 格式,可直接使用官方 SDK 调用,只需修改 base_url 和 api_key。
Python(openai 库)
from openai import OpenAI
client = OpenAI(
api_key="sk-xxxx...",
base_url="https://zhigekeji.com/api/v1"
)
# LLM 对话补全
response = client.chat.completions.create(
model="Qwen3-27B",
messages=[
{"role": "user", "content": "你好,请介绍一下自己"}
]
)
print(response.choices[0].message.content)
# 多模态对话(带参考图)
response = client.chat.completions.create(
model="Qwen3-27B",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "请描述这张图片"},
{"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}}
]
}
]
)
print(response.choices[0].message.content)
# 图片生成(带参考图)
response = client.images.generate(
model="ernie-image",
prompt="一个穿着棒球服的少女,树下",
size="512x768"
)
print(response.data[0].url)
Node.js(openai 库)
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'sk-xxxx...',
baseURL: 'https://zhigekeji.com/api/v1',
});
// LLM 对话补全
const chatResponse = await client.chat.completions.create({
model: 'Qwen3-27B',
messages: [
{ role: 'user', content: '你好,请介绍一下自己' }
],
});
console.log(chatResponse.choices[0].message.content);
// 多模态对话(带参考图)
const visionResponse = await client.chat.completions.create({
model: 'Qwen3-27B',
messages: [
{
role: 'user',
content: [
{ type: 'text', text: '请描述这张图片' },
{ type: 'image_url', image_url: { url: 'https://example.com/photo.jpg' } }
]
}
],
});
console.log(visionResponse.choices[0].message.content);
// 图片生成
const imageResponse = await client.images.generate({
model: 'ernie-image',
prompt: '一个穿着棒球服的少女,树下',
size: '512x768',
});
console.log(imageResponse.data[0].url);
cURL
# LLM 对话补全
curl https://zhigekeji.com/api/v1/chat/completions \
-H "Authorization: Bearer sk-xxxx..." \
-H "Content-Type: application/json" \
-d '{
"model": "Qwen3-27B",
"messages": [{"role": "user", "content": "你好,请介绍一下自己"}]
}'
# 多模态对话(带参考图)
curl https://zhigekeji.com/api/v1/chat/completions \
-H "Authorization: Bearer sk-xxxx..." \
-H "Content-Type: application/json" \
-d '{
"model": "Qwen3-27B",
"messages": [{"role": "user", "content": [
{"type": "text", "text": "请描述这张图片"},
{"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}}
]}]
}'
# 图片生成
curl https://zhigekeji.com/api/v1/images/generations \
-H "Authorization: Bearer sk-xxxx..." \
-H "Content-Type: application/json" \
-d '{
"model": "ernie-image",
"prompt": "一个穿着棒球服的少女,树下",
"size": "512x768"
}'
# 风格反推
curl https://zhigekeji.com/api/v1/images/prompt \
-H "Authorization: Bearer sk-xxxx..." \
-H "Content-Type: application/json" \
-d '{
"images": ["https://example.com/style-reference.jpg"]
}'
计费说明
- 费用 = 消耗 Token 数 × 模型单价 (price_per_token)
- 每次推理成功后自动从用户余额扣除
- 推理失败不扣费
- 余额不足时拒绝请求
- 每个 API 密钥独立统计使用量
错误码
| 状态码 | 说明 |
|---|---|
| 401 | API 密钥无效或已过期 |
| 402 | 余额不足 |
| 403 | 账户已被禁用 / 余额不足 |
| 404 | 模型或任务不存在 |
| 429 | 请求频率超限 |
| 500 | 服务内部错误 |
| 503 | 服务不可用 |