第一次请求
使用 OpenAI、Claude 和 Gemini 兼容接口完成聊天请求
下面分别用 OpenAI Compatible、Claude Messages 和 Gemini generateContent 接口完成一次最小请求。请选择你使用的接口和环境,并把示例中的 API Key 换成你的真实密钥。
OpenAI Compatible
export AIGOCODE_API_KEY="在这里填写你的 AIGoCode API Key"
curl https://api.aigocode.app/v1/chat/completions \
-H "Authorization: Bearer $AIGOCODE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6-astra",
"messages": [
{
"role": "user",
"content": "Hello from AIGoCode!"
}
]
}'set "AIGOCODE_API_KEY=在这里填写你的 AIGoCode API Key"
curl.exe "https://api.aigocode.app/v1/chat/completions" ^
-H "Authorization: Bearer %AIGOCODE_API_KEY%" ^
-H "Content-Type: application/json" ^
-d "{\"model\":\"gpt-6-astra\",\"messages\":[{\"role\":\"user\",\"content\":\"Hello from AIGoCode!\"}]}"$env:AIGOCODE_API_KEY = "在这里填写你的 AIGoCode API Key"
$body = @{
model = "gpt-6-astra"
messages = @(
@{
role = "user"
content = "Hello from AIGoCode!"
}
)
} | ConvertTo-Json -Depth 3
$response = Invoke-RestMethod `
-Method Post `
-Uri "https://api.aigocode.app/v1/chat/completions" `
-Headers @{
Authorization = "Bearer $env:AIGOCODE_API_KEY"
} `
-ContentType "application/json" `
-Body $body
$response | ConvertTo-Json -Depth 10from openai import OpenAI
client = OpenAI(
api_key="在这里填写你的 AIGoCode API Key",
base_url="https://api.aigocode.app/v1",
)
response = client.chat.completions.create(
model="gpt-6-astra",
messages=[
{
"role": "user",
"content": "Hello from AIGoCode!",
}
],
)
print(response.model_dump_json(indent=2))import OpenAI from "openai";
const client = new OpenAI({
apiKey: "在这里填写你的 AIGoCode API Key",
baseURL: "https://api.aigocode.app/v1",
});
const response = await client.chat.completions.create({
model: "gpt-6-astra",
messages: [
{
role: "user",
content: "Hello from AIGoCode!",
},
],
});
console.log(JSON.stringify(response, null, 2));成功响应
成功后会返回 OpenAI Compatible 格式的响应,其中 choices[0].message.content 是模型回复内容。
{
"id": "resp_xxx",
"object": "chat.completion",
"created": xxxxxx,
"model": "gpt-6-astra",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello, AIGoCode! How can I help today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": xx,
"completion_tokens": xx,
"total_tokens": xx
},
"service_tier": "default"
}Claude Messages
使用 Claude Messages 接口调用 Claude Sonnet 5。
export AIGOCODE_API_KEY="在这里填写你的 AIGoCode API Key"
curl https://api.aigocode.app/v1/messages \
-H "x-api-key: $AIGOCODE_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5",
"max_tokens": 512,
"messages": [
{
"role": "user",
"content": "Hello from AIGoCode!"
}
]
}'set "AIGOCODE_API_KEY=在这里填写你的 AIGoCode API Key"
curl.exe "https://api.aigocode.app/v1/messages" ^
-H "x-api-key: %AIGOCODE_API_KEY%" ^
-H "anthropic-version: 2023-06-01" ^
-H "Content-Type: application/json" ^
-d "{\"model\":\"claude-sonnet-5\",\"max_tokens\":512,\"messages\":[{\"role\":\"user\",\"content\":\"Hello from AIGoCode!\"}]}"$env:AIGOCODE_API_KEY = "在这里填写你的 AIGoCode API Key"
$body = @{
model = "claude-sonnet-5"
max_tokens = 512
messages = @(
@{
role = "user"
content = "Hello from AIGoCode!"
}
)
} | ConvertTo-Json -Depth 3
$response = Invoke-RestMethod `
-Method Post `
-Uri "https://api.aigocode.app/v1/messages" `
-Headers @{
"x-api-key" = $env:AIGOCODE_API_KEY
"anthropic-version" = "2023-06-01"
} `
-ContentType "application/json" `
-Body $body
$response | ConvertTo-Json -Depth 10import json
from urllib.request import Request, urlopen
api_key = "在这里填写你的 AIGoCode API Key"
body = {
"model": "claude-sonnet-5",
"max_tokens": 512,
"messages": [
{
"role": "user",
"content": "Hello from AIGoCode!",
}
],
}
request = Request(
"https://api.aigocode.app/v1/messages",
data=json.dumps(body).encode("utf-8"),
headers={
"x-api-key": api_key,
"anthropic-version": "2023-06-01",
"Content-Type": "application/json",
},
method="POST",
)
with urlopen(request) as response:
result = json.load(response)
print(json.dumps(result, ensure_ascii=False, indent=2))const apiKey = "在这里填写你的 AIGoCode API Key";
const response = await fetch("https://api.aigocode.app/v1/messages", {
method: "POST",
headers: {
"x-api-key": apiKey,
"anthropic-version": "2023-06-01",
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "claude-sonnet-5",
max_tokens: 512,
messages: [
{
role: "user",
content: "Hello from AIGoCode!",
},
],
}),
});
const result = await response.json();
if (!response.ok) {
throw new Error(JSON.stringify(result));
}
console.log(JSON.stringify(result, null, 2));成功响应
以下是使用上面的请求体真实调用 claude-sonnet-5 得到的响应。
{
"id": "msg_xxx",
"type": "message",
"role": "assistant",
"model": "claude-sonnet-5",
"content": [
{
"type": "text",
"text": "Hello! Claude here, from Anthropic. What can I help you with today — code, questions, writing, or something else?",
"citations": []
}
],
"stop_reason": "end_turn",
"stop_sequence": null,
"stop_details": null,
"context_management": {
"applied_edits": []
},
"usage": {
"input_tokens": xx,
"cache_creation_input_tokens": xx,
"cache_read_input_tokens": xx,
"cache_creation": {
"ephemeral_5m_input_tokens": xx,
"ephemeral_1h_input_tokens": xx
},
"output_tokens": xx,
"output_tokens_details": {
"thinking_tokens": xx
},
"service_tier": "standard",
"inference_geo": "not_available"
}
}Gemini generateContent
使用 Gemini generateContent 接口调用 Gemini 3.8 Flash。
export AIGOCODE_API_KEY="在这里填写你的 AIGoCode API Key"
curl "https://api.aigocode.app/v1beta/models/gemini-3.8-flash:generateContent?key=$AIGOCODE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"parts": [
{
"text": "Hello from AIGoCode!"
}
]
}
],
"generationConfig": {
"thinkingConfig": {
"thinkingBudget": 0,
"includeThoughts": false
}
}
}'set "AIGOCODE_API_KEY=在这里填写你的 AIGoCode API Key"
curl.exe "https://api.aigocode.app/v1beta/models/gemini-3.8-flash:generateContent?key=%AIGOCODE_API_KEY%" ^
-H "Content-Type: application/json" ^
-d "{\"contents\":[{\"parts\":[{\"text\":\"Hello from AIGoCode!\"}]}],\"generationConfig\":{\"thinkingConfig\":{\"thinkingBudget\":0,\"includeThoughts\":false}}}"$env:AIGOCODE_API_KEY = "在这里填写你的 AIGoCode API Key"
$body = @{
contents = @(
@{
parts = @(
@{
text = "Hello from AIGoCode!"
}
)
}
)
generationConfig = @{
thinkingConfig = @{
thinkingBudget = 0
includeThoughts = $false
}
}
} | ConvertTo-Json -Depth 7
$response = Invoke-RestMethod `
-Method Post `
-Uri "https://api.aigocode.app/v1beta/models/gemini-3.8-flash:generateContent?key=$env:AIGOCODE_API_KEY" `
-ContentType "application/json" `
-Body $body
$response | ConvertTo-Json -Depth 10import json
from urllib.parse import quote
from urllib.request import Request, urlopen
api_key = "在这里填写你的 AIGoCode API Key"
url = (
"https://api.aigocode.app/v1beta/models/"
f"gemini-3.8-flash:generateContent?key={quote(api_key, safe='')}"
)
body = {
"contents": [
{
"parts": [
{
"text": "Hello from AIGoCode!",
}
]
}
],
"generationConfig": {
"thinkingConfig": {
"thinkingBudget": 0,
"includeThoughts": False,
}
},
}
request = Request(
url,
data=json.dumps(body).encode("utf-8"),
headers={"Content-Type": "application/json"},
method="POST",
)
with urlopen(request) as response:
result = json.load(response)
print(json.dumps(result, ensure_ascii=False, indent=2))const apiKey = "在这里填写你的 AIGoCode API Key";
const url =
"https://api.aigocode.app/v1beta/models/" +
`gemini-3.8-flash:generateContent?key=${encodeURIComponent(apiKey)}`;
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
contents: [
{
parts: [
{
text: "Hello from AIGoCode!",
},
],
},
],
generationConfig: {
thinkingConfig: {
thinkingBudget: 0,
includeThoughts: false,
},
},
}),
});
const result = await response.json();
if (!response.ok) {
throw new Error(JSON.stringify(result));
}
console.log(JSON.stringify(result, null, 2));成功响应
以下是使用上面的请求体真实调用 gemini-3.8-flash 得到的响应。
{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"thoughtSignature": "xxx",
"text": "Hello to the team at AIGoCode! 👋\n\nHow can I help you today? Whether you're working on code, brainstorming features, or tackling a tough technical problem, I'm ready to assist."
}
]
},
"finishReason": "STOP"
}
],
"usageMetadata": {
"promptTokenCount": xx,
"candidatesTokenCount": xx,
"totalTokenCount": xx
},
"modelVersion": "gemini-3.8-flash",
"responseId": "resp_xxx"
}下一步
- 如果返回
401,检查 认证方式。 - 如果返回
403或余额相关错误,查看 账户与额度。 - 如果你想直接配置工具,查看 Claude Code、Codex 或 API 接入工具。