开发者文档
接入黑云 API Hub,快速集成主流 AI 模型。
快速开始
1. 注册账号
访问 https://2685336309.icu 注册黑云账户。新用户注册即获赠 100,000 Token 免费额度,无需信用卡,开箱即用。
2. 创建 API Key
登录 黑云控制台,在「API 密钥」页面创建一个新的密钥。请妥善保管 API Key,创建后仅显示一次。
💡 提示:每个账户最多可创建 5 个 API Key,建议为不同应用分配不同的 Key 以便管理。
3. 发起首次 API 请求
获得 API Key 后,使用以下命令进行首次调用:
curl https://2685336309.icu/v1/chat/completions \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-chat",
"messages": [{"role": "user", "content": "你好,请介绍一下自己"}]
}'
📌 API 基础地址:所有请求均使用 https://2685336309.icu/v1 作为基础 URL。
认证方式
Bearer Token 认证
黑云 API 采用标准的 Bearer Token 认证方式。所有请求必须在 HTTP Header 中包含 Authorization 字段:
Authorization: Bearer sk-你的API密钥
安全建议
- 切勿将 API Key 暴露在客户端代码(前端 JavaScript、移动端应用)中
- 建议将 API Key 存储在环境变量或密钥管理服务中
- 定期轮换 API Key,降低泄露风险
- 可以为不同项目创建独立的 API Key 以实现权限隔离
- 监控控制台中的用量统计,留意异常调用模式
⚠️ 注意:如果 API Key 泄露,请立即在控制台删除并重新生成。
模型列表
黑云支持多个渠道的 AI 模型。每个模型有独立的定价和上下文长度限制。以下为完整价格表。
DeepSeek
| 模型 | 输入 (¥/1K tokens) | 输出 (¥/1K tokens) | 上下文 |
|---|---|---|---|
| deepseek-chat | 0.00014 | 0.00028 | 64K |
| deepseek-coder | 0.00014 | 0.00028 | 16K |
Kimi Moonshot
| 模型 | 输入 (¥/1K tokens) | 输出 (¥/1K tokens) | 上下文 |
|---|---|---|---|
| moonshot-v1-8k | 0.00170 | 0.00170 | 8K |
| moonshot-v1-32k | 0.00341 | 0.00341 | 32K |
| moonshot-v1-128k | 0.00852 | 0.00852 | 128K |
通义千问 Alibaba Qwen
| 模型 | 输入 (¥/1K tokens) | 输出 (¥/1K tokens) | 上下文 |
|---|---|---|---|
| qwen-turbo | 0.00286 | 0.00286 | 1M |
| qwen-plus | 0.00286 | 0.00286 | 128K |
| qwen-max | 0.00286 | 0.00286 | 32K |
| qwen-long | 0.00286 | 0.00286 | 10M |
| qwen2.5-7b-instruct | 0.00286 | 0.00286 | 32K |
| qwen2.5-14b-instruct | 0.00286 | 0.00286 | 32K |
| qwen2.5-32b-instruct | 0.00286 | 0.00286 | 32K |
| qwen2.5-72b-instruct | 0.00286 | 0.00286 | 32K |
智谱 ChatGLM
| 模型 | 输入 (¥/1K tokens) | 输出 (¥/1K tokens) | 上下文 |
|---|---|---|---|
| glm-4 | 0.00710 | 0.00710 | 128K |
| glm-4-plus | 0.00710 | 0.00710 | 128K |
| glm-4-air | 0.00007 | 0.00007 | 128K |
| glm-4-flash | 免费 🆓 | 免费 🆓 | 128K |
| glm-4-long | 0.00014 | 0.00014 | 1M |
| glm-4-0520 | 0.00710 | 0.00710 | 128K |
| glm-4v | 0.00710 | 0.00710 | 128K |
SiliconFlow
| 模型 | 输入 (¥/1K tokens) | 输出 (¥/1K tokens) | 上下文 |
|---|---|---|---|
| Pro/deepseek-ai/DeepSeek-V3 | 0.00133 | 0.00133 | 128K |
| Pro/deepseek-ai/DeepSeek-R1 | 0.004 | 0.016 | 64K |
| Qwen/Qwen2.5-72B-Instruct | 0.004 | 0.004 | 128K |
| Qwen/QwQ-32B | 0.001 | 0.001 | 32K |
| internlm/internlm3-8b-instruct | 0.00072 | 0.00072 | 32K |
| deepseek-ai/DeepSeek-V2.5 | 0.00072 | 0.00072 | 128K |
MXAPI-AI
| 模型 | 输入 (¥/1K tokens) | 输出 (¥/1K tokens) | 上下文 |
|---|---|---|---|
| gpt-4 | 0.03000 | 0.06000 | 8K |
| gpt-4o | 0.00500 | 0.02000 | 128K |
| gpt-4o-mini | 0.00015 | 0.00060 | 128K |
| gpt-3.5-turbo | 0.00050 | 0.00150 | 16K |
| deepseek-chat | 0.00100 | 0.00200 | 64K |
| claude-3-5-sonnet | 0.00300 | 0.01500 | 200K |
API 参考 — 聊天补全
黑云 API 完全兼容 OpenAI 的 Chat Completions 接口格式,主流 SDK 无需额外适配即可使用。
📌 兼容性:支持 openai Python 库、openai Node.js 库等主流 OpenAI SDK。
POST /v1/chat/completions
创建一个聊天补全请求。
请求参数
| 参数 | 类型 | 说明 | 必填 |
|---|---|---|---|
| model | string | 模型名称,如 deepseek-chat | 是 |
| messages | array | 消息列表,包含 role 和 content | 是 |
| max_tokens | integer | 最大生成 Token 数,默认 4096 | 否 |
| temperature | number | 采样温度 (0–2),默认 1.0 | 否 |
| top_p | number | 核采样参数 (0–1),默认 1.0 | 否 |
| stream | boolean | 是否流式返回,默认 false | 否 |
| stop | string/array | 停止序列 | 否 |
| frequency_penalty | number | 频率惩罚 (-2–2) | 否 |
| presence_penalty | number | 存在惩罚 (-2–2) | 否 |
请求示例
cURL
curl https://2685336309.icu/v1/chat/completions \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-chat",
"messages": [
{"role": "system", "content": "你是一位助手"},
{"role": "user", "content": "介绍一下大模型的基本原理"}
],
"max_tokens": 1024,
"temperature": 0.7
}'
Python
from openai import OpenAI
client = OpenAI(
base_url="https://2685336309.icu/v1",
api_key="sk-your-api-key"
)
response = client.chat.completions.create(
model="deepseek-chat",
messages=[
{"role": "system", "content": "你是一位助手"},
{"role": "user", "content": "介绍一下大模型的基本原理"}
],
max_tokens=1024,
temperature=0.7
)
print(response.choices[0].message.content)
Node.js
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://2685336309.icu/v1',
apiKey: 'sk-your-api-key'
});
const response = await client.chat.completions.create({
model: 'deepseek-chat',
messages: [
{role: 'system', content: '你是一位助手'},
{role: 'user', content: '介绍一下大模型的基本原理'}
],
max_tokens: 1024,
temperature: 0.7
});
console.log(response.choices[0].message.content);
Java (OkHttp)
// Maven 依赖:
// com.squareup.okhttp3:okhttp:4.12.0
// com.google.code.gson:gson:2.10.1
import okhttp3.*;
import com.google.gson.JsonObject;
import java.io.IOException;
public class ChatCompletionExample {
public static void main(String[] args) throws IOException {
OkHttpClient client = new OkHttpClient();
JsonObject body = new JsonObject();
body.addProperty("model", "deepseek-chat");
JsonObject msg = new JsonObject();
msg.addProperty("role", "user");
msg.addProperty("content", "介绍一下大模型的基本原理");
body.add("messages", new com.google.gson.JsonArray());
body.getAsJsonArray("messages").add(msg);
Request request = new Request.Builder()
.url("https://2685336309.icu/v1/chat/completions")
.addHeader("Authorization", "Bearer sk-your-api-key")
.addHeader("Content-Type", "application/json")
.post(RequestBody.create(
MediaType.parse("application/json"),
body.toString()
))
.build();
try (Response response = client.newCall(request).execute()) {
System.out.println(response.body().string());
}
}
}
Go
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
requestBody, _ := json.Marshal(map[string]interface{}{
"model": "deepseek-chat",
"messages": []map[string]string{
{"role": "user", "content": "介绍一下大模型的基本原理"},
},
"max_tokens": 1024,
"temperature": 0.7,
})
req, _ := http.NewRequest(
"POST",
"https://2685336309.icu/v1/chat/completions",
bytes.NewBuffer(requestBody),
)
req.Header.Set("Authorization", "Bearer sk-your-api-key")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error:", err)
return
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
响应格式
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1680000000,
"model": "deepseek-chat",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "大模型..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 15,
"completion_tokens": 200,
"total_tokens": 215
}
}
流式响应
设置 stream: true 即可启用流式响应,API 会以 Server-Sent Events (SSE) 格式逐块返回数据。每个数据块包含一个 delta 字段而非 message。
data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"大"},"finish_reason":null}]}
data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"模型"},"finish_reason":null}]}
data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]
API 参考 — 图像生成
通过图像生成 API,可以将文本描述转换为图像。兼容 OpenAI DALL-E 接口风格。
POST /v1/images/generations
| 参数 | 类型 | 说明 | 必填 |
|---|---|---|---|
| model | string | 图像生成模型名称 | 是 |
| prompt | string | 文本描述,最多 1000 字符 | 是 |
| n | integer | 生成数量 (1–4),默认 1 | 否 |
| size | string | 图像尺寸,如 1024x1024 | 否 |
| quality | string | 图像质量,standard 或 hd | 否 |
curl https://2685336309.icu/v1/images/generations \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "dall-e-3",
"prompt": "一只橘猫坐在服务器机房里,科技感,数字艺术",
"n": 1,
"size": "1024x1024"
}'
多语言 SDK 示例
以下为各语言的完整可运行示例。只需替换 your-api-key 为真实 API Key 即可。
Python
使用 OpenAI 官方 Python SDK:
from openai import OpenAI
client = OpenAI(
base_url="https://2685336309.icu/v1",
api_key="your-api-key"
)
response = client.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": "你好"}]
)
print(response.choices[0].message.content)
Node.js
使用 OpenAI 官方 Node.js SDK:
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://2685336309.icu/v1',
apiKey: 'your-api-key'
});
const response = await client.chat.completions.create({
model: 'deepseek-chat',
messages: [{role: 'user', content: '你好'}]
});
console.log(response.choices[0].message.content);
cURL
curl https://2685336309.icu/v1/chat/completions \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{"model":"deepseek-chat","messages":[{"role":"user","content":"你好"}]}'
Java (OkHttp)
在 pom.xml 中添加依赖:
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.12.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
Java 源代码:
import okhttp3.*;
import com.google.gson.JsonObject;
import com.google.gson.JsonArray;
import java.io.IOException;
public class BlackCloudChat {
public static void main(String[] args) throws IOException {
OkHttpClient client = new OkHttpClient();
JsonObject msg = new JsonObject();
msg.addProperty("role", "user");
msg.addProperty("content", "你好");
JsonArray messages = new JsonArray();
messages.add(msg);
JsonObject body = new JsonObject();
body.addProperty("model", "deepseek-chat");
body.add("messages", messages);
Request request = new Request.Builder()
.url("https://2685336309.icu/v1/chat/completions")
.addHeader("Authorization", "Bearer your-api-key")
.addHeader("Content-Type", "application/json")
.post(RequestBody.create(
MediaType.parse("application/json"),
body.toString()
))
.build();
try (Response response = client.newCall(request).execute()) {
System.out.println(response.body().string());
}
}
}
Go
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
body := map[string]interface{}{
"model": "deepseek-chat",
"messages": []map[string]string{
{"role": "user", "content": "你好"},
},
}
jsonData, _ := json.Marshal(body)
req, _ := http.NewRequest(
"POST",
"https://2685336309.icu/v1/chat/completions",
bytes.NewBuffer(jsonData),
)
req.Header.Set("Authorization", "Bearer your-api-key")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("请求失败:", err)
return
}
defer resp.Body.Close()
respBody, _ := io.ReadAll(resp.Body)
fmt.Println(string(respBody))
}
错误码说明
| HTTP 状态码 | 错误类型 | 说明 | 解决方案 |
|---|---|---|---|
| 401 | invalid_api_key | API Key 无效或未提供 | 检查请求头中是否包含正确的 Authorization: Bearer |
| 402 | insufficient_quota | 账户余额/额度不足 | 前往控制台 充值 或等待免费额度重置 |
| 404 | model_not_found | 请求的模型不存在或未启用 | 检查 model 参数是否正确,参考模型列表 |
| 429 | rate_limit_exceeded | 请求频率超出限制 | 降低请求频率,稍后重试 |
| 500 | upstream_error | 上游模型服务异常 | 请稍后重试,如持续失败请联系客服 |
| 503 | service_unavailable | 服务维护中 | 请稍后重试,关注控制台维护公告 |
📌 所有错误响应均包含:{"error": {"message": "...", "type": "...", "code": 401}}
使用限制
频率限制
为保障服务稳定性,API 接口有以下频率限制:
- 标准用户:每分钟最多 60 次请求
- 高级用户:每分钟最多 300 次请求(需联系申请)
- 图像生成:每分钟最多 10 次请求
上下文长度
不同模型的上下文长度不同,详见上方 模型列表。超出上下文长度的请求会被截断或拒绝。
额度计算
费用按实际消耗的 Token 数量进行计费。Token 是模型处理文本的基本单位,一般约 750 个汉字 ≈ 1000 tokens。
💡 计算公式:
总费用 = 输入 Token 数 × 输入单价 + 输出 Token 数 × 输出单价
例如:调用 deepseek-chat,输入 500 tokens、输出 300 tokens:
500 × 0.00014 + 300 × 0.00028 = 0.154 元
最佳实践
- 为生成类任务设置合理的
max_tokens,避免不必要的输出消耗 - 使用短而精确的提示词,减少输入 token 消耗
- 利用
stream模式优化用户体验,首字延迟更低 - 实现指数退避重试机制处理 429/500 错误