一套接口,接进任何吃算力的流程

在线推理用 OpenAI 兼容接口,批处理与自定义作业用通用任务接口,供给方用 Worker 接入。三种角色,同一套鉴权。

第一步:拿密钥

登录控制台,在「用户信息 → API 密钥」创建。密钥只在创建时完整显示一次,请立即保存。

所有请求使用 Authorization: Bearer <你的密钥>。密钥与账号绑定,余额共用,可在同一页面随时吊销。

在线推理(OpenAI 兼容)

把 base_url 指向本平台即可,SDK 不用改。支持对话、图像生成、向量化、语音转写。

# pip install openai
from openai import OpenAI

client = OpenAI(
    base_url="https://api.kogun.site/v1",
    api_key="sk-kogun-你的密钥",
)

resp = client.chat.completions.create(
    model="kogun-qwen-72b",
    messages=[{"role": "user", "content": "把这段话翻成英文"}],
)
print(resp.choices[0].message.content)
// npm i openai
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.kogun.site/v1",
  apiKey: "sk-kogun-你的密钥",
});

const r = await client.chat.completions.create({
  model: "kogun-qwen-72b",
  messages: [{ role: "user", content: "hello" }],
});
console.log(r.choices[0].message.content);
curl https://api.kogun.site/v1/chat/completions \
  -H "Authorization: Bearer sk-kogun-你的密钥" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kogun-qwen-72b",
    "messages": [{"role":"user","content":"hello"}]
  }'

批处理与自定义作业

渲染、训练、仿真、数据处理这类长任务走异步接口:先提交,拿 task_id,再轮询或等回调。

# 提交(自动按 gpu_model 与 estimated_hours 预扣费)
curl -X POST https://api.kogun.site/v1/compute/submit \
  -H "Authorization: Bearer sk-kogun-你的密钥" \
  -H "Content-Type: application/json" \
  -d '{
    "task_name": "blender-第3集-4K",
    "task_type": "render",
    "gpu_model": "RTX 4090",
    "estimated_hours": 6,
    "params": {"frames": "1201-1440", "engine": "cycles", "samples": 256}
  }'

# 查询进度
curl https://api.kogun.site/v1/compute/status/<task_id> \
  -H "Authorization: Bearer sk-kogun-你的密钥"

# 取结果(完成后返回产物地址)
curl https://api.kogun.site/v1/compute/result/<task_id> \
  -H "Authorization: Bearer sk-kogun-你的密钥"
任务先进入 pending,由调度器按算力评分与地域匹配设备。竞价实例可能被抢占,重投时带上原 task_id 的检查点即可续跑。

接口清单

以下是面向调用方的稳定接口,完整参数见 API 参考。

方法路径说明
GET/v1/models可用模型列表与上下文长度
POST/v1/chat/completions对话补全,流式与非流式
POST/v1/images/generations文生图(SDXL / SD3)
POST/v1/embeddings向量化,用于检索与聚类
POST/v1/audio/transcriptions语音转写(Whisper)
POST/v1/compute/submit提交通用算力任务
GET/v1/compute/status/{id}任务状态与进度
GET/v1/compute/result/{id}结果与产物下载
GET/v1/dashboard/billing用量与费用明细
GET/api/public/catalog公开算力目录(免鉴权)
POST/api/public/estimate成本估算(免鉴权)

错误处理

状态码type含义与处理
401invalid_api_key密钥无效或已吊销,检查 Bearer 头
402insufficient_quota余额不足,充值后重试
404model_not_found模型名不存在,先查 /v1/models
429rate_limit_exceeded超出并发限额,退避重试
503no_available_node暂无匹配设备,任务会排队等待

供给方:把你的设备接进来

如果你有闲置 GPU,安装 Worker 后自动注册、测速评级、进入调度池,按单结算,收益七成归你。

wget https://www.kogun.site/static/kogun-worker.py
python3 kogun-worker.py --login 你的用户名 你的密码 --server www.kogun.site:443

自动测速评级

上报显存、算力、网络与稳定性,综合评分决定接单优先级与单价档位。

空闲才接单

可设工作时段与占用阈值,自己要用时一键暂停,不干扰本地工作。