API 文档

兼容 OpenAI。你的代码要是已经在用 OpenAI SDK,改两行就完事。下面先是 5 分钟上手,然后是全部细节。

快速上手

  1. 打开 API 控制台,建一把密钥。把 cgw-sk-... 那串复制走 —— 只显示一次。
  2. 充值 USDT 余额,入口在 账单页。首充 $10 到账 $15,够你试上一阵了。
  3. 发一次请求:
  4. 可直接运行的示例(Python、Node.js、cURL、Cursor/Cline 配置)在公开仓库 <a href="https://github.com/mrhy7176/cloudgpu-examples" class="text-primary underline" target="_blank" rel="noopener">github.com/mrhy7176/cloudgpu-examples</a>。
cURL
curl 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/completionsOpenAI 格式的对话补全。请求和响应的结构跟 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 — most at or below it; the 价目表 shows the exact comparison. 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.

完整的分模型价目表在介绍页.

GPU 实例

同一把 API key 也能租 GPU:看货架、按模板开机、轮询到运行中、读 SSH 信息和公网 API 地址、销毁。计费和网页完全一样:按分钟、扣同一个余额。

这一节只针对 REST 接口。在网页上租 GPU 没有任何门槛。程序化的实例接口只对累计充值达到 $2,000 的账号开放,未达到的账号会收到 403 gpu_api_not_enabled 并附上还差多少。

方法路径用途
GET/v1/gpu/offers可租的卡:型号、显存、每小时价格、有货情况(none / low / ok)、最少几张。
GET/v1/gpu/templates模板:id、名称、推荐卡型、是否带公网 API 端点。
POST/v1/gpu/instances开机。请求体:gpu_model 和/或 template,可选 gpu_count(1–8)与 model_name。返回 202,状态 creating。
GET/v1/gpu/instances你在跑、在开和最近停掉的实例。
GET/v1/gpu/instances/{id}单个实例:状态、SSH 主机/端口/用户/密码、api_url、已运行分钟数、目前费用。
DELETE/v1/gpu/instances/{id}销毁实例并结算。POST /v1/gpu/instances/{id}/destroy 等价。
curl -X POST https://cloudgpu.app/v1/gpu/instances \
  -H "Authorization: Bearer $CLOUDGPU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"gpu_model": "RTX 4090", "template": "ollama"}'

# 202 Accepted
{"id":"2096…","object":"gpu.instance","gpu_model":"RTX 4090","gpu_count":1,"template":"ollama",
 "status":"creating","hourly_usd":0.33,"ssh":null,"api_url":null, …}

# poll GET /v1/gpu/instances/{id} until status is "running";
# then ssh.host / ssh.port / ssh.password and api_url (for API templates) are filled in.

默认:同时最多 10 台在跑或在开,每小时最多开 20 台,每把 key 每分钟最多 60 次 GPU API 请求。真实业务需要提额请联系 support@cloudgpu.app。

限流

每把密钥每分钟100 次请求
每个账号每天10000 次请求

这些默认值是公测期防滥用用的。需要提额就找我们 —— 只要是真实业务都可以提,说一下用途就行。

错误码

报错的结构和 OpenAI 一样:HTTP 状态码加上 JSON 正文 { error: { type, code, message } }.

状态码什么时候会出现
401missing_authorization没有带 Authorization 请求头。
401invalid_api_key密钥不存在或已被吊销。
400model_not_found模型 id 不在目录里。看 GET /v1/models。
402insufficient_balanceUSDT 余额低于 $0.01。请充值。
429rate_limit_exceeded撞到每分钟或每天的限额了。
503upstream_not_configured网关正在开通 —— 几个小时内会好。

准备好了?

领取 API 密钥