kimiapikey.comGuide
Kimi API Key Integration with OpenAI SDKs and LangChain
Integrating this API into an app means changing two values in code you probably already have: the base URL and the key. This guide shows the change for the OpenAI SDKs, LangChain and LiteLLM, then covers retries and limits for production use.
Updated

Key points
- Every client needs the same three values: base URL https://api.kimiapikey.com/v1, your key and the model
uncensored. - Store them in environment variables so you can swap providers without editing code.
- Handle 429 responses separately: rate_limited, concurrency and a temporary overload with Retry-After: 5.
- A full key allows 8 concurrent requests and 300 per minute; a trial key allows 2 and 60.
What actually changes in your code
A kimi api key integration sounds like a project, but for this endpoint it is a configuration change. The service implements the OpenAI chat completions format, so any client library that lets you set a base URL and a key will work. There is no custom SDK to install and no new request shape to learn.
| Setting | Value |
|---|---|
| Base URL | https://api.kimiapikey.com/v1 |
| API key | The key from your dashboard, sent as Authorization: Bearer |
| Model | uncensored |
| Endpoints | POST /v1/chat/completions, GET /v1/models |
Two points save time. First, this is a text model behind one endpoint: no embeddings route, no image generation, no audio. If your app calls those, keep another provider for them and route only chat here. Second, this is not the official API of Kimi or any other vendor; it is an independent provider running one open-weight model, so model names from other platforms will not resolve. The Kimi API key explainer covers that difference at more length.
Get your key on the API key page. New accounts can claim $0.50 of trial credit there, which is plenty for everything below.
Configuration and moving an existing app over
The official OpenAI Python and Node libraries read OPENAI_API_KEY and OPENAI_BASE_URL from the environment when you do not pass them explicitly. That makes the lowest-effort integration a shell change:
export OPENAI_BASE_URL="https://api.kimiapikey.com/v1"
export OPENAI_API_KEY="YOUR_KEY"
Existing code that builds a bare OpenAI() client now talks to this endpoint. You still change the model argument to uncensored. Put the model name into a variable too, for example LLM_MODEL, so a test environment and a production environment can differ without a code edit.
The habit is worth the minute it takes. When the base URL, key and model live in config, trying another OpenAI-compatible provider is a deployment change, and rolling back is the same change in reverse.
Most teams do not start from a blank file. They have an app that already calls an OpenAI-style API, and they want it to call this one. The migration is mostly a search for three strings.
- Find where the client is built and change the base URL.
- Find every
model=argument and replace the old name withuncensored. - Search for features your code uses that this API does not provide, such as embeddings, image generation or audio. Those calls must stay with another provider or be removed.
Then compare behaviour, not only syntax. A different model has a different voice, different default length and different habits with formatting. Run your existing test prompts, read the answers side by side and adjust the system prompt where the tone has drifted. Prompt text that worked around another model's quirks sometimes does nothing here, and sometimes makes things worse, so remove old workarounds one by one and watch what changes.
Check the parameters you pass, too. Temperature, top_p, stop, seed and the penalties are passed through, so they behave as you expect. Fields that belong to other vendors, or to features this API lacks, will not do anything useful. Keep the request body small and standard. The body limit is 8 MB, which only matters if you embed large documents directly.
Python: sync, streaming and async
The explicit form, which does not depend on environment variables:
from openai import OpenAI
client = OpenAI(
base_url="https://api.kimiapikey.com/v1",
api_key="YOUR_KEY",
)
resp = client.chat.completions.create(
model="uncensored",
messages=[
{"role": "system", "content": "You answer in plain English."},
{"role": "user", "content": "Explain idempotency in two sentences."},
],
temperature=0.7,
)
print(resp.choices[0].message.content)
print(resp.usage.prompt_tokens, resp.usage.completion_tokens)
For streaming, set stream=True and read the chunks as they arrive. The stream is delivered over server-sent events, and usage is reported at the end.
stream = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Write a limerick about retries."}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
For a service that handles many users, use the async client and cap your own parallelism so you never exceed the key's concurrency limit. A semaphore is the simplest way:
import asyncio
from openai import AsyncOpenAI
client = AsyncOpenAI(
base_url="https://api.kimiapikey.com/v1",
api_key="YOUR_KEY",
)
gate = asyncio.Semaphore(8)
async def ask(prompt: str) -> str:
async with gate:
r = await client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": prompt}],
)
return r.choices[0].message.content
async def main():
prompts = [f"Give one fact about the number {n}." for n in range(20)]
answers = await asyncio.gather(*(ask(p) for p in prompts))
print(len(answers), "answers")
asyncio.run(main())
Set the semaphore to 2 while you are on the trial key, and 8 on a funded key.
Node and TypeScript
The Node library takes the same two options under slightly different names:
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.kimiapikey.com/v1",
apiKey: process.env.API_KEY,
});
const completion = await client.chat.completions.create({
model: "uncensored",
messages: [{ role: "user", content: "Name three HTTP status codes." }],
});
console.log(completion.choices[0].message.content);
Streaming with the same client uses stream: true and an async iterator over the result. If you use a front-end framework that wraps the OpenAI library, such as a chat UI toolkit, look for its base URL option and set it the same way. Keep the key on the server. A key placed in browser code can be copied by anyone who opens the developer tools, and the credit behind it is real money.
LangChain and LiteLLM
Frameworks that wrap the OpenAI client usually expose the same two parameters. In LangChain for Python, the OpenAI chat model class accepts them directly:
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="uncensored",
base_url="https://api.kimiapikey.com/v1",
api_key="YOUR_KEY",
temperature=0.5,
)
reply = llm.invoke("Summarize what a message queue does in one sentence.")
print(reply.content)
From there, chains, prompt templates and output parsers work as they do with any chat model. If you bind tools, the API supports tool calling with tools and tool_choice, and tool results come back to the model as role: "tool" messages, which is what the framework produces.
LiteLLM is useful when you want one calling convention across several providers. Prefix the model with openai/ and pass the base URL as api_base:
import litellm
resp = litellm.completion(
model="openai/uncensored",
api_base="https://api.kimiapikey.com/v1",
api_key="YOUR_KEY",
messages=[{"role": "user", "content": "Say hello in French."}],
)
print(resp.choices[0].message.content)
For structured data, pass response_format={"type": "json_object"} and say in the prompt that you want JSON. Always parse the result defensively, because JSON mode asks for valid JSON but your schema is still only a request in the prompt.
Limits, retries and error handling
A funded key allows 8 concurrent requests and 300 requests per minute. A trial key allows 2 and 60. The body can be up to 8 MB, and the window is 100,000 tokens for prompt and completion together. When you exceed a limit, the API answers with HTTP 429 and one of these:
rate_limited: too many requests per minute. Back off for several seconds.concurrency: too many requests running at once. Wait for one to finish. A streamed request holds its slot until the stream ends, so a slow consumer counts against you.- A 429 with
Retry-After: 5: temporary overload. Wait five seconds and try again.
A small retry wrapper that honours the header handles all three:
import time
from openai import OpenAI, RateLimitError
client = OpenAI(base_url="https://api.kimiapikey.com/v1", api_key="YOUR_KEY", max_retries=0)
def chat(messages, tries=4):
for attempt in range(tries):
try:
return client.chat.completions.create(model="uncensored", messages=messages)
except RateLimitError as e:
wait = int(e.response.headers.get("retry-after", 2 ** attempt))
time.sleep(wait)
raise RuntimeError("still rate limited after retries")
Failed or refused requests are not charged, so retrying carries no billing penalty. Log the X-Request-Id response header with every call; it is the quickest way to point to one request if something looks wrong. X-Balance-USD tells you how much credit remains, which you can feed to an alert. The documentation lists all response headers.
Tool calling through a framework
Agent frameworks depend on tool calling, so it is worth a short test before you build on it. This API accepts tools and tool_choice, returns tool_calls when the model wants a function run, and expects the result as a role: "tool" message that references the call ID. Streaming works with tools, with the call arriving in fragments that the SDK assembles for you.
A good first test is a one-tool agent with a function whose result you can check by eye, such as a calculator or a lookup in a small dictionary. Run it ten times. If the model picks the tool and fills its arguments correctly each time, you can add a second tool. If it sometimes answers from memory instead of calling the function, make the tool description more specific, or set tool_choice to force the call for that step. Models differ in how reliably they drive long chains of calls, so keep chains short and add a step limit to any loop so a confused run cannot spin forever and spend credit.
A short pre-launch checklist
- Run one request through curl or the SDK and confirm the usage block is present.
- Test streaming with the client that will be used in production, including what happens when the user closes the page mid-stream.
- Cap your own concurrency below the key's limit.
- Set
max_tokenswhere short answers are expected, and trim chat history before it grows past what you want to pay for. - Keep the key in server-side config and rotate it if it appears in a log.
- Check cost on real traffic. At $0.15 per 1M input and $0.50 per 1M output, a request with 3,000 tokens in and 700 out costs $0.0008, so 10,000 of them cost about $8. Details are on the pricing page.
Prompts sent to the API are not used for training. The one content rule that never changes is the hard limit on sexual content involving minors; the model is otherwise tuned to answer without refusals for lawful adult use, so apps that serve the public should still add their own moderation and age checks where the law or your users expect them.
More guides
- Use a Kimi-Style API Key in Cursor: Setup Guide
- Kimi API Key Pricing: What This Alternative Costs
- Kimi API Key: How It Works and What the Alternatives Are
Frequently Asked Questions
Is the model the same as Moonshot's official Kimi?
No, we host an open-weight model that is tuned to be uncensored. It is not GPT, Claude, Gemini, Grok, DeepSeek, or any other vendor's model. It is a distinct model run on our own servers.
Do you train on my data?
No. Your prompts and completions are not used for training. We value privacy and transparency, so your data remains yours.
What are the rate limits?
You are limited to 300 requests per minute per key. The maximum request body size is 8 MB. These limits are designed to ensure stable performance for all users.
What is the content policy?
The model is uncensored regarding adult, controversial, and creative topics. However, we do block sexual content involving minors. This is a hard limit that always applies, regardless of your subscription level.
Questions and answers
Do I need a special SDK?
No. The standard OpenAI libraries for Python and Node work after you set the base URL to https://api.kimiapikey.com/v1 and use your key. LangChain and LiteLLM work the same way.
Which model name should my code use?
Use uncensored. It is the only model ID the API serves, and GET /v1/models lists it.
How do I avoid 429 errors?
Limit your own parallel requests to 8 on a funded key or 2 on a trial key, and retry after the Retry-After delay when the API asks for it.
Does it support tool calling and JSON mode?
Yes. Use tools and tool_choice for function calls, and response_format with type json_object for JSON output. Streaming also works.
Can I use embeddings or image generation through the same key?
No. The API is text chat only, with no embeddings, image, audio or video endpoints.
Your key is one form away
Create an account, copy the key, change the base URL. That is the whole setup.