GLM Proxy:將 Anthropic Messages API 請求轉換為 Z.ai GLM-4.7 API 格式

GLM Proxy:將 Anthropic Messages API 請求轉換為 Z.ai GLM-4.7 API 格式

Hacker News·

GLM Proxy 是一個開源的 HTTP 代理伺服器,透過轉換 Anthropic Messages API 請求,讓與 Claude 相容的工具能夠使用 Z.ai 的 GLM-4.7 模型。

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

To see all available qualifiers, see our documentation.

GLM Proxy - LLM API proxy server

License

Uh oh!

There was an error while loading. Please reload this page.

dejay2/glmproxy

Folders and files

Latest commit

History

Repository files navigation

GLM Enhanced Proxy

HTTP proxy server that transforms Anthropic Messages API requests to Z.ai GLM-4.7 API format, enabling Claude-compatible tools and applications to use GLM models.

Why GLMProxy?

The Problem with GLM-4.7

GLM-4.7 is a powerful model, but it has limitations when used directly:

How GLMProxy Solves These

Real Benefits

Features

Quick Start

Prerequisites

Installation

Configuration

API keys are configured via a .env file in the project root. This file is automatically loaded on startup.

Create your .env file:

Required keys:

Optional keys for MCP servers:

Security best practices:

If you don't have a .env.example file, create .env manually:

Alternatively, set the environment variable directly in your shell:

Running with CLI (Recommended)

The easiest way to use the proxy:

Running Manually

The proxy will start on http://127.0.0.1:4567 by default.

Access the Dashboard

Open your browser and navigate to:

You'll see the settings dashboard where you can:

Test the connection

Configuration Options

All configuration is done via environment variables:

CLI Reference

The ccglm command provides a convenient way to use the proxy:

What ccglm does

When you run ccglm, it:

Use ccglm yolo to skip permission prompts.

Examples

Usage with AI Tools

Claude Code

The easiest way (using ccglm):

Or configure manually:

Or in the Claude Code settings, set the API base URL to http://127.0.0.1:4567.

Other AI Coding Tools

Any tool that supports the Anthropic Messages API with a custom base URL can use this proxy. Simply configure:

API Reference

POST /v1/messages

Anthropic Messages API compatible endpoint.

Request:

Response:

GET /health

Health check endpoint with status and configuration.

Response:

GET /config

Detailed configuration endpoint (for debugging).

Response:

POST /config

Update runtime configuration. Changes apply to all clients (Claude Code, Cline, dashboard, etc.).

Request:

Response:

Backend Endpoints

The proxy supports two backend paths to Z.ai with intelligent routing:

Automatic Routing (Default)

The proxy automatically selects the best endpoint based on content:

This avoids Z.ai's server_tool_use interception on the Anthropic endpoint which truncates image analysis results.

OpenAI-Compatible Path

Anthropic-Compatible Path

Toggle the Anthropic endpoint:

Features in Detail

Model Routing

The proxy automatically selects the appropriate GLM model based on the current message:

After processing an image or video, subsequent text-only messages automatically switch back to glm-4.7 for faster responses. Previous media in conversation history don't force the vision model.

Media detection scans for:

Video Analysis

GLM-4.6v supports video analysis with up to ~1 hour of video content (128K context). The proxy makes video analysis seamless:

When using Claude Code, simply mention a video file path in your message and the proxy will automatically:

Supported patterns:

Example usage in Claude Code:

In the web dashboard, you can:

Body size limit: 50MB (supports most short-to-medium videos)

For programmatic use, send videos in Anthropic-like format:

Or with base64:

Reasoning

The proxy automatically injects a reasoning prompt before the last user message to encourage step-by-step thinking. The model's reasoning output is:

Example response with reasoning:

Tool Execution

The proxy provides web search capabilities via Z.ai's MCP servers, with two internal tools:

When WEB_SEARCH_ENABLED=true (the default), the proxy automatically intercepts Claude Code's native WebSearch and WebFetch tools. This is useful because:

When Claude Code calls WebSearch or WebFetch, the proxy:

The proxy uses keyword-based triggers to inject web_search/web_reader tools only when the user explicitly requests web functionality. Trigger phrases include:

This prevents unwanted web searches on every request (e.g., during Claude Code startup).

Toggle in the dashboard settings, or via environment:

Client-defined tools are always passed through to the response for client handling.

Streaming

Both backend paths support full SSE streaming with proper Anthropic event format:

Streaming properly handles:

Error Handling

All errors are returned in Anthropic error format:

Error types:

Logging

Structured logging with configurable levels:

Log format:

Troubleshooting

"ZAI_API_KEY environment variable is required"

Set your Z.ai API key:

"GLM API error: 401 Unauthorized"

Your API key is invalid or expired. Get a new key from https://z.ai.

"GLM API error: 429 Too Many Requests"

You've hit the rate limit. Wait and retry, or upgrade your Z.ai plan.

Requests are slow

GLM-4.7 can take 10-30 seconds for complex requests. For faster responses:

Vision requests show truncated analysis

This should be fixed automatically - the proxy routes vision requests through the OpenAI endpoint which provides complete image analysis. If you still see truncated results, ensure you're using the latest version.

Model stays on glm-4.6v after image

The proxy now only checks the current message for images. After an image request, subsequent text-only messages will automatically use glm-4.7. You don't need to start a new conversation.

Debug logging

Enable debug logs to see full request/response details:

Security Considerations

GLM Proxy is designed for localhost development use only. It is not intended for production deployment or multi-user environments.

Intended Use

Security Model

This proxy operates under a localhost trust model:

What NOT to Do

Do not expose this proxy to the public internet. Specifically:

API Key Handling

The proxy handles API keys as follows:

Recommended Practices

For safe localhost development:

If You Need Production Deployment

If you must deploy this proxy in a production or shared environment, you will need to add:

We do not recommend production deployment as this is a development tool, but if you proceed, you assume full responsibility for security hardening.

Project Structure

License

MIT

About

GLM Proxy - LLM API proxy server

Resources

License

Security policy

Uh oh!

There was an error while loading. Please reload this page.

Stars

Watchers

Forks

Releases

Packages

  0

Contributors

  3

Image

Image

Image

Languages

Footer

Footer navigation

Hacker News

相關文章

  1. 展示RLM Analyzer:使用遞歸語言模型進行AI程式碼分析(MIT CSAIL研究)

    3 個月前

  2. 探索前沿人工智能的極限

    3 個月前

  3. 使用 Lynkr 在您自己的模型上運行 Cursor、Claude Code、Codex 等 AI 工具

    3 個月前

  4. Show HN:GLM-Image - 工業級AI圖像生成器

    3 個月前

  5. Show HN:一個中間人代理,用於查看你的 LLM 工具正在發送的內容

    3 個月前