Vercel AI SDK
在 AI SDK 中把 bInference 作为兼容 OpenAI 的模型提供方使用。
安装兼容 OpenAI 的模型提供方:
npm i ai @ai-sdk/openai-compatibleimport { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { streamText } from "ai";
const binference = createOpenAICompatible({
name: "binference",
baseURL: "https://binference.io/api/v1",
apiKey: process.env.BINF_API_KEY,
// Adds usage to streamed answers, with what each call cost.
includeUsage: true,
});
const result = streamText({
model: binference("anthropic/claude-sonnet-5.5"),
prompt: "Write a tweet about our agent's first week.",
maxOutputTokens: 512,
});
for await (const text of result.textStream) {
process.stdout.write(text);
}模型页面中的每个模型 id 都可以用于 binference("...")。工具、结构化输出和多步 Agent 的用法与任何其他模型提供方相同。