z.ai2api_python  by ZyphrZero

OpenAI-compatible API proxy for diverse AI providers

Created 1 month ago
325 stars

Top 83.6% on SourcePulse

GitHubView on GitHub
Project Summary

Summary

This project offers a high-performance, OpenAI-compatible API proxy service built on FastAPI, designed to aggregate multiple AI providers like Z.AI, K2Think, and LongCat. It targets developers and power users seeking a unified interface to access diverse AI models, simplifying integration and management for applications requiring flexible, scalable AI backend solutions.

How It Works

The service functions as an API gateway, routing incoming requests to various upstream AI providers through a multi-provider architecture. It emulates the OpenAI API, enabling seamless integration with existing tools and SDKs. Key technical choices include FastAPI for asynchronous handling, Server-Sent Events (SSE) for efficient streaming responses, and an advanced token pool management system for load balancing, fault tolerance, and dynamic token updates across different AI services.

Quick Start & Requirements

  • Environment: Python 3.9-3.12.
  • Installation: Clone the repository. Install dependencies using uv sync or pip install -r requirements.txt. Run the server via uv run python main.py or python main.py.
  • Docker: Pre-built images are available on Docker Hub (zyphrzero/z-ai2api-python:latest). Deployment is supported via docker run or docker-compose.
  • API Docs: Accessible at http://localhost:8080/docs post-startup.
  • Configuration: Primarily managed through environment variables (e.g., AUTH_TOKEN, LISTEN_PORT).
  • Prerequisites: Requires obtaining provider-specific API tokens (e.g., Z.AI, LongCat) by inspecting browser local storage/cookies, which may have expiration dates.

Highlighted Details

  • Multi-Provider Support: Integrates Z.AI, K2Think, and LongCat models seamlessly.
  • OpenAI API Compatibility: Allows direct use with existing OpenAI SDKs and clients.
  • Token Pool Management: Features automatic load balancing, fault tolerance, health monitoring, and dynamic updates for API tokens.
  • Enhanced Tool Calling: Supports complex tool chains and improved function call implementation.
  • Streaming Responses: Utilizes Server-Sent Events (SSE) for high-performance, real-time output.
  • Anonymous Mode: Provides session isolation and privacy protection.

Maintenance & Community

The project is community-driven, welcoming contributions. Specific community channels (e.g., Discord, Slack) or active maintainer information are not detailed in the README.

Licensing & Compatibility

  • License: MIT License.
  • Usage Restrictions: The project explicitly states it is for "learning and research purposes only" and should "not be used for commercial purposes or scenarios that violate terms of use." Users must also comply with the terms of service of individual AI providers.

Limitations & Caveats

The project is strictly limited to learning and research; commercial use is prohibited by the project's disclaimer. It relies on manual extraction of provider-specific tokens via browser developer tools, which can be unstable and require frequent updates. Multi-modal support necessitates specific, non-anonymous Z.AI API tokens. The monitoring API is noted as having only basic functionality and not yet perfected.

Health Check
Last Commit

5 days ago

Responsiveness

Inactive

Pull Requests (30d)
17
Issues (30d)
19
Star History
152 stars in the last 30 days

Explore Similar Projects

Starred by Chris Lattner Chris Lattner(Author of LLVM, Clang, Swift, Mojo, MLIR; Cofounder of Modular), Tobi Lutke Tobi Lutke(Cofounder of Shopify), and
11 more.

modular by modular

0.2%
25k
AI toolchain unifying fragmented AI deployment workflows
Created 2 years ago
Updated 1 day ago
Feedback? Help us improve.