One Modelflare Smart API Key for every model available to your account — GPT, Claude, Gemini and more — in the AI SDK.
一个 Modelflare Smart API Key,在 AI SDK 里调用你账号可用的全部模型。
- Sign up / 注册: https://modelflare.dev/sign-up?utm_source=ai-sdk&utm_medium=plugin&utm_campaign=integrations
- Console → API Keys → Create Smart API Key, and pick a routing strategy (Balanced / Stability first / Low price first).
npm install @modelflare/ai-sdk-provider aiimport { generateText } from 'ai'
import { modelflare } from '@modelflare/ai-sdk-provider'
// Reads MODELFLARE_API_KEY (and optional MODELFLARE_BASE_URL) per request.
const { text } = await generateText({
model: modelflare('<model-id>'),
prompt: 'Write a haiku about routers.',
})For text generation, use IDs from GET https://modelflare.dev/v1/models?scope=authorized&kind=text&endpoint=openai. The endpoint filter matters because this provider uses the OpenAI-compatible chat protocol. New compatible models work without updating this package.
import { createModelflare } from '@modelflare/ai-sdk-provider'
const modelflare = createModelflare({
apiKey: process.env.MODELFLARE_API_KEY,
baseURL: 'china', // 'global' (default), 'china', or a custom URL
})| Option | Value |
|---|---|
apiKey |
your Smart API Key (default MODELFLARE_API_KEY) |
baseURL |
global → https://modelflare.dev/v1 (default) · china → https://origin.modelflare.dev/v1 · or a custom URL (default MODELFLARE_BASE_URL) |
headers |
extra request headers |
fetch |
custom fetch implementation |
Chat models use modelflare(id) or modelflare.chatModel(id). Image IDs should come from GET /v1/models?scope=authorized&kind=image&image_route=images; native Gemini image models use a different protocol and are not handled by imageModel. Routing across groups, fallback and the routing strategy are handled by the Smart API Key on the server.
Docs: https://docs.modelflare.dev/ · Pricing: https://modelflare.dev/pricing
MIT © Havenbyte LLC