# pip install requests
import json
import requests
resp = requests.post(
"https://api.i3m.cn/api/coding/paas/v4/chat/completions",
headers={
"Authorization": "Bearer sk-your-api-key",
"Content-Type": "application/json",
},
json={
"model": "gpt-4o",
"messages": [{"role": "user", "content": "写一首诗"}],
"stream": True,
"stream_options": {"include_usage": True},
},
stream=True,
)
for line in resp.iter_lines():
if not line or not line.startswith(b"data:"):
continue
data = line[5:].strip()
if data == b"[DONE]":
break
chunk = json.loads(data)
if chunk.get("usage"):
print("\nusage:", chunk["usage"])
for choice in chunk.get("choices", []):
print(choice["delta"].get("content", ""), end="")
javascript
const resp = await fetch("https://api.i3m.cn/api/coding/paas/v4/chat/completions", {
method: "POST",
headers: {
Authorization: "Bearer sk-your-api-key",
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "gpt-4o",
messages: [{ role: "user", content: "写一首诗" }],
stream: true,
stream_options: { include_usage: true }
})
});
const reader = resp.body.getReader();
const decoder = new TextDecoder();
let buffer = "";
while (true) {
const { value, done } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });
const lines = buffer.split("\n");
buffer = lines.pop();
for (const line of lines) {
if (!line.startsWith("data:")) continue;
const data = line.slice(5).trim();
if (data === "[DONE]") continue;
const chunk = JSON.parse(data);
if (chunk.usage) console.log("\nusage:", chunk.usage);
for (const choice of chunk.choices || []) {
process.stdout.write(choice.delta?.content || "");
}
}
}
with client.messages.stream(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello, Claude!"}]
) as stream:
for text in stream.text_stream:
print(text, end="")
EchoBird、CodexBar、QuotaKit 这类工具的「Sub2API」账号类型,会自动向站点请求 GET /v1/usage。在这类工具里把站点地址填成 https://api.i3m.cn、密钥填本站 API 密钥即可,不用额外配置。完整地址:GET https://api.i3m.cn/v1/usage。
配置里的接口地址(baseUrl)填 https://api.i3m.cn/v1,密钥填本站 API 密钥
现金余额
deepseek-whale-pet(独立桌宠)
设置里的「余额接口地址」填 https://api.i3m.cn/v1/user/balance,密钥填本站 API 密钥
现金余额、今日花费
dsh-pet(DSH 桌宠)
装配套插件 dsh-pet-xuanju-balance:dsh plugin --profile web add dsh-pet-xuanju-balance(桌面应用把 web 换成 desktop,或在「插件管理」里填包名),装完重启 DSH。服务商的接口地址填 https://api.i3m.cn/v1、密钥填本站 API 密钥,插件自动沿用