文档

快速开始

使用 OpenAI、Anthropic 和 Gemini 兼容接口完成首次调用

创建 API Key,完成首次调用并查看用量。

本页带你完成最小接入流程:选择分组并创建 Key → 发出第一条请求 → 查看用量与消费记录。

第 1 步:准备 API Key

登录控制台,在模型广场选择支持外接调用的分组,并创建 API Key。

接口格式示例模型对应分组
OpenAI Responsesgpt-6-astraCodex(可外接)
Anthropic Messagesclaude-opus-5-5Claude Code(可外接)
Gemini 原生接口gemini-4-argonGemini

调用前,确认账户有可用的套餐额度或灵活额度。

第 2 步:发出第一条请求

下面三种接口格式任选一种,并在每种格式下选择你正在使用的终端:macOS / Linux、Windows PowerShell 或 Windows Cmd。

Windows PowerShell 和 Cmd 使用不同的命令语法,请复制与你当前终端对应的示例。

AIGOCODE_API_KEY 应填写所选格式对应分组的 Key。切换格式时,同时更换环境变量中的 Key。

以下示例使用英文提示词,让不同终端都能直接复制执行。

OpenAI 格式:Responses API

调用 gpt-6-astra,请求地址为 POST /v1/responses。

macOS / Linux

export AIGOCODE_API_KEY="填写 Codex(可外接)分组的 Key"

curl "https://api.aigocode.dev/v1/responses" \
  -H "Authorization: Bearer $AIGOCODE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-6-astra",
    "input": "Reply with exactly: Hello from AIGoCode!"
  }'

Windows PowerShell

$env:AIGOCODE_API_KEY = "填写 Codex(可外接)分组的 Key"

$body = @{
  model = "gpt-6-astra"
  input = "Reply with exactly: Hello from AIGoCode!"
} | ConvertTo-Json -Depth 6

$response = Invoke-RestMethod `
  -Method Post `
  -Uri "https://api.aigocode.dev/v1/responses" `
  -Headers @{ Authorization = "Bearer $env:AIGOCODE_API_KEY" } `
  -ContentType "application/json; charset=utf-8" `
  -Body ([System.Text.Encoding]::UTF8.GetBytes($body))

$response | ConvertTo-Json -Depth 20

Windows Cmd

set "AIGOCODE_API_KEY=填写 Codex(可外接)分组的 Key"

curl.exe "https://api.aigocode.dev/v1/responses" ^
  -H "Authorization: Bearer %AIGOCODE_API_KEY%" ^
  -H "Content-Type: application/json" ^
  -d "{\"model\":\"gpt-6-astra\",\"input\":\"Reply with exactly: Hello from AIGoCode!\"}"

回复正文位于 output 中的消息内容,读取类型为 output_text 的文本。

Anthropic 格式:Messages API

调用 claude-opus-5-5,请求地址为 POST /v1/messages。

macOS / Linux

export AIGOCODE_API_KEY="填写 Claude Code(可外接)分组的 Key"

curl "https://api.aigocode.dev/v1/messages" \
  -H "x-api-key: $AIGOCODE_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-opus-5-5",
    "max_tokens": 512,
    "messages": [
      {
        "role": "user",
        "content": "Reply with exactly: Hello from AIGoCode!"
      }
    ]
  }'

Windows PowerShell

$env:AIGOCODE_API_KEY = "填写 Claude Code(可外接)分组的 Key"

$body = @{
  model = "claude-opus-5-5"
  max_tokens = 512
  messages = @(
    @{
      role = "user"
      content = "Reply with exactly: Hello from AIGoCode!"
    }
  )
} | ConvertTo-Json -Depth 6

$response = Invoke-RestMethod `
  -Method Post `
  -Uri "https://api.aigocode.dev/v1/messages" `
  -Headers @{
    "x-api-key" = $env:AIGOCODE_API_KEY
    "anthropic-version" = "2023-06-01"
  } `
  -ContentType "application/json; charset=utf-8" `
  -Body ([System.Text.Encoding]::UTF8.GetBytes($body))

$response | ConvertTo-Json -Depth 20

Windows Cmd

set "AIGOCODE_API_KEY=填写 Claude Code(可外接)分组的 Key"

curl.exe "https://api.aigocode.dev/v1/messages" ^
  -H "x-api-key: %AIGOCODE_API_KEY%" ^
  -H "anthropic-version: 2023-06-01" ^
  -H "Content-Type: application/json" ^
  -d "{\"model\":\"claude-opus-5-5\",\"max_tokens\":512,\"messages\":[{\"role\":\"user\",\"content\":\"Reply with exactly: Hello from AIGoCode!\"}]}"

回复正文位于 content 中类型为 text 的内容块。

Gemini 格式:generateContent

调用 gemini-4-argon,请求地址为 POST /v1beta/models/gemini-4-argon:generateContent。

macOS / Linux

export AIGOCODE_API_KEY="填写 Gemini 分组的 Key"

curl "https://api.aigocode.dev/v1beta/models/gemini-4-argon:generateContent" \
  -H "x-goog-api-key: $AIGOCODE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "parts": [
          {
            "text": "Reply with exactly: Hello from AIGoCode!"
          }
        ]
      }
    ]
  }'

Windows PowerShell

$env:AIGOCODE_API_KEY = "填写 Gemini 分组的 Key"

$body = @{
  contents = @(
    @{
      parts = @(
        @{ text = "Reply with exactly: Hello from AIGoCode!" }
      )
    }
  )
} | ConvertTo-Json -Depth 6

$response = Invoke-RestMethod `
  -Method Post `
  -Uri "https://api.aigocode.dev/v1beta/models/gemini-4-argon:generateContent" `
  -Headers @{ "x-goog-api-key" = $env:AIGOCODE_API_KEY } `
  -ContentType "application/json; charset=utf-8" `
  -Body ([System.Text.Encoding]::UTF8.GetBytes($body))

$response | ConvertTo-Json -Depth 20

Windows Cmd

set "AIGOCODE_API_KEY=填写 Gemini 分组的 Key"

curl.exe "https://api.aigocode.dev/v1beta/models/gemini-4-argon:generateContent" ^
  -H "x-goog-api-key: %AIGOCODE_API_KEY%" ^
  -H "Content-Type: application/json" ^
  -d "{\"contents\":[{\"parts\":[{\"text\":\"Reply with exactly: Hello from AIGoCode!\"}]}]}"

回复正文位于 candidates 中的 content.parts 文本内容。

三种示例成功时,响应正文应包含:

Hello from AIGoCode!

第 3 步:查看用量与消费

进入控制台的「使用统计」,可以查看请求数量、额度消耗、输入输出与缓存 Token、模型分布和使用趋势,并在请求日志中核对逐次消费。

套餐额度与灵活额度的消耗会分别展示,具体规则见「计费与余额」。

下一步

  • Agent 工具接入:将服务配置到 Claude Code、Codex 等工具。
  • API 参考:查看接口参数、请求与响应格式。
  • 模型名称列表:查询其他模型 ID。
  • 错误码:请求失败时,核对 Key 分组、认证字段、地址和账户额度。

本页目录