Kimi (Moonshot AI) API key setup

Published 2026-10-11 · Updated 2026-10-20

Moonshot’s Kimi keys look familiar: sk- plus a long alphanumeric body, roughly 52 characters in total. The part that confuses people isn’t the key, it’s which endpoint to point it at.

Two platforms, two base URLs

A key only works on the platform that issued it. A 401 from api.moonshot.ai on a .cn key is the classic symptom.

Setup

export MOONSHOT_API_KEY="sk-..."
curl https://api.moonshot.ai/v1/models \
  -H "Authorization: Bearer $MOONSHOT_API_KEY"
from openai import OpenAI
import os

client = OpenAI(
    api_key=os.environ["MOONSHOT_API_KEY"],
    base_url="https://api.moonshot.ai/v1",
)

resp = client.chat.completions.create(
    model="kimi-k3",
    messages=[{"role": "user", "content": "Say hello"}],
)
print(resp.choices[0].message.content)

The Kimi Code keys

Kimi’s coding subscription issues a different credential: sk-kimi-..., used against https://api.kimi.com/coding/v1. It’s a separate product from the open platform keys: same account family, different billing.

Notes

Keep MOONSHOT_API_KEY in the environment, match it to the right region, and the rest behaves like any OpenAI-compatible API.