开始/快速开始

创建 API Key、按任务选择接口,并完成第一条成功请求。

快速开始

四步从零到第一个成功的 API 响应。

第 1 步 — 注册账户

  1. 访问 UniGateway 登录页
  2. 使用邮箱地址登录

登录后进入控制台,可管理密钥、查看用量和配置路由。

第 2 步 — 充值余额

前往 设置 → 计费 充值余额。详见使用方案与定价

第 3 步 — 获取 API Key

  1. 在 UniGateway 控制台打开 设置 → API Keys
  2. 点击 创建密钥
  3. 立即复制密钥 — 仅显示一次
export UNIGATEWAY_API_KEY="<your-api-key>"

安全提示:API 密钥保存在环境变量或 .env 文件中,不要提交到代码仓库。

密钥轮换和多密钥策略参见账户与 API Key

第 4 步 — 发送第一个请求

UniGateway 支持三种 API 协议,选择你最熟悉的一种。

如果你已经知道要实现什么功能,可以先看这张表:

目标接口推荐首个模型
聊天或文本生成/v1/chat/completionsgpt-5.4
Claude 原生消息格式/v1/messagesclaude-sonnet-4-6
Gemini 原生文本/v1beta/models/gemini-3-pro-preview:generateContentgemini-3-pro-preview
图片生成/v1/images/generationsgpt-image-2
Gemini 图片生成/v1beta/models/gemini-3-pro-image-preview:generateContentgemini-3-pro-image-preview
语音转写/v1/audio/transcriptionswhisper-1
音频翻译/v1/audio/translationswhisper-1

投入生产前,请始终先用 GET /v1/models 确认模型 ID 可用。

协议 1:OpenAI Chat Completions

Base URL:https://api.unigateway.ai/v1

curl https://api.unigateway.ai/v1/chat/completions \
  -H "Authorization: Bearer $UNIGATEWAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "messages": [
      {"role": "user", "content": "生命的意义是什么?"}
    ]
  }'

Python(OpenAI SDK)

pip install openai
from openai import OpenAI

client = OpenAI(
    api_key="<YOUR_UNIGATEWAY_API_KEY>",
    base_url="https://api.unigateway.ai/v1",
)

completion = client.chat.completions.create(
    model="gpt-5.4",
    messages=[{"role": "user", "content": "生命的意义是什么?"}],
)

print(completion.choices[0].message.content)

TypeScript(OpenAI SDK)

npm install openai
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.UNIGATEWAY_API_KEY,
  baseURL: "https://api.unigateway.ai/v1",
});

const completion = await client.chat.completions.create({
  model: "gpt-5.4",
  messages: [{ role: "user", content: "生命的意义是什么?" }],
});

console.log(completion.choices[0].message.content);

协议 2:Anthropic Messages

Base URL:https://api.unigateway.ai/v1

curl https://api.unigateway.ai/v1/messages \
  -H "Authorization: Bearer $UNIGATEWAY_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Anthropic-Version: 2023-06-01" \
  -d '{
    "model": "claude-sonnet-4-6",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "生命的意义是什么?"}
    ]
  }'

Python(Anthropic SDK)

pip install anthropic
import anthropic

client = anthropic.Anthropic(
    api_key="<YOUR_UNIGATEWAY_API_KEY>",
    base_url="https://api.unigateway.ai/v1",
)

message = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{"role": "user", "content": "生命的意义是什么?"}],
)

print(message.content[0].text)

TypeScript(Anthropic SDK)

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

const client = new Anthropic({
  apiKey: process.env.UNIGATEWAY_API_KEY,
  baseURL: "https://api.unigateway.ai/v1",
});

const message = await client.messages.create({
  model: "claude-sonnet-4-6",
  max_tokens: 1024,
  messages: [{ role: "user", content: "生命的意义是什么?" }],
});

console.log(message.content[0].text);

协议 3:Google Gemini

Base URL:https://api.unigateway.ai/v1beta

curl https://api.unigateway.ai/v1beta/models/gemini-3-pro-preview:generateContent \
  -H "Authorization: Bearer $UNIGATEWAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {"parts": [{"text": "生命的意义是什么?"}]}
    ]
  }'

Python(requests)

pip install requests
import requests

api_key = "<YOUR_UNIGATEWAY_API_KEY>"
resp = requests.post(
    "https://api.unigateway.ai/v1beta/models/gemini-3-pro-preview:generateContent",
    headers={
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json",
    },
    json={
        "contents": [
            {"parts": [{"text": "生命的意义是什么?"}]}
        ]
    },
)
resp.raise_for_status()
print(resp.json()["candidates"][0]["content"]["parts"][0]["text"])
const resp = await fetch(
  "https://api.unigateway.ai/v1beta/models/gemini-3-pro-preview:generateContent",
  {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.UNIGATEWAY_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      contents: [{ parts: [{ text: "生命的意义是什么?" }] }],
    }),
  },
);

if (!resp.ok) {
  throw new Error(await resp.text());
}

const data = await resp.json();
console.log(data.candidates[0].content.parts[0].text);

查找模型 ID

UniGateway 上的每个模型都有唯一 ID。可在控制台浏览,或调用 API 查询:

curl https://api.unigateway.ai/v1/models \
  -H "Authorization: Bearer $UNIGATEWAY_API_KEY"

从返回中选择模型 ID。示例 ID — 以实时查询为准:

家族示例 ID
OpenAIgpt-5.4
Anthropicclaude-sonnet-4-6
Googlegemini-3-pro-preview

使用 GET /v1/models 返回的精确模型 ID,不要硬编码猜测名称。

模型库展示名不一定是可直接请求的模型 ID。请求中请使用 API 返回的 id 字段。

下一步

Example request

Run it in your stack

Pick the SDK style that matches your app and copy the snippet directly into your project.

from openai import OpenAI

client = OpenAI(
    api_key="<YOUR_UNIGATEWAY_API_KEY>",
    base_url="https://api.unigateway.ai/v1",
)

resp = client.chat.completions.create(
    model="gpt-5.4",
    messages=[
        {"role": "system", "content": "You are a concise assistant."},
        {"role": "user", "content": "Write a 1-line product tagline for UniGateway."},
    ],
    temperature=0.3,
)

print(resp.choices[0].message.content)