Unofficial Python client for Kimi AI — reverse-engineered, no API key required
Project description
p2d-kimi
Unofficial Python client for Kimi AI (kimi.moonshot.cn). No API key needed — just your bearer token.
Reverse-engineered from the web interface. Works with any valid Kimi account token.
Install
pip install p2d-kimi
Quick start
from p2dkimi import KimiClient
client = KimiClient(token="your-kimi-bearer-token")
reply = client.chat("What is the capital of France?")
print(reply)
Streaming
from p2dkimi import KimiClient
client = KimiClient(token="your-token")
for chunk in client.stream("Explain quantum computing in simple terms"):
print(chunk, end="", flush=True)
Multi-turn conversation
client = KimiClient(token="your-token")
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)
With search enabled
reply = client.chat("Latest news on AI today", use_search=True)
API
KimiClient(token, model="kimi", timeout=60)
| Parameter | Description |
|---|---|
token |
Bearer JWT from kimi.moonshot.cn (see below) |
model |
Model ID: "kimi" (default), "k1", "ok-computer", etc. |
timeout |
HTTP timeout in seconds |
Each KimiClient instance automatically generates its own unique device_id and session_id using UUID4, so multiple clients can run concurrently without conflicts.
Methods
| Method | Returns | Description |
|---|---|---|
chat(message, chat_id, history, use_search) |
str |
Send a message, get full reply |
stream(message, chat_id, history, use_search) |
Generator[str] |
Send a message, yield reply chunks |
new_chat(name) |
str (chat ID) |
Create a new conversation, return its ID |
Getting your token
- Open kimi.moonshot.cn in your browser
- Open DevTools → Network → any request → copy
Authorization: Bearer <token>
Or from the iOS/Android app using a MITM proxy (e.g. mitmproxy, Charles).
The token is a JWT that lasts ~30 days.
How it works
KimiClient.chat("hello")
→ new_chat() POST /api/chat → chat_id
→ stream_completion() POST /api/chat/{id}/completion/stream → SSE chunks
→ collect chunks event=cmpl text="Hello!"
→ return full string
All sessions and device IDs are generated fresh per client instance using uuid4(), so every user gets their own isolated session without any shared state.
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 p2d_kimi-0.1.0.tar.gz.
File metadata
- Download URL: p2d_kimi-0.1.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9633330b16e5a404083cf1b3d53d8576914e146478e6322b11f78fdd7507d052
|
|
| MD5 |
50647e916a7edafffd2308867f1bcfa0
|
|
| BLAKE2b-256 |
706543360f3587d6c93ff54bf6c8a351c39addb5b9a5f76e8198a7c7adde4cb4
|
Provenance
The following attestation bundles were made for p2d_kimi-0.1.0.tar.gz:
Publisher:
publish.yml on pooraddyy/p2d-kimi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
p2d_kimi-0.1.0.tar.gz -
Subject digest:
9633330b16e5a404083cf1b3d53d8576914e146478e6322b11f78fdd7507d052 - Sigstore transparency entry: 1615600089
- Sigstore integration time:
-
Permalink:
pooraddyy/p2d-kimi@e065229fecf645de45b0c74eb3bd3150df19f1a4 -
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@e065229fecf645de45b0c74eb3bd3150df19f1a4 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file p2d_kimi-0.1.0-py3-none-any.whl.
File metadata
- Download URL: p2d_kimi-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.6 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 |
a4cb04d83071dadff631d8516add25940dc3e333f726469c47a1f1b1e89e5935
|
|
| MD5 |
6ffdef08dc3aae4241edeec6a2d3b6d6
|
|
| BLAKE2b-256 |
29a26c25964de1911c80ecc6fc3be0f22326477bbc4a0bc9d270ad36211b1001
|
Provenance
The following attestation bundles were made for p2d_kimi-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on pooraddyy/p2d-kimi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
p2d_kimi-0.1.0-py3-none-any.whl -
Subject digest:
a4cb04d83071dadff631d8516add25940dc3e333f726469c47a1f1b1e89e5935 - Sigstore transparency entry: 1615600093
- Sigstore integration time:
-
Permalink:
pooraddyy/p2d-kimi@e065229fecf645de45b0c74eb3bd3150df19f1a4 -
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@e065229fecf645de45b0c74eb3bd3150df19f1a4 -
Trigger Event:
workflow_dispatch
-
Statement type: