kimi-nocost
Unofficial Python client for Kimi AI (kimi.moonshot.cn). No API key needed — just your bearer token.
Features
- No API key required — uses your browser session token
- Persistent sessions — messages stay in the same conversation automatically
- Streaming support — yield reply chunks in real time
- Web search — toggle Kimi's built-in search on any message
- Multi-turn conversations — full context preserved across calls
- Image upload — send up to 20 images at once
- File upload — send documents, PDFs, code files (max 100 MB each, 1,000 files, 10 GB total)
- Built-in Models — switch models easily with
Models.K2D6,Models.K2D6_AGENT, etc. - Lightweight — only depends on
requests
Install
pip install kimi-nocost
Quick Start
from kimi_nocost import KimiClient
client = KimiClient(token="your-kimi-bearer-token", model="kimi")
reply = client.chat("What is the capital of France?")
print(reply)
modelis required. Pass it as a plain string —"kimi","k1","k2d6", etc. Omitting it raises aTypeError.
Models
Use the built-in Models class to switch between Kimi models:
from kimi_nocost import KimiClient, Models
client = KimiClient(token="your-token", model=Models.KIMI)
reply = client.chat("Explain transformers")
print(reply)
client.model = Models.K2D6
reply = client.chat("Solve this step by step: 2x + 5 = 13")
print(reply)
| Constant | Model ID | Description |
|---|---|---|
Models.KIMI |
kimi |
Default model |
Models.K1 |
k1 |
K1 model |
Models.K2D6 |
k2d6 |
K2.6 Instant — fast responses |
Models.K2D6_AGENT |
k2d6-agent |
K2.6 Agent — research, slides, docs |
Multi-Turn Conversation
client = KimiClient(token="your-token", model="kimi")
reply1 = client.chat("My name is Alex.")
reply2 = client.chat("What is my name?")
print(reply2)
Streaming
from kimi_nocost import KimiClient
client = KimiClient(token="your-token", model="kimi")
for chunk in client.stream("Explain quantum computing in simple terms"):
print(chunk, end="", flush=True)
With Web Search
reply = client.chat("Latest news on AI today", use_search=True)
Image Upload
Send up to 20 images in a single call:
from kimi_nocost import KimiClient
client = KimiClient(token="your-token", model="kimi")
file_ids = client.upload_images([
"photo1.jpg",
"photo2.png",
(open("screenshot.png", "rb"), "screenshot.png"),
])
reply = client.chat("Describe these images", refs=file_ids)
print(reply)
File Upload
Send documents, PDFs, or code files (max 100 MB each, 1,000 files per session, 10 GB total):
file_id = client.upload_file("report.pdf")
reply = client.chat("Summarize this document", refs=[file_id])
print(reply)
You can also pass raw bytes with a filename:
import io
content = b"def hello(): print('world')"
file_id = client.upload_file(io.BytesIO(content), "hello.py")
reply = client.chat("What does this code do?", refs=[file_id])
print(reply)
Starting a New Chat
client.new_chat(name="fresh-start")
reply = client.chat("Let's start over.")
Manual Chat ID
chat_id = client.new_chat(name="my-session")
reply1 = client.chat("My name is Alex.", chat_id=chat_id)
reply2 = client.chat("What is my name?", chat_id=chat_id)
print(reply2)
API Reference
KimiClient(token, model, timeout=60)
| Parameter | Type | Description |
|---|---|---|
token |
str |
Bearer JWT from kimi.moonshot.cn |
model |
str |
Model ID — use Models.* constants |
timeout |
int |
HTTP timeout in seconds |
Methods
| Method | Returns | Description |
|---|---|---|
chat(message, chat_id, history, use_search, refs) |
str |
Send a message, get full reply |
stream(message, chat_id, history, use_search, refs) |
Generator[str] |
Send a message, yield reply chunks |
new_chat(name) |
str |
Create a new conversation and set it as active |
upload_file(file, filename) |
str |
Upload a file, returns file ID |
upload_images(files) |
List[str] |
Upload up to 20 images, returns list of file IDs |
upload_single(file, filename) |
str |
Upload a single file or image, returns file ID |
Attributes
| Attribute | Type | Description |
|---|---|---|
model |
str |
Current model — change anytime |
chat_id |
str |
Active conversation ID |
file_count |
int |
Number of files uploaded this session |
total_size |
int |
Total bytes uploaded this session |
REST API Server
The included Flask server exposes HTTP endpoints:
| Endpoint | Method | Description |
|---|---|---|
POST /chat/new |
POST | Create a new session → returns chat_id |
POST /chat |
POST | Send a message → returns reply + chat_id |
POST /chat/stream |
POST | Stream a reply as plain text |
POST /upload/images |
POST | Upload up to 20 images → returns file_ids |
POST /upload/file |
POST | Upload a single file → returns file_id |
GET /health |
GET | Health check |
Pass your token via Authorization: Bearer <token> header.
Chat with files:
{
"message": "Summarize this",
"file_ids": ["id1", "id2"],
"model": "k2d6-agent"
}
Upload images (multipart, field name images):
curl -H "Authorization: Bearer <token>" \
-F "images=@photo1.jpg" \
-F "images=@photo2.png" \
http://localhost:8080/upload/images
Upload file (multipart, field name file):
curl -H "Authorization: Bearer <token>" \
-F "file=@report.pdf" \
http://localhost:8080/upload/file
Getting Your Token
- Open kimi.moonshot.cn in your browser
- Open DevTools → Network → any request
- Copy the value of
Authorization: Bearer <token>
Or from iOS/Android using a MITM proxy (e.g. mitmproxy, Charles).
The token is a JWT that lasts ~30 days.
Demo
See DEMO.md for a full working Telegram bot with image & file upload support.
Community
Join for Python tutorials, projects, and updates → t.me/pythontodayz
License
MIT — made by addy
Release files for kimi-nocost 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| kimi_nocost-0.1.3.tar.gz | 7.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| kimi_nocost-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.3 kB
Release files / kimi_nocost-0.1.3.tar.gz
| Download URL | kimi_nocost-0.1.3.tar.gz |
|---|---|
| Size | 7.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b7aa2c304af8ac266e89f692d0fe8fe56f251bb6fbba93bfbc8deb109ce22166
|
|
BLAKE2b-256 checksum How to use checksums |
ed1bc05fbbaaa0f81da37c608ccb3ff1da20343a01ea571989451e5819360417
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 15, 2026.
Transparency logRelease files / kimi_nocost-0.1.3-py3-none-any.whl
| Download URL | kimi_nocost-0.1.3-py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d7e974114eef91c25a3fd017adc2076568d9fa0a11441dcf64a5b315c3503eb1
|
|
BLAKE2b-256 checksum How to use checksums |
5f711993bf715cce50657e93709c092a06964d159cccdc5c1b9805d0ea0d8338
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 15, 2026.
Transparency log