AIGoCode Docs

OpenAI Compatible

使用 OpenAI 兼容协议调用 AIGoCode

OpenAI Compatible 适合已有 OpenAI SDK、OpenAI 风格客户端或自写 HTTP 请求的场景。

Base URL

https://api.aigocode.com/v1

请求示例

chat.completions
curl https://api.aigocode.com/v1/chat/completions \
  -H "Authorization: Bearer $AIGOCODE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "messages": [
      {
        "role": "user",
        "content": "用一句话介绍 AIGoCode"
      }
    ]
  }'
openai.ts
import OpenAI from "openai";

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

const response = await client.chat.completions.create({
  model: "gpt-5.4",
  messages: [
    {
      role: "user",
      content: "Hello from AIGoCode",
    },
  ],
});

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

图片生成示例

image-2 使用 OpenAI Compatible 的 Images API。下面示例会生成一张 PNG,并把返回的 b64_json 保存到本地文件。

images.generations
curl https://api.aigocode.com/v1/images/generations \
  -H "Authorization: Bearer $AIGOCODE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "image-2",
    "prompt": "一张未来感城市夜景海报,霓虹灯,电影级光影",
    "size": "1024x1024",
    "n": 1,
    "response_format": "b64_json"
  }'
image-2.ts
import { writeFile } from "node:fs/promises";

const response = await fetch("https://api.aigocode.com/v1/images/generations", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.AIGOCODE_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "image-2",
    prompt: "一张未来感城市夜景海报,霓虹灯,电影级光影",
    size: "1024x1024",
    n: 1,
    response_format: "b64_json",
  }),
});

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

const result = await response.json();
const imageBase64 = result.data?.[0]?.b64_json;

if (!imageBase64) {
  throw new Error("No image returned");
}

await writeFile("image-2.png", Buffer.from(imageBase64, "base64"));

模型 ID 见 模型名称列表

On this page