Moonshot AI Provider
The Moonshot AI provider offers access to powerful language models through the Moonshot API, including the Kimi series of models with reasoning capabilities.
API keys can be obtained from the Kimi API Platform.
Setup
The Moonshot AI provider is available via the @ai-sdk/moonshotai module. You can install it with:
pnpm add @ai-sdk/moonshotai
Provider Instance
You can import the default provider instance moonshotai from @ai-sdk/moonshotai:
import { moonshotai } from '@ai-sdk/moonshotai';For custom configuration, you can import createMoonshotAI and create a provider instance with your settings:
import { createMoonshotAI } from '@ai-sdk/moonshotai';
const moonshotai = createMoonshotAI({ apiKey: process.env.MOONSHOT_API_KEY ?? '',});You can use the following optional settings to customize the Moonshot AI provider instance:
-
baseURL string
Use a different URL prefix for API calls. The default prefix is
https://api.moonshot.ai/v1 -
apiKey string
API key that is being sent using the
Authorizationheader. It defaults to theMOONSHOT_API_KEYenvironment variable -
headers Record<string,string>
Custom headers to include in the requests
-
fetch (input: RequestInfo, init?: RequestInit) => Promise<Response>
Custom fetch implementation
Language Models
You can create language models using a provider instance:
import { moonshotai } from '@ai-sdk/moonshotai';import { generateText } from 'ai';
const { text } = await generateText({ model: moonshotai('kimi-k3'), prompt: 'Write a vegetarian lasagna recipe for 4 people.',});You can also use the .chatModel() or .languageModel() factory methods:
const model = moonshotai.chatModel('kimi-k3');// orconst model = moonshotai.languageModel('kimi-k3');Moonshot AI language models can be used in the streamText function
(see AI SDK Core).
Moonshot V1 models support the standard temperature, topP,
presencePenalty, and frequencyPenalty settings. Kimi models use fixed
sampling parameters; the provider omits those settings for Kimi requests and
returns an unsupported-setting warning when they are supplied.
Kimi K3 supports toolChoice: 'required'. Kimi K2.6 and the Kimi K2.7 Code
models reject that setting, so the provider omits it and returns an
unsupported-setting warning for those model IDs. Other tool choice modes are
passed through unchanged.
Log Probabilities
Moonshot V1 models can return token log probabilities through provider
options. Set logprobs to true, or set topLogprobs to automatically enable
log probabilities and request up to 20 alternatives per token:
import { moonshotai, type MoonshotAIProviderOptions } from '@ai-sdk/moonshotai';import { generateText } from 'ai';
const result = await generateText({ model: moonshotai('moonshot-v1-8k'), prompt: 'Reply with one word that means happy.', providerOptions: { moonshotai: { topLogprobs: 3, } satisfies MoonshotAIProviderOptions, },});
console.log(result.providerMetadata?.moonshotai.logprobs);The complete content logprob objects are available in Moonshot provider
metadata for both generated and streamed responses.
Structured Outputs
Native structured outputs are enabled for Kimi K models and the official Moonshot V1 text, auto, and vision models.
The provider normalizes schemas to Moonshot's supported JSON Schema subset and enables strict schema validation by default.
For unknown custom model IDs, object generation falls back to JSON mode instead of schema-constrained decoding.
For best reliability, include your schema requirements in the prompt in
addition to passing the schema to generateObject.
Message Names
Moonshot AI supports optional participant names on system, user, and assistant
messages. Set providerOptions.moonshotai.name on each message that should
include a name:
import { moonshotai, type MoonshotAIMessageProviderOptions,} from '@ai-sdk/moonshotai';import { generateText } from 'ai';
const { text } = await generateText({ model: moonshotai('kimi-k3'), messages: [ { role: 'user', content: 'Suggest a name for my neighborhood book club.', providerOptions: { moonshotai: { name: 'organizer', } satisfies MoonshotAIMessageProviderOptions, }, }, ],});The same option works with streamText. Names are omitted when unset. The
provider ignores a name on a tool message and returns a warning. Avoid including
unnecessary personal or identifying information in message names.
Partial Mode
Moonshot AI Partial Mode
continues a prefix supplied as the final assistant message. Set
providerOptions.moonshotai.partial to true on that message:
import { moonshotai, type MoonshotAIAssistantMessageProviderOptions,} from '@ai-sdk/moonshotai';import { generateText } from 'ai';
const { text } = await generateText({ model: moonshotai('kimi-k3'), messages: [ { role: 'user', content: 'Complete this sentence about the night sky.', }, { role: 'assistant', content: 'The stars above the city', providerOptions: { moonshotai: { partial: true, } satisfies MoonshotAIAssistantMessageProviderOptions, }, }, ],});The partial assistant message must be the final prompt message. Partial Mode cannot be combined with JSON object response format; JSON schema response format is supported.
Kimi K3 Dynamic Tool Loading
Kimi K3 can load complete function tool definitions at arbitrary positions in
a conversation. Add tools to the Moonshot provider options of an empty system
message. The provider sends { role: 'system', tools: [...] } without a
content field and normalizes each input schema to Moonshot Flavored JSON
Schema.
import { moonshotai, type MoonshotAISystemMessageProviderOptions,} from '@ai-sdk/moonshotai';import { generateText } from 'ai';
const result = await generateText({ model: moonshotai('kimi-k3'), allowSystemInMessages: true, messages: [ { role: 'user', content: 'Help me prepare for a trip.' }, { role: 'assistant', content: 'I can help with that.' }, { role: 'system', content: '', providerOptions: { moonshotai: { tools: [ { type: 'function', name: 'get_weather', description: 'Get the current weather for a city', inputSchema: { type: 'object', properties: { city: { type: 'string' } }, required: ['city'], additionalProperties: false, }, strict: true, }, ], } satisfies MoonshotAISystemMessageProviderOptions, }, }, { role: 'user', content: 'What is the weather in San Francisco?' }, ],});Each entry must include its complete function definition. Top-level tools and dynamically loaded tools can be used in the same request. Known unsupported official models omit the dynamic message and return a warning; custom model IDs retain it for forward compatibility.
Keep dynamic system messages in trusted server-side state. Tool names, descriptions, and schemas are sent to Moonshot and consume context. Dynamic declarations are request-local, so retain earlier declarations in later requests while those tools should remain available.
Reasoning Models
Kimi K3 always reasons and supports low, high, and max reasoning effort.
The default is max. You can configure the effort through provider options:
import { moonshotai, type MoonshotAIProviderOptions } from '@ai-sdk/moonshotai';import { generateText } from 'ai';
const { text, reasoningText } = await generateText({ model: moonshotai('kimi-k3'), providerOptions: { moonshotai: { reasoningEffort: 'high', } satisfies MoonshotAIProviderOptions, }, prompt: 'How many "r"s are in the word "strawberry"?',});
console.log(reasoningText);console.log(text);Kimi K2.5 and K2.6 can enable or disable thinking. Kimi K2.7 always has thinking and preserved reasoning enabled. Keep reasoning history in multi-turn Kimi K2.7 conversations. The reasoning output is exposed through the standard AI SDK reasoning parts.
import { moonshotai, type MoonshotAIProviderOptions } from '@ai-sdk/moonshotai';import { streamText } from 'ai';
const result = streamText({ model: moonshotai('kimi-k2.7-code'), providerOptions: { moonshotai: { thinking: { type: 'enabled' }, reasoningHistory: 'preserved', } satisfies MoonshotAIProviderOptions, }, prompt: 'How many "r"s are in the word "strawberry"?',});
for await (const part of result.fullStream) { if (part.type === 'reasoning-delta') { process.stdout.write(part.text); } else if (part.type === 'text-delta') { process.stdout.write(part.text); }}See AI SDK UI: Chatbot for more details on how to integrate reasoning into your chatbot.
Predicted Outputs
You can provide static predicted content when much of the expected response is already known. Moonshot AI can use the prediction to accelerate the response while still generating any changed content:
import { moonshotai, type MoonshotAIProviderOptions } from '@ai-sdk/moonshotai';import { streamText } from 'ai';
const source = `export function greet(name: string) { return \`Hello, \${name}!\`;}`;
const result = streamText({ model: moonshotai('kimi-k3'), messages: [ { role: 'user', content: 'Change the function to say "Welcome" instead of "Hello". Respond only with the updated code.', }, { role: 'user', content: source }, ], providerOptions: { moonshotai: { prediction: { type: 'content', content: source, }, } satisfies MoonshotAIProviderOptions, },});
for await (const textPart of result.textStream) { process.stdout.write(textPart);}The content can also be an array of text parts:
prediction: { type: 'content', content: [ { type: 'text', text: 'First known section' }, { type: 'text', text: 'Second known section' }, ],}Predicted content is sent to Moonshot AI as part of the request. Avoid including sensitive or proprietary text unless you intend to share it with the provider.
Provider Options
The following optional provider options are available for Moonshot AI language models:
-
strictJsonSchema boolean
Whether to use strict JSON schema validation for structured outputs. Defaults to
true. -
logprobs boolean
Whether to return log probabilities for generated tokens.
-
topLogprobs number
Number of most likely tokens to return at each token position, from 0 to 20. Setting this option automatically enables
logprobs. -
reasoningEffort 'low' | 'high' | 'max'
Reasoning effort for Kimi K3. Defaults to
'max'. -
prediction { type: 'content'; content: string | Array<{ type: 'text'; text: string }> }
Supplies static predicted output that can accelerate requests where most of the response is already known.
-
thinking object
Configuration for Kimi K2.5 and K2.6. Kimi K2.7 accepts only
enabledbecause its thinking cannot be disabled. Kimi K3 does not accept this field.-
type 'enabled' | 'disabled'
Whether to enable thinking mode. For Kimi K2.7 Code, only
'enabled'is accepted. -
budgetTokens number
Deprecated. Moonshot Chat Completions does not support thinking budgets. The provider omits this value and returns a warning. It remains accepted for backwards compatibility.
-
-
reasoningHistory 'disabled' | 'interleaved' | 'preserved'
Controls preserved reasoning behavior in multi-turn conversations:
'disabled'and'interleaved'are retained for compatibility. They do not change the request, so the model's server-default behavior applies.'preserved'maps tothinking.keep: 'all'for Kimi K2.6. Kimi K2.7 and K3 preserve reasoning by default.
Chat Response Metadata
Moonshot AI preserves provider-specific response fields in
providerMetadata.moonshotai for generated and streamed responses:
responseObject:chat.completionorchat.completion.chunkchoiceIndex: the selected response choice indexmessageRole: the response message role, when suppliedtoolCallTypes: the tool-call type for each returned call
These fields remain in provider metadata because they are specific to Moonshot AI's Chat Completions response rather than shared AI SDK result fields.
Model Capabilities
The Moonshot V1 series and Kimi K2.5 are unavailable to newly registered users and are scheduled for full platform sunset on August 31, 2026. They remain listed because they are still part of the Chat Completions API model surface, but new applications should use Kimi K3, Kimi K2.7 Code, or Kimi K2.6.
| Model | Image Input | Object Generation | Tool Usage | Tool Streaming |
|---|---|---|---|---|
moonshot-v1-auto | ||||
moonshot-v1-8k | ||||
moonshot-v1-32k | ||||
moonshot-v1-128k | ||||
moonshot-v1-8k-vision-preview | ||||
moonshot-v1-32k-vision-preview | ||||
moonshot-v1-128k-vision-preview | ||||
kimi-k2.5 | ||||
kimi-k2.6 | ||||
kimi-k2.7-code | ||||
kimi-k2.7-code-highspeed | ||||
kimi-k3 |
See the Kimi model list and model parameter reference for current availability and model-specific constraints. You can also pass custom or retired provider model IDs as strings when needed.