Content
[!IMPORTANT]
Official version updates are slightly delayed. If you need to use it urgently, it is recommended to [switch to the Canary branch](https://github.com/hmjz100/Z.ai2api/tree/canary).
<div align=center>
<img width="100" src="https://wsrv.nl/?url=https%3a%2f%2fz-cdn.chatglm.cn%2fz-ai%2fstatic%2flogo.svg&w=300&output=webp" />
<h1>Z.ai2api</h1>
<p>Proxy Z.ai as OpenAI Compatible format, supporting token-free, intelligent processing of chain-of-thought, image uploading (after login) and other functions</p>
<p>Based on https://github.com/kbykb/OpenAI-Compatible-API-Proxy-for-Z, refactored with AI assistance</p>
</div>
## Features
- Supports generating a model list based on the official website's /api/models and automatically selecting appropriate model names.
- (After login) Supports uploading images and using the GLM image recognition series models.
- Supports intelligent identification of chain-of-thought, perfectly converting various formats.
## Requirements


## Environment
Use the `.env` file for configuration.
### `BASE`
- Upstream API base domain
- Default value: `https://chat.z.ai`
### `PORT`
- Service port
- Default value: `8080`
### `MODEL`
- Alternative model, called when no model is passed in
- Default value: `GLM-4.5`
### `TOKEN`
- Access token
- Can be left blank if `ANONYMOUS_MODE` is enabled
### `ANONYMOUS_MODE`
- Guest mode, a random token will be obtained after enabling
- Default value: `true`
- Uploading files to call visual models is not supported in guest mode
### `THINK_TAGS_MODE`
- Chain-of-thought formatting mode
- Default value: `reasoning`
- Optional `reasoning` `think` `strip` `details`, effects are as follows
- "reasoning"
- reasoning_content: `Um, the user...`
- content: `Hello!`
- "think"
- content: `<think>\n\nUm, the user...\n\n</think>\n\nHello!`
- "strip"
- content: `> Um, the user...\n\nHello!`
- "details"
- content: `<details type="reasoning" open><div>\n\nUm, the user...\n\n</div><summary>Thought for 1 seconds</summary></details>\n\nHello!`
### `DEBUG_MODE`
- Display debug information, some debug information will be displayed after enabling
- Default value: `false`
## Usage
```
git clone https://github.com/hmjz100/Z.ai2api.git
cd Z.ai2api
pip install -r requirements.txt
python app.py
```
Connection Info
You Might Also Like
markitdown
MarkItDown-MCP is a lightweight server for converting URIs to Markdown.
servers
Model Context Protocol Servers
Time
A Model Context Protocol server for time and timezone conversions.
Filesystem
Node.js MCP Server for filesystem operations with dynamic access control.
Sequential Thinking
A structured MCP server for dynamic problem-solving and reflective thinking.
git
A Model Context Protocol server for Git automation and interaction.