claude-fable-5
最后更新:2026-11-14
POSThttps://www.sagelib.com/anthropic/v1/messages
claude-fable-5 模型的聊天生成接口,Anthropic直连,支持多轮上下文、流式输出、工具调用、结构化输出等。
接口鉴权方式请参考:API接入与鉴权
请求参数
请求头
| 参数名称 | 描述 |
|---|---|
*Content-Type string |
可选值:application/json application/json |
*anthropic-version string |
可选值:2023-06-01 Anthropic API 版本号,固定为 2023-06-01 |
*X-Api-Key string |
鉴权令牌,格式为 ${AIGATEWAY_TOKEN} |
Body 参数
| 参数名称 | 描述 |
|---|---|
*model string |
可选值:"claude-fable-5" 模型名称,须精确匹配 |
*messages array |
可选值:content 对话消息列表,首条须为 user 角色 |
*max_tokens integer |
可选值:1 ~ 128000 最大输出 token 数,上限 128000 |
system string |
可选值:String or content block array 系统提示词,Anthropic 顶层参数(非 messages 数组内) |
stop_sequences array |
可选值:String array, up to 4 items 自定义停止序列 |
stream boolean |
默认值:false 可选值:true、false 是否启用 SSE 流式输出 |
tools array |
可选值:Array of Anthropic-format tool definitions 工具定义列表,含 name/description/input_schema |
tool_choice object |
可选值:auto、any、tool、none 工具选择策略,Anthropic 对象格式 |
metadata object |
可选值:Contains user_id sub-field 请求元数据,user_id 禁止含 PII |
thinking object |
可选值:adaptive、enabled 思考配置,支持 enabled(需 budget_tokens >= 1024)与 adaptive |
cache_control object |
可选值:type: ephemeral 缓存控制,最低 1024 tokens |
service_tier string |
可选值:auto、standard_only 服务层级 |
container string |
可选值:String 容器标识符 |
betas array |
可选值:Array of beta feature names 模型支持的 Beta 特性列表,需通过 anthropic-beta HTTP Header 传递 |
output_config object |
可选值:medium、high、xhigh、max 输出配置,含推理力度与结构化输出 |
inference_geo string |
可选值:String 推理地理区域 |
fallbacks array |
可选值:Array of model names 服务端模型降级链,主模型失败时按序切换 |
context_management object |
可选值:Object 上下文管理配置 |
请求示例
curl -v 'https://www.sagelib.com/anthropic/messages' \
-H "x-api-key: ***" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-fable-5",
"max_tokens": 2048,
"messages": [
{
"role": "user",
"content": "Hello"
}
]
}'
import json
import requests
# Configure base variables
base_url = "https://www.sagelib.com" # 把 base_url 换成你的网关地址 https://www.sagelib.com
api_key = "***" # Replace with your API key
url = f"https://www.sagelib.com/anthropic/messages"
headers = {
"x-api-key": api_key,
"anthropic-version": "2023-06-01",
"Content-Type": "application/json",
}
data = {
"model": "claude-fable-5",
"max_tokens": 2048,
"messages": [
{
"role": "user",
"content": "Hello"
}
]
}
# Send the POST request
response = requests.post(url, headers=headers, json=data)
# Print the status code and the returned JSON data
print(f"Status Code: {response.status_code}")
try:
print(json.dumps(response.json(), indent=2, ensure_ascii=False))
except Exception:
print(response.text)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class LlmStreamClient {
public static void main(String[] args) {
String baseUrl = "https://www.sagelib.com";
String apiKey = "***";
String url = "https://www.sagelib.com/anthropic/messages";
String jsonRequestBody = """
{
"model": "claude-fable-5",
"max_tokens": 2048,
"messages": [
{
"role": "user",
"content": "Hello"
}
]
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("x-api-key", apiKey).header("anthropic-version", "2023-06-01")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonRequestBody))
.build();
try {
// Use ofInputStream to handle the streaming response
HttpResponse<java.io.InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.body()))) {
String line;
while ((line = reader.readLine()) != null) {
line = line.trim();
if (line.startsWith("data:")) {
String data = line.substring(5).trim();
if ("[DONE]".equals(data)) {
break;
}
// Tip: you can bring in Gson or Jackson here to parse the JSON in data and extract delta.content
System.out.println("Received stream chunk: " + data);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
baseUrl := "https://www.sagelib.com"
apiKey := "***"
url := "https://www.sagelib.com/anthropic/messages"
jsonRequestBody := `
{
"model": "claude-fable-5",
"max_tokens": 2048,
"messages": [
{
"role": "user",
"content": "Hello"
}
]
}
`
req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonRequestBody))
if err != nil {
fmt.Println("Failed to create request:", err)
return
}
req.Header.Set("x-api-key", apiKey)
req.Header.Set("anthropic-version", "2023-06-01")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Request failed:", err)
return
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
// Pretty-print the returned JSON data
var prettyBody map[string]interface{}
if err := json.Unmarshal(body, &prettyBody); err == nil {
pretty, _ := json.MarshalIndent(prettyBody, "", " ")
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println(string(pretty))
} else {
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println(string(body))
}
}
curl -v 'https://www.sagelib.com/anthropic/messages' \
-H "x-api-key: ***" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-fable-5",
"max_tokens": 8192,
"thinking": {
"type": "enabled",
"budget_tokens": 4096
},
"messages": [
{
"role": "user",
"content": "Analyze the pros and cons comparison of Paxos vs Raft consensus algorithms"
}
]
}'
import json
import requests
# Configure base variables
base_url = "https://www.sagelib.com" # 把 base_url 换成你的网关地址 https://www.sagelib.com
api_key = "***" # Replace with your API key
url = f"https://www.sagelib.com/anthropic/messages"
headers = {
"x-api-key": api_key,
"anthropic-version": "2023-06-01",
"Content-Type": "application/json",
}
data = {
"model": "claude-fable-5",
"max_tokens": 8192,
"thinking": {
"type": "enabled",
"budget_tokens": 4096
},
"messages": [
{
"role": "user",
"content": "Analyze the pros and cons comparison of Paxos vs Raft consensus algorithms"
}
]
}
# Send the POST request
response = requests.post(url, headers=headers, json=data)
# Print the status code and the returned JSON data
print(f"Status Code: {response.status_code}")
try:
print(json.dumps(response.json(), indent=2, ensure_ascii=False))
except Exception:
print(response.text)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class LlmStreamClient {
public static void main(String[] args) {
String baseUrl = "https://www.sagelib.com";
String apiKey = "***";
String url = "https://www.sagelib.com/anthropic/messages";
String jsonRequestBody = """
{
"model": "claude-fable-5",
"max_tokens": 8192,
"thinking": {
"type": "enabled",
"budget_tokens": 4096
},
"messages": [
{
"role": "user",
"content": "Analyze the pros and cons comparison of Paxos vs Raft consensus algorithms"
}
]
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("x-api-key", apiKey).header("anthropic-version", "2023-06-01")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonRequestBody))
.build();
try {
// Use ofInputStream to handle the streaming response
HttpResponse<java.io.InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.body()))) {
String line;
while ((line = reader.readLine()) != null) {
line = line.trim();
if (line.startsWith("data:")) {
String data = line.substring(5).trim();
if ("[DONE]".equals(data)) {
break;
}
// Tip: you can bring in Gson or Jackson here to parse the JSON in data and extract delta.content
System.out.println("Received stream chunk: " + data);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
baseUrl := "https://www.sagelib.com"
apiKey := "***"
url := "https://www.sagelib.com/anthropic/messages"
jsonRequestBody := `
{
"model": "claude-fable-5",
"max_tokens": 8192,
"thinking": {
"type": "enabled",
"budget_tokens": 4096
},
"messages": [
{
"role": "user",
"content": "Analyze the pros and cons comparison of Paxos vs Raft consensus algorithms"
}
]
}
`
req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonRequestBody))
if err != nil {
fmt.Println("Failed to create request:", err)
return
}
req.Header.Set("x-api-key", apiKey)
req.Header.Set("anthropic-version", "2023-06-01")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Request failed:", err)
return
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
// Pretty-print the returned JSON data
var prettyBody map[string]interface{}
if err := json.Unmarshal(body, &prettyBody); err == nil {
pretty, _ := json.MarshalIndent(prettyBody, "", " ")
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println(string(pretty))
} else {
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println(string(body))
}
}
curl -v 'https://www.sagelib.com/anthropic/messages' \
-H "x-api-key: ***" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-fable-5",
"max_tokens": 4096,
"system": "You are a distributed systems architecture expert; please answer in Chinese.",
"output_config": {
"effort": "xhigh"
},
"messages": [
{
"role": "user",
"content": "Design the architecture of a distributed cache solution"
}
]
}'
import json
import requests
# Configure base variables
base_url = "https://www.sagelib.com" # 把 base_url 换成你的网关地址 https://www.sagelib.com
api_key = "***" # Replace with your API key
url = f"https://www.sagelib.com/anthropic/messages"
headers = {
"x-api-key": api_key,
"anthropic-version": "2023-06-01",
"Content-Type": "application/json",
}
data = {
"model": "claude-fable-5",
"max_tokens": 4096,
"system": "You are a distributed systems architecture expert; please answer in Chinese.",
"output_config": {
"effort": "xhigh"
},
"messages": [
{
"role": "user",
"content": "Design the architecture of a distributed cache solution"
}
]
}
# Send the POST request
response = requests.post(url, headers=headers, json=data)
# Print the status code and the returned JSON data
print(f"Status Code: {response.status_code}")
try:
print(json.dumps(response.json(), indent=2, ensure_ascii=False))
except Exception:
print(response.text)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class LlmStreamClient {
public static void main(String[] args) {
String baseUrl = "https://www.sagelib.com";
String apiKey = "***";
String url = "https://www.sagelib.com/anthropic/messages";
String jsonRequestBody = """
{
"model": "claude-fable-5",
"max_tokens": 4096,
"system": "You are a distributed systems architecture expert; please answer in Chinese.",
"output_config": {
"effort": "xhigh"
},
"messages": [
{
"role": "user",
"content": "Design the architecture of a distributed cache solution"
}
]
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("x-api-key", apiKey).header("anthropic-version", "2023-06-01")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonRequestBody))
.build();
try {
// Use ofInputStream to handle the streaming response
HttpResponse<java.io.InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.body()))) {
String line;
while ((line = reader.readLine()) != null) {
line = line.trim();
if (line.startsWith("data:")) {
String data = line.substring(5).trim();
if ("[DONE]".equals(data)) {
break;
}
// Tip: you can bring in Gson or Jackson here to parse the JSON in data and extract delta.content
System.out.println("Received stream chunk: " + data);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
baseUrl := "https://www.sagelib.com"
apiKey := "***"
url := "https://www.sagelib.com/anthropic/messages"
jsonRequestBody := `
{
"model": "claude-fable-5",
"max_tokens": 4096,
"system": "You are a distributed systems architecture expert; please answer in Chinese.",
"output_config": {
"effort": "xhigh"
},
"messages": [
{
"role": "user",
"content": "Design the architecture of a distributed cache solution"
}
]
}
`
req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonRequestBody))
if err != nil {
fmt.Println("Failed to create request:", err)
return
}
req.Header.Set("x-api-key", apiKey)
req.Header.Set("anthropic-version", "2023-06-01")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Request failed:", err)
return
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
// Pretty-print the returned JSON data
var prettyBody map[string]interface{}
if err := json.Unmarshal(body, &prettyBody); err == nil {
pretty, _ := json.MarshalIndent(prettyBody, "", " ")
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println(string(pretty))
} else {
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println(string(body))
}
}
响应参数
Body 参数
| 参数名称 | 描述 |
|---|---|
id string |
响应唯一标识,如 msg_${message_id} |
type string |
固定为 message |
role string |
固定为 assistant |
model string |
实际使用的模型名称 |
content array |
内容块数组 |
stop_reason string |
停止原因:end_turn / max_tokens / stop_sequence / tool_use |
stop_sequence string |
匹配的停止序列(stop_reason=stop_sequence 时) |
usage object |
|
input_tokens integer |
输入 token 数 |
output_tokens integer |
输出 token 数(含推理 token) |
cache_creation_input_tokens integer |
缓存写入 token 数 |
cache_read_input_tokens integer |
缓存命中 token 数 |