快速开始
1. 注册账号
打开 控制台,使用邮箱或 GitHub OAuth 登录;首次登录会自动创建账号。
2. 获取 API Key
进入 API Keys 页面,点击 新建 API Key,复制以 sk- 开头的字符串。Key 仅在创建时完整展示一次,请立即妥善保存;离开页面后将只能看到掩码。
TIP
建议把 Key 写入环境变量,例如 export SAKRYLLE_API_KEY=sk-xxxxxxxxxxxxxxxx,避免误提交到代码仓库。
3. 第一次请求
下面用 gpt-5.6-sol 调用 /v1/chat/completions:
bash
curl https://api.sakrylle.com/v1/chat/completions \
-H "Authorization: Bearer $SAKRYLLE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.6-sol",
"messages": [
{"role": "user", "content": "自我介绍一下。"}
]
}'python
# pip install openai
from openai import OpenAI
import os
client = OpenAI(
base_url="https://api.sakrylle.com/v1",
api_key=os.environ["SAKRYLLE_API_KEY"],
)
resp = client.chat.completions.create(
model="gpt-5.6-sol",
messages=[{"role": "user", "content": "自我介绍一下。"}],
)
print(resp.choices[0].message.content)javascript
// npm install openai
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.sakrylle.com/v1",
apiKey: process.env.SAKRYLLE_API_KEY,
});
const resp = await client.chat.completions.create({
model: "gpt-5.6-sol",
messages: [{ role: "user", content: "自我介绍一下。" }],
});
console.log(resp.choices[0].message.content);go
// go get github.com/openai/openai-go
package main
import (
"context"
"fmt"
"os"
"github.com/openai/openai-go"
"github.com/openai/openai-go/option"
)
func main() {
client := openai.NewClient(
option.WithBaseURL("https://api.sakrylle.com/v1"),
option.WithAPIKey(os.Getenv("SAKRYLLE_API_KEY")),
)
resp, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{
Model: openai.F("gpt-5.6-sol"),
Messages: openai.F([]openai.ChatCompletionMessageParamUnion{
openai.UserMessage("自我介绍一下。"),
}),
})
if err != nil {
panic(err)
}
fmt.Println(resp.Choices[0].Message.Content)
}rust
// cargo add reqwest --features json,rustls-tls
// cargo add tokio --features full
// cargo add serde_json
use reqwest::Client;
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let key = std::env::var("SAKRYLLE_API_KEY")?;
let body = json!({
"model": "gpt-5.6-sol",
"messages": [{"role": "user", "content": "自我介绍一下。"}]
});
let resp: serde_json::Value = Client::new()
.post("https://api.sakrylle.com/v1/chat/completions")
.bearer_auth(key)
.json(&body)
.send().await?
.json().await?;
println!("{}", resp["choices"][0]["message"]["content"]);
Ok(())
}java
// 标准库 java.net.http;JDK 11+
import java.net.URI;
import java.net.http.*;
public class Quickstart {
public static void main(String[] args) throws Exception {
String key = System.getenv("SAKRYLLE_API_KEY");
String body = """
{"model":"gpt-5.6-sol",
"messages":[{"role":"user","content":"自我介绍一下。"}]}
""";
HttpRequest req = HttpRequest.newBuilder()
.uri(URI.create("https://api.sakrylle.com/v1/chat/completions"))
.header("Authorization", "Bearer " + key)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> resp = HttpClient.newHttpClient()
.send(req, HttpResponse.BodyHandlers.ofString());
System.out.println(resp.body());
}
}csharp
// dotnet add package System.Net.Http.Json
using System.Net.Http.Headers;
using System.Net.Http.Json;
var key = Environment.GetEnvironmentVariable("SAKRYLLE_API_KEY");
using var http = new HttpClient { BaseAddress = new Uri("https://api.sakrylle.com/v1/") };
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", key);
var resp = await http.PostAsJsonAsync("chat/completions", new {
model = "gpt-5.6-sol",
messages = new[] { new { role = "user", content = "自我介绍一下。" } }
});
Console.WriteLine(await resp.Content.ReadAsStringAsync());4. 流式响应
把 stream 设为 true,服务器会以 SSE(text/event-stream)逐 token 推送增量。
bash
curl https://api.sakrylle.com/v1/chat/completions \
-H "Authorization: Bearer $SAKRYLLE_API_KEY" \
-H "Content-Type: application/json" \
-N \
-d '{
"model": "gpt-5.6-sol",
"stream": true,
"messages": [{"role": "user", "content": "讲一个关于樱花的短故事。"}]
}'python
from openai import OpenAI
import os
client = OpenAI(
base_url="https://api.sakrylle.com/v1",
api_key=os.environ["SAKRYLLE_API_KEY"],
)
stream = client.chat.completions.create(
model="gpt-5.6-sol",
stream=True,
messages=[{"role": "user", "content": "讲一个关于樱花的短故事。"}],
)
for chunk in stream:
delta = chunk.choices[0].delta.content or ""
print(delta, end="", flush=True)javascript
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.sakrylle.com/v1",
apiKey: process.env.SAKRYLLE_API_KEY,
});
const stream = await client.chat.completions.create({
model: "gpt-5.6-sol",
stream: true,
messages: [{ role: "user", content: "讲一个关于樱花的短故事。" }],
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}go
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/openai/openai-go"
"github.com/openai/openai-go/option"
)
func main() {
client := openai.NewClient(
option.WithBaseURL("https://api.sakrylle.com/v1"),
option.WithAPIKey(os.Getenv("SAKRYLLE_API_KEY")),
)
stream := client.Chat.Completions.NewStreaming(context.Background(), openai.ChatCompletionNewParams{
Model: openai.F("gpt-5.6-sol"),
Messages: openai.F([]openai.ChatCompletionMessageParamUnion{
openai.UserMessage("讲一个关于樱花的短故事。"),
}),
})
for stream.Next() {
chunk := stream.Current()
if len(chunk.Choices) > 0 {
fmt.Print(chunk.Choices[0].Delta.Content)
}
}
if err := stream.Err(); err != nil && err != io.EOF {
panic(err)
}
}rust
use futures_util::StreamExt;
use reqwest::Client;
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let key = std::env::var("SAKRYLLE_API_KEY")?;
let body = json!({
"model": "gpt-5.6-sol",
"stream": true,
"messages": [{"role": "user", "content": "讲一个关于樱花的短故事。"}]
});
let mut stream = Client::new()
.post("https://api.sakrylle.com/v1/chat/completions")
.bearer_auth(key)
.json(&body)
.send().await?
.bytes_stream();
while let Some(chunk) = stream.next().await {
print!("{}", String::from_utf8_lossy(&chunk?));
}
Ok(())
}java
import java.net.URI;
import java.net.http.*;
public class Stream {
public static void main(String[] args) throws Exception {
String key = System.getenv("SAKRYLLE_API_KEY");
String body = """
{"model":"gpt-5.6-sol","stream":true,
"messages":[{"role":"user","content":"讲一个关于樱花的短故事。"}]}
""";
HttpRequest req = HttpRequest.newBuilder()
.uri(URI.create("https://api.sakrylle.com/v1/chat/completions"))
.header("Authorization", "Bearer " + key)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpClient.newHttpClient()
.send(req, HttpResponse.BodyHandlers.ofLines())
.body()
.forEach(System.out::println);
}
}csharp
using System.Net.Http.Headers;
var key = Environment.GetEnvironmentVariable("SAKRYLLE_API_KEY");
using var http = new HttpClient();
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", key);
var content = new StringContent("""
{"model":"gpt-5.6-sol","stream":true,
"messages":[{"role":"user","content":"讲一个关于樱花的短故事。"}]}
""", System.Text.Encoding.UTF8, "application/json");
using var resp = await http.PostAsync(
"https://api.sakrylle.com/v1/chat/completions", content,
HttpCompletionOption.ResponseHeadersRead);
using var stream = await resp.Content.ReadAsStreamAsync();
using var reader = new StreamReader(stream);
string? line;
while ((line = await reader.ReadLineAsync()) != null) {
Console.WriteLine(line);
}5. Anthropic 格式
把 endpoint 换成 /v1/messages、模型换成 claude-haiku-4-5-20251001,并按 Anthropic 文档构造 messages:
bash
curl https://api.sakrylle.com/v1/messages \
-H "Authorization: Bearer $SAKRYLLE_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-haiku-4-5-20251001",
"max_tokens": 256,
"messages": [
{"role": "user", "content": "自我介绍一下。"}
]
}'python
# pip install anthropic
from anthropic import Anthropic
import os
client = Anthropic(
base_url="https://api.sakrylle.com",
api_key=os.environ["SAKRYLLE_API_KEY"],
)
resp = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=256,
messages=[{"role": "user", "content": "自我介绍一下。"}],
)
print(resp.content[0].text)javascript
// npm install @anthropic-ai/sdk
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://api.sakrylle.com",
apiKey: process.env.SAKRYLLE_API_KEY,
});
const resp = await client.messages.create({
model: "claude-haiku-4-5-20251001",
max_tokens: 256,
messages: [{ role: "user", content: "自我介绍一下。" }],
});
console.log(resp.content[0].text);TIP
官方 Anthropic SDK 默认会读取 ANTHROPIC_API_KEY;这里我们显式传 api_key=SAKRYLLE_API_KEY 是因为用的是同一个 Sakrylle Key。base_url 不需要 /v1 后缀,SDK 会自动补上。
