Skip to main content
This guide provides a quick overview for getting started with Moonshot AI chat models. For the latest package details, examples, and source, see the langchain-moonshot repository.
Feature support varies by Moonshot model. The examples below use kimi-k2.5 for reasoning and tool calling, and moonshot-v1-32k-vision-preview for image input.

Overview

Integration details

Model features

Setup

To access Moonshot models, you’ll need a Moonshot account, an API key, and the langchain-moonshot integration package.

Credentials

Head to the Moonshot console to create an API key. Once you’ve done this, set the MOONSHOT_API_KEY environment variable.
By default, the package uses Moonshot’s international endpoint (https://api.moonshot.ai/v1). To use the China endpoint instead, set:
To enable automated tracing of your model calls, set your LangSmith API key:

Installation

The LangChain Moonshot integration lives in the langchain-moonshot package:

Instantiation

Now we can instantiate our model object and generate responses:
For kimi-k2.5, if temperature is set, it must be 1.0 when thinking=True and 0.6 when thinking=False. Omitting thinking (or setting it to None) is treated as thinking-enabled for validation purposes. To use temperature=0.6, explicitly set thinking=False.

Invocation

Reasoning output

ChatMoonshot preserves Moonshot’s reasoning_content field on both non-streaming and streaming responses.

Streaming

To recover usage metadata while streaming, set stream_usage=True:

Tool calling

Moonshot supports LangChain tool calling via bind_tools:
For kimi-k2.5 with thinking=True, tool_choice must be "auto" or "none". Forced tool choice (specifying a function name) is not supported.

Structured output

Moonshot supports structured output through LangChain’s with_structured_output(...). Moonshot does not expose a distinct json_schema steering path in this package, so method="json_schema" is intentionally downgraded to function_calling.

Multimodal input

Vision-capable Moonshot models accept OpenAI-style image_url content blocks:

Moonshot-specific notes

  • ChatMoonshot is a standalone LangChain integration package for Moonshot AI chat models built on top of langchain-openai.
  • Moonshot-specific request controls exposed by the package include thinking, prompt_cache_key, safety_identifier, and max_completion_tokens.
  • kimi-k2.5 is validated more strictly than generic OpenAI-compatible chat models.
  • For kimi-k2.5, top_p must remain 0.95, n must remain 1, and both presence_penalty and frequency_penalty must remain 0.0.
  • When thinking=True, Moonshot builtin $web_search is rejected for kimi-k2.5.

Repository

For the latest package code, README examples, release notes, and installation metadata, see: