快速开始/快速开始

创建 API Key、把 SDK 指向 UniGateway,并完成第一条成功请求。

快速开始

本指南帮助你从 API Key 到首条成功响应。

前置条件

  1. 拥有可用的 UniGateway 账号。
  2. 在控制台创建 API Key。
  3. 账户余额或额度可用。

1. 准备 API Key

export UNIGATEWAY_API_KEY="<your-key>"

2. 先确认可用模型

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

从返回结果中选择一个模型 ID。

3. 发送首条 Chat 请求

curl https://api.unigateway.ai/v1/chat/completions \
  -H "Authorization: Bearer $UNIGATEWAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.2",
    "messages": [
      {"role": "user", "content": "为 UniGateway 写一句上线公告。"}
    ]
  }'

4. 切换不同模型家族

接口不变,只改 model

  • OpenAI:gpt-5.2
  • Claude:claude-sonnet-4-6
  • Gemini:gemini-3-pro-preview

正式接入前建议补齐回退链策略,见 模型选择与回退

Python 示例

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="claude-sonnet-4-6",
    messages=[{"role": "user", "content": "用 3 点总结 UniGateway。"}],
)

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

TypeScript 示例

import OpenAI from "openai";

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

const resp = await client.chat.completions.create({
  model: "gemini-3-pro-preview",
  messages: [{ role: "user", content: "给我一个 API 上线检查清单。" }],
});

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

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.2",
    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)