✅ FULLY IMPLEMENTED - Complete OpenAI AND Anthropic Claude API support with dual endpoints!
🎓 For personal, non-commercial or educational use only. Please use responsibly! 🌈
Hey there! 👋 Welcome to ZtoApi - your ultimate dual-API proxy that brings Z.ai's amazing GLM models to life through BOTH OpenAI AND Anthropic Claude compatible interfaces! ✨ Built with Deno's awesome native HTTP API, it supports streaming/non-streaming responses for both APIs, plus comes with a real-time monitoring dashboard! 😍
Use your existing OpenAI OR Claude clients without any changes! 🚀
- 🔄 OpenAI API fully compatible — use your existing OpenAI clients seamlessly! 🎯
- 🎭 Anthropic Claude API fully compatible — use Claude Desktop, cline, cursor, and any Claude tools! 🤖
- 🛠️ Native tool calling support — AI can execute server-side functions! 🔧
- Built-in tools:
get_current_time,fetch_url,hash_string,calculate_expression - Multiple formats: JSON, XML, and simple function call syntax detection
- Streaming & non-streaming: Full support for both response modes
- Easy extensibility: Add custom tools via simple registry system
- Security-first: Whitelist-based registry with input validation
- Full OpenAI compatibility: Standard
toolsandtool_choiceparameters
- Built-in tools:
- 🌊 SSE streaming support for both APIs - real-time token delivery! ✨
- 🧠 Advanced thinking content processing with 5 amazing modes
- 📊 Built-in web Dashboard with live request stats for both APIs! 🎨
- 🔐 API key authentication with optional anonymous token fallback 🛡️
- ⚙️ Configurable via environment variables - make it yours! 🎛️
- 🚀 Deployable on Deno Deploy or self-hosted - your choice! 🏠
See Models for a complete list of supported models and their capabilities.
GET /v1/models # List available models
POST /v1/chat/completions # Chat completions (streaming & non-streaming)
# Supports tool calling with `tools` parameter
GET /anthropic/v1/models # List available Claude models
POST /anthropic/v1/messages # Messages (streaming & non-streaming)
POST /anthropic/v1/messages/count_tokens # Count tokens in messages
GET / # Welcome page & overview
GET /dashboard # Real-time API monitoring dashboard
GET /docs # API documentation
Base paths:
- OpenAI: http://localhost:9090/v1 🌐
- Claude: http://localhost:9090/anthropic/v1 🎭
- Get a Z.ai API Token: Visit https://chat.z.ai and get your token
- Set Environment Variables: Configure
ZAI_TOKENand other settings - Run Locally:
deno run --allow-net --allow-env --allow-read main.ts
For detailed setup instructions, see Getting Started.
Include tools in your API requests and let the AI use them automatically:
curl -X POST http://localhost:9090/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_ZAI_TOKEN" \
-d '{
"model": "GLM-4.5",
"messages": [{"role": "user", "content": "What time is it?"}],
"tools": [
{
"type": "function",
"function": {
"name": "get_current_time",
"description": "Get current UTC time"
}
}
],
"tool_choice": "auto"
}'Available built-in tools:
get_current_time- Returns current UTC timefetch_url- Fetches content from URLs (text/JSON)hash_string- Calculates SHA256/SHA1 hashescalculate_expression- Safely evaluates math expressions
See Native Tool Calling for complete documentation.
For comprehensive information, see our detailed documentation:
- 🚀 Getting Started - Setup and first steps
- 🚀 Deployment - Cloud and local deployment
- 🔌 API Reference - Complete API documentation
- 🤖 Models - Model capabilities and mappings
- ✨ Features - Advanced features and configuration
- 💻 Examples - Usage examples with multiple languages
- 🔧 Troubleshooting - Common issues and solutions
- 🔬 Advanced - Technical implementation details
- 🛠️ Native Tool Calling - Tool calling system guide
ZtoApi now features a modular architecture for better maintainability:
src/
├── config/ # Configuration & constants
├── services/ # Business logic (token pool, signatures, image processing)
├── types/ # TypeScript type definitions
└── utils/ # Utility functions (logging, stats, helpers)
For developers:
- 📖 Migration Guide - Guide to the new modular structure
- 📋 Cleanup Summary - Detailed refactoring report
- 🤖 AGENTS.md - Development guide for AI agents
Want to help make ZtoApi even better? We'd love your help! 💪
Development Workflow:
deno task dev # Run with watch mode
deno task test # Run tests
deno task lint # Lint code
deno task fmt # Format code
deno task check # Type check- Open issues and pull requests on the project repository 🎉
- Follow the Migration Guide for code structure
- All PRs automatically run CI checks (lint, format, type check, tests)
This project is released under the MIT License. See LICENSE for details. 📄
Hope you enjoy using ZtoApi as much as we enjoyed building it! If you have any questions or feedback, don't hesitate to reach out! 🤗✨
Happy coding! (´。• ᵕ •。`) 💖
Special thanks to the amazing open-source community! This project was inspired by and includes code adapted from:
- claude-proxy by simpx - Claude API proxy implementation patterns and Anthropic API structure. Their excellent work provided the foundation for our Claude API compatibility layer! 🎭✨
🚀 MASSIVE THANKS TO THE HEROES WHO SAVED THIS PROJECT:
- 🏆 @sarices (ZhengWeiDong) - THE ABSOLUTE LEGEND 🔥🔥🔥
- 🎯 SINGLE-HANDEDLY FIXED Z.ai upstream authentication - WITHOUT HIM THIS PROJECT WOULD BE BROKEN!
- ⚡ IMPLEMENTED Base64 encoding signature algorithm - Critical fix that restored ALL API functionality
- 🛠️ RESOLVED the dreaded "502 Bad Gateway" errors - Both OpenAI AND Anthropic endpoints now work flawlessly
- 💡 PR: feat(api): update signature algorithm to align with upstream
- 🎖️ IMPACT: This genius-level contribution literally SAVED the entire project! 🙌✨
- 🏅 HERO STATUS: ZhengWeiDong (Z.ai upstream fixing) - WE OWE YOU EVERYTHING! 🎉
This man deserves a medal! Without @sarices, none of this would work! 🏆