Skip to content

快速开始

1. 创建 API Key

前往 API Keys 页面创建一个新密钥。请妥善保存,密钥只显示一次。

2. 设置 Base URL

将 OpenAI 兼容客户端指向我们的端点:

https://api.jarvisclaw.ai/v1

3. 发送第一个请求

使用任何 OpenAI 兼容 SDK 或纯 HTTP 请求。将 model 设为 "auto" 即可启用智能路由自动选择最优模型。

python
from jarvisclaw import ChatClient

chat = ChatClient(api_key="sk-your-api-key")

# 极简调用 — 一行输入,一行输出
print(chat.complete("你好!"))

# 流式输出
for chunk in chat.stream("讲个笑话"):
    print(chunk, end="")
javascript
import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://api.jarvisclaw.ai/v1',
  apiKey: 'sk-your-api-key',
});

const response = await client.chat.completions.create({
  model: 'auto',
  messages: [{ role: 'user', content: '你好!' }],
  stream: true,
});
for await (const chunk of response) {
  process.stdout.write(chunk.choices[0]?.delta?.content || '');
}
bash
curl https://api.jarvisclaw.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-your-api-key" \
  -d '{"model": "auto", "messages": [{"role": "user", "content": "你好!"}]}'
go
import jarvisclaw "github.com/api-jarvisclaw/go-sdk/v2"

client, _ := jarvisclaw.NewChatClient(jarvisclaw.WithAPIKey("sk-your-api-key"))

// 简单对话
text, _ := client.Complete(ctx, "你好!")
fmt.Println(text)

// 流式输出
stream, _ := client.Stream(ctx, "讲个笑话")
for chunk := range stream.Channel() {
    fmt.Print(chunk)
}