moonshotai
Package
Section titled “Package”@ai-sdk/moonshotai
Factories
Section titled “Factories”AIProviders.moonshotAI
Capabilities
Section titled “Capabilities”- Language
Structured output model support
Section titled “Structured output model support”Every Moonshot model ID, including legacy moonshot-v1-* and custom/future IDs, forwards JSON Schema structured output. Capability detection no longer depends on the kimi-k family prefix.
Generated content follows Moonshot’s order: reasoning, function tool calls, then
text; the text and toolCalls convenience fields remain available.
Kimi K3.1 context caching
Section titled “Kimi K3.1 context caching”kimi-k3.1-pro and kimi-k3.1-pro-highspeed share Kimi K3’s reasoning-history
support. Use reasoningHistory: "preserved" to send thinking.keep = "all".
let provider = try AIProviders.moonshotAI()let model = try provider.languageModel("kimi-k3.1-pro")let result = try await model.generate(LanguageModelRequest( messages: [.user("Summarize the supplied context")], providerOptions: ["moonshotai": [ "promptCacheOptions": ["ttl": "1h"], "reasoningHistory": "preserved" ]]))promptCacheOptions accepts optional mode: "implicit" and ttl: "5m" or
"1h". An empty object sends the default implicit mode; omitting the option
omits the cache object. Invalid values fail before network I/O.
usage.inputTokensCacheWrite reports cache writes, and inputTokensNoCache
excludes cache reads and writes. The msh-usage-cache-write-tokens-5m and -1h
response headers populate providerMetadata["moonshotai"]["cacheWriteTokens"]
with ttl5m and ttl1h; malformed counts are ignored. Both unary and streaming
calls retain these fields.
MFJS tool and response JSON schemas retain type: "object" at the root. A root
anyOf or oneOf containing only objects is accepted, including one-hop local
$defs and definitions references. Non-object, nullable-object and empty root
unions fail before sending. Nested unions retain the provider’s type-placement
rules.
MoonshotAI was audited against upstream 3.0.78; its implemented chat-model surface remains at 3.0.37 semantics: MOONSHOT_API_KEY, custom base URL and headers, callable provider plus languageModel/chat aliases, moonshotai.chat provider IDs, versioned user-agent suffix, stream usage by default, current model IDs such as kimi-k2.5, kimi-k2.6, and kimi-k2.7-code, providerOptions.moonshotai thinking, reasoning effort/history, prompt-cache, and safety mapping, owned image/video/text input conversion with local unsupported-media errors, MFJS tool-schema normalization, structured outputs for kimi-k* models with top-level $schema stripping, Moonshot error schema, and unsupported embedding/image families. The 3.0.43 V1/Kimi partial and predicted output, message-name, log-probability, media-reference, reasoning/sampling, structured-output, response-metadata, raw-usage, and error-code delta remains deferred to a dedicated provider pass. The 2026-10-11 pass: Common max effort maps to high through the shared chat helper. The 2026-10-18 pass: All current and future model IDs inherit structured-output support; older separately deferred V1/Kimi codec gaps remain explicit. The 2026-10-23 pass: Generated content orders reasoning, function calls, then text; the broader V1/Kimi gaps remain deferred. The 2026-10-25 pass: Kimi K3.1 aliases inherit K3 reasoning history. Cache mode/TTL, cache-write token accounting and per-TTL headers are preserved; MFJS object unions retain their required object root. Missing stream completion signals are interrupted.
Factory argument requirements are defined by the public Swift factory signatures. Use Public symbols when you need the exact initializer or factory declaration.
Return to the provider matrix.