跳到正文
← 返回接入教程

通用 SDK(Python / Node.js)

在自己的程序里调用 6090ti,可以直接使用 OpenAI 或 Anthropic 的官方 SDK,只需改接口地址和 Key。同一个 Key 两种 SDK 都能用,按要调用的模型选择:

要调用的模型使用的 SDK接口地址(base URL)
Claude 系列Anthropic SDKhttps://api.6090ti.com
GPT 等其他模型OpenAI SDKhttps://api.6090ti.com/v1

准备

  • 已注册账户、已充值,并在控制台创建了 API Key。
  • 用这个 Key 请求 /v1/models,从返回列表中选择要用的模型;价格页仅用于查看展示价格。下文用 <模型名> 表示。
  • 把 Key 保存在环境变量 P6090TI_API_KEY 里,不要直接写进代码。
# macOS / Linux
export P6090TI_API_KEY="<你的 Key>"

# Windows(运行后重新打开终端)
setx P6090TI_API_KEY "<你的 Key>"

Python

安装:

pip install openai anthropic

OpenAI SDK(GPT 等其他模型)

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.6090ti.com/v1",
    api_key=os.environ["P6090TI_API_KEY"],
)

resp = client.chat.completions.create(
    model="<模型名>",
    messages=[{"role": "user", "content": "用一句话介绍你自己"}],
)
print(resp.choices[0].message.content)

流式输出(边生成边显示):

stream = client.chat.completions.create(
    model="<模型名>",
    messages=[{"role": "user", "content": "写一首四行短诗"}],
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

OpenAI SDK 也可以用 Responses 接口:

resp = client.responses.create(model="<模型名>", input="只回复 OK")
print(resp.output_text)

Anthropic SDK(Claude 系列)

import os
import anthropic

client = anthropic.Anthropic(
    base_url="https://api.6090ti.com",
    api_key=os.environ["P6090TI_API_KEY"],
)

msg = client.messages.create(
    model="<模型名>",
    max_tokens=512,
    messages=[{"role": "user", "content": "用一句话介绍你自己"}],
)
print(msg.content[0].text)

流式输出:

with client.messages.stream(
    model="<模型名>",
    max_tokens=512,
    messages=[{"role": "user", "content": "写一首四行短诗"}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)

Node.js

安装:

npm install openai @anthropic-ai/sdk

OpenAI SDK(GPT 等其他模型)

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.6090ti.com/v1",
  apiKey: process.env.P6090TI_API_KEY,
});

const resp = await client.chat.completions.create({
  model: "<模型名>",
  messages: [{ role: "user", content: "用一句话介绍你自己" }],
});
console.log(resp.choices[0].message.content);

Anthropic SDK(Claude 系列)

import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  baseURL: "https://api.6090ti.com",
  apiKey: process.env.P6090TI_API_KEY,
});

const msg = await client.messages.create({
  model: "<模型名>",
  max_tokens: 512,
  messages: [{ role: "user", content: "用一句话介绍你自己" }],
});
console.log(msg.content[0].text);

以上 Node.js 示例使用 ES 模块写法,请把文件保存为 .mjs,或在 package.json 中设置 "type": "module"。

查询可用模型

用你的 Key 请求模型列表,返回的就是这个 Key 开通的模型:

curl https://api.6090ti.com/v1/models \
  -H "Authorization: Bearer <你的 Key>"

常见错误

  • 401:Key 填错或没有读到环境变量。
  • 403 余额不足:充值后重试。
  • 404 模型不可用:模型名写错,或你的 Key 没有开通这个模型。
  • SDK 与模型不匹配:Claude 系列模型请用 Anthropic SDK 和 https://api.6090ti.com;其他模型请用 OpenAI SDK 和 https://api.6090ti.com/v1。
  • 429:请求太频繁或上游繁忙,稍后重试,程序里建议加入退避重试。

完整的参数和错误说明见 API 文档。