Unofficial Python client for Kimi AI — no API key required, reverse-engineered
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kimi_nocost-0.1.3.tar.gz.
File metadata
- Download URL: kimi_nocost-0.1.3.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7aa2c304af8ac266e89f692d0fe8fe56f251bb6fbba93bfbc8deb109ce22166
|
|
| MD5 |
8946fd1301c51e37dc29b28f7eddf212
|
|
| BLAKE2b-256 |
ed1bc05fbbaaa0f81da37c608ccb3ff1da20343a01ea571989451e5819360417
|
Provenance
The following attestation bundles were made for kimi_nocost-0.1.3.tar.gz:
Publisher:
publish.yml on pooraddyy/kimi-nocost
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kimi_nocost-0.1.3.tar.gz -
Subject digest:
b7aa2c304af8ac266e89f692d0fe8fe56f251bb6fbba93bfbc8deb109ce22166 - Sigstore transparency entry: 1827672055
- Sigstore integration time:
-
Permalink:
pooraddyy/kimi-nocost@ede0210b861734875f79b4a8c3c439d4b576fae5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pooraddyy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ede0210b861734875f79b4a8c3c439d4b576fae5 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file kimi_nocost-0.1.3-py3-none-any.whl.
File metadata
- Download URL: kimi_nocost-0.1.3-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7e974114eef91c25a3fd017adc2076568d9fa0a11441dcf64a5b315c3503eb1
|
|
| MD5 |
830b9b065606f35d6894b8a68a276ee1
|
|
| BLAKE2b-256 |
5f711993bf715cce50657e93709c092a06964d159cccdc5c1b9805d0ea0d8338
|
Provenance
The following attestation bundles were made for kimi_nocost-0.1.3-py3-none-any.whl:
Publisher:
publish.yml on pooraddyy/kimi-nocost
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kimi_nocost-0.1.3-py3-none-any.whl -
Subject digest:
d7e974114eef91c25a3fd017adc2076568d9fa0a11441dcf64a5b315c3503eb1 - Sigstore transparency entry: 1827672140
- Sigstore integration time:
-
Permalink:
pooraddyy/kimi-nocost@ede0210b861734875f79b4a8c3c439d4b576fae5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pooraddyy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ede0210b861734875f79b4a8c3c439d4b576fae5 -
Trigger Event:
workflow_dispatch
-
Statement type: