Cencori 适配器提供了一个统一的接口来访问 14+ 个 AI 提供商(OpenAI、Anthropic、Google、xAI 等),并内置了安全性、可观察性和成本跟踪功能。
npm install @cencori/ai-sdk
import { chat } from "@tanstack/ai";
import { cencori } from "@cencori/ai-sdk/tanstack";
const adapter = cencori("gpt-4o");
for await (const chunk of chat({
adapter,
messages: [{ role: "user", content: "Hello!" }],
})) {
if (chunk.type === "content") {
console.log(chunk.delta);
}
}
import { createCencori } from "@cencori/ai-sdk/tanstack";
const cencori = createCencori({
apiKey: process.env.CENCORI_API_KEY!,
baseUrl: "https://cencori.com", // Optional
});
const adapter = cencori("gpt-4o");
import { chat } from "@tanstack/ai";
import { cencori } from "@cencori/ai-sdk/tanstack";
const adapter = cencori("claude-3-5-sonnet");
for await (const chunk of chat({
adapter,
messages: [{ role: "user", content: "Tell me a story" }],
})) {
if (chunk.type === "content") {
process.stdout.write(chunk.delta);
} else if (chunk.type === "done") {
console.log("\nDone:", chunk.finishReason);
}
}
import { chat } from "@tanstack/ai";
import { cencori } from "@cencori/ai-sdk/tanstack";
const adapter = cencori("gpt-4o");
for await (const chunk of chat({
adapter,
messages: [{ role: "user", content: "What's the weather in NYC?" }],
tools: {
getWeather: {
name: "getWeather",
description: "Get weather for a location",
inputSchema: {
type: "object",
properties: { location: { type: "string" } },
},
},
},
})) {
if (chunk.type === "tool_call") {
console.log("Tool call:", chunk.toolCall);
}
}
通过单个参数在提供商之间切换
import { cencori } from "@cencori/ai-sdk/tanstack";
// OpenAI
const openai = cencori("gpt-4o");
// Anthropic
const anthropic = cencori("claude-3-5-sonnet");
// Google
const google = cencori("gemini-2.5-flash");
// xAI
const grok = cencori("grok-3");
// DeepSeek
const deepseek = cencori("deepseek-v3.2");
所有响应都使用相同的统一格式,无论提供商如何。
| 提供者 | 模型 |
|---|---|
| OpenAI | gpt-5, gpt-4o, gpt-4o-mini, o3, o1 |
| Anthropic | claude-opus-4, claude-sonnet-4, claude-3-5-sonnet |
| gemini-3-pro, gemini-2.5-flash, gemini-2.0-flash | |
| xAI | grok-4, grok-3 |
| Mistral | mistral-large, codestral, devstral |
| DeepSeek | deepseek-v3.2, deepseek-reasoner |
| + 更多 | Groq, Cohere, Perplexity, Together, Qwen, OpenRouter |
CENCORI_API_KEY=csk_your_api_key_here
使用环境变量创建一个 Cencori 适配器。
参数
返回值: 一个 Cencori TanStack AI 适配器实例。
创建一个自定义 Cencori 适配器工厂。
参数
返回值: 一个函数,用于为特定模型创建适配器实例。