Kimi K3.1 Pro API Setup: A Step-by-Step Guide with the OpenAI SDK



0850 840 08 23

Setting up the Kimi K3.1 Pro API takes four steps: create an API key in the Kimi API Platform console, store it in the MOONSHOT_API_KEY environment variable, install the OpenAI Python SDK with python3 -m pip install --upgrade 'openai>=1.0', and point the client's base_url at https://api.moonshot.ai/v1 with kimi-k3.1-pro as the model. Released by Moonshot AI on October 23, 2026, K3.1 Pro is an open-weight model with a 1M-token context. The most important setting after setup is reasoning_effort: it defaults to max, so every request runs at the highest thinking level.
Kimi K3.1 Pro is the first model in Moonshot AI's K3.1 series. The company's tech blog presents it as a post-trained version of Kimi K3 and its most capable 3T-class open-weight model to date. According to the model card, K3.1 Pro has 2.8 trillion total parameters, of which 104 billion are active per token, and a context window of 1,048,576 tokens. It takes text and images, and the official guide also supports video input through file uploads. A kimi-k3.1-pro-highspeed variant offers the same capabilities at 2-3 times the speed.
Kimi K3.1 Pro is pitched at coding, finance and 3D design. By Moonshot's own measurement, it scores 65.7% on Terminal-Bench 4.0, against 66.4% given for Claude Opus 5.5. In independent testing, Vals AI puts the model 9th of 34 on the Vals Index with 62.52 and lists its release date as October 23, 2026. Besides the Kimi API, the model is served by 17 providers on OpenRouter.
You need five things to use Kimi K3.1 Pro through the API:
export line below is for a macOS or Linux shell. On Windows, set the environment variable the way your own shell does it.Setting up Kimi K3.1 Pro follows Moonshot's official Python example; the code blocks below are taken unchanged from the official documentation.
Step 1 — Store the key in an environment variable. The examples read the key from MOONSHOT_API_KEY. Replace the quoted value with your own key:
export MOONSHOT_API_KEY="YOUR_KIMI_API_KEY"Step 2 — Install the OpenAI SDK. This command upgrades the SDK to version 1.0 or later:
python3 -m pip install --upgrade 'openai>=1.0'Step 3 — Point the client at the Kimi endpoint. The only Kimi-specific setting is the base_url line:
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["MOONSHOT_API_KEY"],
base_url="https://api.moonshot.ai/v1",
)Step 4 — Send the first request. Add this below the client in the same Python file and run the file with Python; the model's reply is printed in the terminal:
completion = client.chat.completions.create(
model="kimi-k3.1-pro",
messages=[{"role": "user", "content": "Introduce Kimi K3.1 Pro in one sentence."}],
)
print(completion.choices[0].message.content)Step 5 — Choose the thinking level. Thinking is always on in Kimi K3.1 Pro and cannot be turned off; the reasoning_effort field sets how much. The official example sets the highest level explicitly:
completion = client.chat.completions.create(
model="kimi-k3.1-pro",
reasoning_effort="max",
messages=[{"role": "user", "content": "Prove that the square root of 2 is irrational."}],
)
print(completion.choices[0].message.content)The field accepts low, high and max. If you leave it out, max is used. For short tasks such as answering customer questions, compare low and high on your own examples.
The quickest way to verify the Kimi K3.1 Pro setup independently of Python is the curl request from the official guide. It uses the same MOONSHOT_API_KEY variable:
curl https://api.moonshot.ai/v1/chat/completions \
--header "Authorization: Bearer $MOONSHOT_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model": "kimi-k3.1-pro",
"messages": [{"role": "user", "content": "Introduce Kimi K3.1 Pro in one sentence."}]
}'The response comes back in OpenAI format, with the text in choices[0].message.content. The Python example reads the reply from completion.choices[0].message.content as well. Kimi models do not produce the exact same answer every time, so check for a meaningful reply rather than an identical sentence. If curl works but Python does not, the problem is most likely the SDK version or the base_url line.
Most errors with Kimi K3.1 Pro come from habits formed on OpenAI models. Based on the limits in the official guide, the main cases are:
| Symptom | Cause | Fix |
|---|---|---|
| The model shows as locked in your account | No credit has been added yet | Top up at least $1 |
Your temperature or top_p setting changes nothing | These values are fixed on K3.1 Pro (temperature=1.0, top_p=0.95) | Remove them from the request and steer behavior with instructions |
| Multi-turn chat or tool calls do not give the expected result | Only content from the previous reply is sent back | Append the full assistant message, including reasoning_content and tool_calls, to messages |
| A request with an image fails | Public image URLs are not supported | Send the image as base64 or as ms://<file-id> |
| JSON output cannot be parsed | The code reads the reasoning_content field | Parse json_schema output from message.content only |
| Replies are slow and cost more than expected | The default reasoning_effort is max | Try low or high for short tasks; for speed, look at kimi-k3.1-pro-highspeed |
One more note: the guide says the official web search tool is being updated and is not recommended for production workflows in the near term. If your assistant needs current information, run the search with your own tool.
There are three ways to reach Kimi K3.1 Pro, and each has different data and license consequences. We compiled the table below from the official documentation and the license text:
| Route | Setup work | Who processes the data | License angle |
|---|---|---|---|
| Kimi API | Key, OpenAI SDK, base_url | Moonshot AI; Zero Data Retention is available | Use through Moonshot's official products is exempt |
| Third-party provider (e.g. providers on OpenRouter) | The provider's key and endpoint | The provider you choose | The exemption is written for certified inference partners only; ask the provider |
| Your own servers | Multi-GPU server with vLLM, SGLang or TokenSpeed | Your infrastructure | Internal use is exempt; if you offer the model to others as a service, check the revenue threshold |
In the example below, an AI assistant handling 10,000 customer conversations a month costs $230 in Kimi K3.1 Pro model usage. For pricing, we used the figures Vals AI lists: $2 per million input tokens and $10 per million output tokens. We could not access the table on Kimi's pricing page, so check the current price in the console before you budget. We assume 4,000 input tokens and 1,500 output tokens including thinking per conversation; these are our example figures, not numbers published by Moonshot.
We kept the output share high because thinking at the default max level can run long. Repeated system prompts are cached automatically and cached input is billed at a lower rate, so your real bill may differ. The math covers model usage only; WhatsApp or phone channel fees, integration and maintenance are not included.
Before taking Kimi K3.1 Pro live, settle four points:
The steps in this guide are written for the model ID kimi-k3.1-pro and the https://api.moonshot.ai/v1 endpoint. According to the official guide, max_completion_tokens defaults to 131072 and can be raised to 1048576. Because the SDK is installed with the openai>=1.0 condition, you get the current OpenAI release on that day; pin the version you use in production in your own dependency file. For the faster model, changing the model ID to kimi-k3.1-pro-highspeed is enough.
For businesses that work with long documents and want to test another model with only small changes to existing OpenAI code, setting up Kimi K3.1 Pro is a low-cost way to experiment. Take a mid-sized engineering firm that reads long tender specifications before every bid. With a 1M-token context, it can pass an entire specification to the model in one request and ask compliance questions. If its code already uses the OpenAI SDK, switching means changing the key, the base_url and the model line. The real work is measuring answer quality in each language you serve and settling the data processing terms with your provider.
Who it suits, and who it does not:
max level. Businesses that cannot send customer data to an outside provider and have no multi-GPU servers should also look elsewhere.Three steps you can take this week:
low and max; record accuracy and response time.If you need a cheaper classification layer, see our Claude Haiku 5.5 API setup guide; to add an assistant to your website, see our AI assistant installation guide. For multi-step flows that read a long document and then open a CRM record or draft a quote, see our AI agent service; to receive customer messages on WhatsApp, our WhatsApp automation service. You can try ready-made scenarios on our demos page.
Last checked: November 8, 2026.
To adapt Kimi K3.1 Pro or another model to your own workflow, visit our AI assistant service page, request a short discovery call through our contact form, or call +90 850 840 08 23 and talk live with Azra, our voice assistant.
Yes. The model unlocks once your account has a top-up of at least $1. Vals AI lists token pricing at $2 per million input tokens and $10 per million output tokens; check the current price in the console. Requests processed in bulk through the Batch API are billed at 60% of the standard price.
Moonshot's model card does not list supported languages, and the official example describes the model as especially good in Chinese and English. Test answer quality in each language you serve with real customer questions before going live, and state the response language explicitly in the system prompt.
The weights are on Hugging Face, and the model card gives the vllm serve "moonshotai/Kimi-K3.1-Pro" command for vLLM. With 2.8 trillion total parameters, though, the model needs a multi-GPU server. Internal use is free under the license; if you plan to offer the model to others as a service, check the license's revenue threshold.
Yes. The Kimi API follows the OpenAI format, so changing the key, the base_url and the model ID is enough. In addition, remove the fixed parameters (temperature, top_p) from requests and send the assistant message back with its reasoning_content in multi-turn conversations.