Content
> [!IMPORTANT]
> The official version update is 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>Proxies Z.ai in an OpenAI Compatible format, supporting token-free access, intelligent processing of thought chains, image uploads (after login), and more.</p>
<p>Based on https://github.com/kbykb/OpenAI-Compatible-API-Proxy-for-Z using AI-assisted refactoring.</p>
</div>
## Features
- Supports generating a model list based on the official website /api/models and automatically selects the appropriate model name.
- (After login) Supports image uploads using the GLM image recognition series models.
- Supports intelligent recognition of thought chains, perfectly converting various formats.
## Requirements


## Environment
Configuration is done using the `.env` file.
### `BASE`
- Upstream API base domain
- Default value: `https://chat.z.ai`
### `PORT`
- Server port
- Default value: `8080`
### `MODEL`
- Alternative model to call when no model is provided
- Default value: `GLM-4.5`
### `TOKEN`
- Access token
- Can be left empty if `ANONYMOUS_MODE` is enabled
### `ANONYMOUS_MODE`
- Guest mode, when enabled, a random token will be obtained
- Default value: `true`
- File upload calls to visual models are not supported in guest mode
### `THINK_TAGS_MODE`
- Thought chain formatting mode
- Default value: `reasoning`
- Options: `reasoning`, `think`, `strip`, `details`, with effects as follows:
- "reasoning"
- reasoning_content: `Hmm, the user...`
- content: `Hello!`
- "think"
- content: `<think>\n\nHmm, the user...\n\n</think>\n\nHello!`
- "strip"
- content: `> Hmm, the user...\n\nHello!`
- "details"
- content: `<details type="reasoning" open><div>\n\nHmm, the user...\n\n</div><summary>Thought for 1 seconds</summary></details>\n\nHello!`
### `DEBUG_MODE`
- Displays debug information; when enabled, some debug information will be shown
- 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 MCP
MarkItDown-MCP is a lightweight server for converting URIs to Markdown.
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.
Fetch
Retrieve and process content from web pages by converting HTML into markdown format.