API 文档
兼容 OpenAI。你的代码要是已经在用 OpenAI SDK,改两行就完事。下面先是 5 分钟上手,然后是全部细节。
快速上手
cURLcurl https://cloudgpu.app/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $CGW_API_KEY" \ -d '{ "model": "deepseek-v4-flash", "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Say hi in one sentence."} ] }'
鉴权
每一次请求 /v1/* requires an Authorization: Bearer cgw-sk-<your_key> header. Keys are scoped to your CloudGPU account. Revoke any key any time from the console; revocation takes effect immediately.
The raw key is shown exactly once at creation time. We store only a sha256 hash; we cannot recover it if you lose it. Create a new key if that happens.
接口
| 方法 | 路径 | 用途 |
|---|---|---|
| POST | /v1/chat/completions | OpenAI 格式的对话补全。请求和响应的结构跟 OpenAI 一样。 |
| GET | /v1/models | 列出可用模型,以及当前每 token 的价格。 |
向量、函数调用、视觉、图像生成 —— 在计划里,v0 还没有。
流式输出
在请求体里带上 "stream": true。响应是 OpenAI 格式的 Server-Sent Events。OpenAI SDK 会自己处理好。
Python (streaming)# Streaming — same client, stream=True for chunk in client.chat.completions.create( model="deepseek-v4-flash", messages=[{"role": "user", "content": "Count to 5."}], stream=True, ): delta = chunk.choices[0].delta.content if delta: print(delta, end="", flush=True)
SDK
我们不做自己的 SDK —— OpenAI SDK 原样就能用,只要改 base_url 覆盖。
Python# pip install openai>=1.0 from openai import OpenAI client = OpenAI( api_key="cgw-sk-...", # from /api/console base_url="https://cloudgpu.app/v1", ) resp = client.chat.completions.create( model="deepseek-v4-flash", messages=[{"role": "user", "content": "Say hi."}], ) print(resp.choices[0].message.content) print(f"Used {resp.usage.total_tokens} tokens")
Node.js// npm install openai import OpenAI from "openai"; const client = new OpenAI({ apiKey: process.env.CGW_API_KEY, baseURL: "https://cloudgpu.app/v1", }); const resp = await client.chat.completions.create({ model: "deepseek-v4-flash", messages: [{ role: "user", content: "Say hi." }], }); console.log(resp.choices[0].message.content);
价格与计费
Every model is priced 比它自家官网便宜 for the same model — see the 价目表. You pay per token, per image, per character or per second of audio depending on the model; nothing is metered by the hour and there is no monthly minimum.
Each request deducts from your prepaid balance. Successful calls show in your 控制台 within ~1 second with full token counts and dollar cost.
完整的分模型价目表在介绍页.
限流
| 每把密钥每分钟 | 100 次请求 |
| 每个账号每天 | 10000 次请求 |
这些默认值是公测期防滥用用的。需要提额就找我们 —— 只要是真实业务都可以提,说一下用途就行。
错误码
报错的结构和 OpenAI 一样:HTTP 状态码加上 JSON 正文 { error: { type, code, message } }.
| 状态 | 码 | 什么时候会出现 |
|---|---|---|
| 401 | missing_authorization | 没有带 Authorization 请求头。 |
| 401 | invalid_api_key | 密钥不存在或已被吊销。 |
| 400 | model_not_found | 模型 id 不在目录里。看 GET /v1/models。 |
| 402 | insufficient_balance | USDT 余额低于 $0.01。请充值。 |
| 429 | rate_limit_exceeded | 撞到每分钟或每天的限额了。 |
| 503 | upstream_not_configured | 网关正在开通 —— 几个小时内会好。 |
准备好了?
领取 API 密钥