Skip to main content

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

  1. Open kimi.moonshot.cn in your browser
  2. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

p2d_kimi-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

p2d_kimi-0.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

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

Hashes for p2d_kimi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9633330b16e5a404083cf1b3d53d8576914e146478e6322b11f78fdd7507d052
MD5 50647e916a7edafffd2308867f1bcfa0
BLAKE2b-256 706543360f3587d6c93ff54bf6c8a351c39addb5b9a5f76e8198a7c7adde4cb4

See more details on using hashes here.

Provenance

The following attestation bundles were made for p2d_kimi-0.1.0.tar.gz:

Publisher: publish.yml on pooraddyy/p2d-kimi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for p2d_kimi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a4cb04d83071dadff631d8516add25940dc3e333f726469c47a1f1b1e89e5935
MD5 6ffdef08dc3aae4241edeec6a2d3b6d6
BLAKE2b-256 29a26c25964de1911c80ecc6fc3be0f22326477bbc4a0bc9d270ad36211b1001

See more details on using hashes here.

Provenance

The following attestation bundles were made for p2d_kimi-0.1.0-py3-none-any.whl:

Publisher: publish.yml on pooraddyy/p2d-kimi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page