EN ▾
Get API key

kimiapikey.comGuide

Moonshot API Base URL: Point Your Code Elsewhere

The moonshot api base url is just one string in your OpenAI-style client, and changing it is how you point the same code at a different provider. This page shows where that string lives in Python, Node, curl and common tools, and how to aim it at an alternative endpoint.

Updated

A cable being moved between two sockets on a switchboard, illustrating a changed API base URL
Isometric illustration of a code editor linked by a glowing cable to an API server

Key points

  • The base URL is a single setting; the request body stays in the OpenAI chat format.
  • Change three things when you switch: base URL, API key, model ID.
  • Our endpoint is https://api.kimiapikey.com/v1 and the model ID is uncensored.
  • It is an independent hosted model, not Moonshot's official service, so re-test your prompts.

What a base URL actually does

OpenAI-compatible clients build every request from two parts: a base URL and a path. The SDK joins them, so a call to chat.completions.create becomes a POST to <base_url>/chat/completions. Providers that follow this format, Moonshot among them, publish their own base URL in their documentation. Look it up there rather than copying it from a forum post, because it is the one value you cannot guess.

Switching providers therefore needs three edits and nothing else:

  1. The base URL, which decides where the request goes.
  2. The API key, which is issued per provider and only works on that provider's servers.
  3. The model ID, because every provider names its models differently.

Messages, roles, streaming, tools and JSON mode keep the same shape, which is why the migration is short. Anything that depends on a provider-specific feature, such as a built-in web search tool, will need separate handling.

It also helps to keep the three values together in one config block or one environment file per provider. When the base URL, key and model ID sit side by side, switching back is a one-line change, and you avoid the half-migrated state where a new key is paired with an old address.

Python: the openai package

In Python you set the base URL when you create the client. This example talks to the endpoint on this site:

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": "user", "content": "Explain a base URL in one sentence."}],
)
print(resp.choices[0].message.content)

If you would rather keep the code free of settings, use the environment instead. The SDK reads OPENAI_BASE_URL and OPENAI_API_KEY when you call OpenAI() with no arguments, so a deployment can switch providers without a code change. Be aware that this also means a leftover variable in your shell can override a value you wrote in the file.

Node and curl

The official JavaScript package uses the same option name, written in camel case:

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.kimiapikey.com/v1",
  apiKey: process.env.API_KEY,
});

const resp = await client.chat.completions.create({
  model: "uncensored",
  messages: [{ role: "user", content: "Hello" }],
  stream: false,
});
console.log(resp.choices[0].message.content);

With no SDK at all, the base URL is simply the front of the address:

curl https://api.kimiapikey.com/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"uncensored","messages":[{"role":"user","content":"Hello"}]}'

The same endpoint also accepts POST /v1/responses, and GET /v1/models lists what it serves. Authentication is a bearer token in the Authorization header in every case.

Editors and chat front ends

GUI tools expose the base URL under different labels: "API base", "Override OpenAI Base URL", "Custom endpoint" or "Provider URL". The value you paste is the same string as in the code above, ending at /v1. Do not paste the full /chat/completions address unless the tool says it wants the complete URL.

After saving, add the model ID by hand if the tool does not fetch a list. Some editors validate the key against a fixed provider and refuse custom values, in which case look for a setting that turns on the custom or OpenAI-compatible mode first. The article on using a Kimi-style API key in Cursor walks through one such tool in detail.

What changes when you swap providers

A matching format does not mean matching behavior. Before you move production traffic, check these points one by one:

  • Output style. A different model writes differently. Run your real prompts, not a toy example.
  • Context size. The endpoint here has a 100,000 token window for prompt plus completion. If your current setup sends longer prompts, trim them first.
  • Limits. A full key allows 8 concurrent requests and 300 per minute. Over either limit you get HTTP 429, with rate_limited or concurrency as the code.
  • Features. Streaming over SSE, tool calling and JSON mode are supported. Image, audio and video generation, embeddings and fine-tuning are not; this is a text-only API.
  • Naming. The service runs one open-weight model chosen to answer without content refusals for lawful adult use. It is not Moonshot's official API and not a router across vendors.

A neutral way to compare is to log the same ten prompts through both endpoints and read the answers side by side. That takes minutes and saves guesswork.

Base URL mistakes and what they look like

Most failures after a switch come from the address, not the key. Here is how each slip shows up and how to repair it.

MistakeSymptomFix
Host only, no /v1404 on every callAdd /v1 to the end
Full path pasted in404 with a doubled path in the errorCut the address back to /v1
Trailing slash plus manual path joinsDouble slash in the URLLet the SDK join the path
Old key, new URL401Use the key issued by the new provider
Old URL, new key401 from the old providerSearch the repo and the shell for the old address
http:// instead of https://Redirect or connection errorUse https everywhere

A fast way to find leftovers is to search your project and your deployment settings for the old host name. Look in .env files, CI variables, Docker compose files and any editor settings, since a single forgotten copy is enough to send some traffic to the old provider.

Streaming and tools after the switch

Set stream: true and the reply arrives as server-sent events, with token usage reported at the end. Tool calling uses the usual tools and tool_choice fields, streamed tool_calls and results sent back as messages with role: "tool". If your code already handles these for the old provider, it should keep working; confirm by running one streamed call and one tool call before you cut over fully. Remember that a streamed request holds its concurrency slot until the stream ends.

Cost check before you switch

Billing here is per token: $0.15 per 1M input tokens and $0.50 per 1M output tokens, from prepaid credit, with no subscription. Failed or refused requests are not charged, and credit does not expire. For another provider's rates, check their current pricing page, since those change.

A worked example. Suppose a request has 2,000 input tokens and 500 output tokens:

  • Input: 2,000 / 1,000,000 x $0.15 = $0.0003
  • Output: 500 / 1,000,000 x $0.50 = $0.00025
  • Total: $0.00055 per request, so 1,000 requests cost $0.55

The smallest top-up is $20, and larger ones add a bonus: +5% from $50, +10% from $100 and +15% from $200. Crypto (USDT on TRC20, USDC on Base) is accepted. Full details are on the pricing page, and the Kimi-focused breakdown is in Kimi API key pricing.

Get a key and run the first call

Sign up with Google or with email and password, then open the API key page. New users can claim $0.50 of trial credit there with one click, one per person, valid for 7 days and with no card needed. Trial keys are limited to 2 concurrent requests and 60 per minute, which is plenty for a test run.

Paste the key into the Python snippet above, run it, and confirm you get text back. The docs list every parameter, and the response headers X-Request-Id and X-Balance-USD help with debugging and balance tracking. Prompts sent to the service are not used for training.

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 to change my code when I change the base URL?

Usually only three values: base URL, API key and model ID. The message format, streaming and tool calling stay the same as long as the new provider supports them.

Should the base URL end with /v1?

Yes for this endpoint: https://api.kimiapikey.com/v1. The SDK adds /chat/completions itself, so do not include it.

Is this the official Moonshot API?

No. It is an independent hosted open-weight model behind an OpenAI-compatible API. It is not Moonshot's service and not a router across vendors.

Where do I find the model ID?

Call GET /v1/models with your key. On this endpoint the model ID is uncensored.

Your key is one form away

Create an account, copy the key, change the base URL. That is the whole setup.

Get API keyRead the docs