A reverse-engineered Python client for Kimi AI (Moonshot) that bypasses the web interface and provides direct API access with advanced features like deep thinking and web search capabilities.
- Direct API Access: Bypass the web interface and communicate directly with Kimi's backend
- Authentication Management: Automated login with session persistence and token management
- Interactive Chat Mode: Real-time conversation with streaming responses
- Single Prompt Mode: Execute one-off queries from command line
- Session Persistence: Maintain conversation context across multiple interactions
- Rich Console Output: Beautiful terminal interface with colored status messages
- Headless Browser Automation: Seamless credential extraction without GUI interference
- Clone or navigate to the kimi directory:
cd kimi-reverse-api- Install dependencies:
pip install -r requirements.txt- Set up your credentials:
- Edit
data/.envwith your Google credentials (Kimi uses Google OAuth):
- Edit
KIMI_EMAIL=your_email@gmail.com
KIMI_PASSWORD=your_passwordStart an interactive chat session:
python main.pyAvailable commands during chat:
/exit,/quit,/q- Exit the program
Execute a single query and exit:
python main.py "What is the capital of France?"kimi/
├── data/ # Data storage directory
│ ├── .env # Environment variables (credentials)
│ ├── auth_token.txt # Stored authentication token
│ ├── kimi_cookies.json # Browser cookies
│ └── last_login.txt # Last login timestamp
├── src/ # Source code
│ ├── __init__.py
│ ├── auth.py # Authentication and credential extraction
│ ├── client.py # Main Kimi API client
│ ├── config.py # Configuration management
│ └── display.py # Terminal UI and formatting
├── main.py # Entry point
├── requirements.txt # Python dependencies
└── README.md # This file
- Checks for existing valid session
- If expired, launches headless browser
- Automatically fills Google OAuth login
- Extracts cookies and auth token
- Stores credentials for future use
- Sessions expire after 1 hour
- Automatic re-authentication when needed
- Conversation context maintained within sessions
- Graceful handling of network interruptions
- Python 3.8+
- Or manually put cookie in the kimi_cookies.json and auth_token.txt also change last_login.txt to current time i will change it later.
- Valid Google account (for Kimi login)
- Chrome/Chromium browser (for authentication)
- Internet connection
rich- Terminal formatting and colorsnodriver- Headless browser automationpython-dotenv- Environment variable managementhttpx- HTTP client for API calls
Login Failed
- Verify Google credentials in
data/.env - Check internet connection
- Ensure Google account can access Kimi
Session Expired
- Delete
data/last_login.txtto force re-authentication - Check if Kimi changed their login process
Browser Issues
- Install/update Chrome or Chromium
- Check if browser automation is blocked by antivirus
- Credentials are stored locally in plain text
- Use environment variables for production deployments
- This tool is for educational and research purposes
- Respect Kimi's terms of service
This project is for educational and research purposes. Please respect Kimi's terms of service and use responsibly.
This is a reverse-engineered client and is not officially supported by Kimi/Moonshot. Use at your own risk. The authors are not responsible for any issues that may arise from using this software.