CoolFace
Apppublic

mouse0524/CliProxyAPI

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes
App README

<div align="center"> <br/>

 ██████╗ ██╗  ██╗      ███╗   ███╗██╗   ██╗      █████╗ ██████╗ ██╗
██╔═══██╗██║  ██║      ████╗ ████║╚██╗ ██╔╝     ██╔══██╗██╔══██╗██║
██║   ██║███████║      ██╔████╔██║ ╚████╔╝      ███████║██████╔╝██║
██║   ██║██╔══██║      ██║╚██╔╝██║  ╚██╔╝       ██╔══██║██╔═══╝ ██║
╚██████╔╝██║  ██║      ██║ ╚═╝ ██║   ██║        ██║  ██║██║     ██║
 ╚═════╝ ╚═╝  ╚═╝      ╚═╝     ╚═╝   ╚═╝        ╚═╝  ╚═╝╚═╝     ╚═╝

统一 AI API 代理网关

![Version](.) ![SDK](.) ![Status](.) ![License](.)

<br/>

一个运行在 HuggingFace Space 上的高性能 AI API 代理,<br/> 统一接入 Claude · Gemini · OpenAI · Codex · Vertex AI

<br/>

</div>


⚡ 支持的模型

提供商支持模型接入方式
🟣 Anthropic ClaudeClaude 4.5 / 4.6 全系列API Key
🔵 Google GeminiGemini 3.1 Pro / FlashAPI Key
🟢 OpenAIGPT-5.1 / GPT-5.2API Key
🟡 Vertex AIGemini on Vertex服务账号
OpenAI-compat任意兼容 OpenAI 格式的服务API Key

🚀 快速接入

将你的 API Base URL 替换为本 Space 地址即可:

bash
# 原始请求
curl https://api.anthropic.com/v1/messages ...

# 替换为本代理
curl https://[user_name]-[space_name].hf.space/v1/messages \
  -H "x-api-key: 你的访问密钥" \
  -H "Content-Type: application/json" \
  -d '{"model": "claude-4-6-sonnet", "max_tokens": 1024, "messages": [{"role": "user", "content": "Hello"}]}'

Python 示例

python
import anthropic

client = anthropic.Anthropic(
    api_key="你的访问密钥",
    base_url="https://[user_name]-[space_name].hf.space",
)

message = client.messages.create(
    model="claude-4-6-sonnet",
    max_tokens=1024,
    messages=[{"role": "user", "content": "你好!"}]
)
print(message.content)

OpenAI SDK 兼容

python
from openai import OpenAI

client = OpenAI(
    api_key="你的访问密钥",
    base_url="https://[user_name]-[space_name].hf.space/openai",
)

response = client.chat.completions.create(
    model="gpt-5.1",
    messages=[{"role": "user", "content": "你好!"}]
)

🏗️ 技术架构

┌─────────────────────────────────────────────────────┐
│                HuggingFace Space                     │
│                                                     │
│   Client Request                                    │
│        │                                            │
│        ▼                                            │
│   ┌─────────────┐        ┌──────────────────────┐   │
│   │             │        │   Supabase PostgreSQL │   │
│   │ CLIProxyAPI │◄──────►│   Token Store         │   │
│   │  :7860      │        │   Config Store        │   │
│   │             │        └──────────────────────┘   │
│   └──────┬──────┘                                   │
│          │                                          │
└──────────┼──────────────────────────────────────────┘
           │
    ┌──────┴───────┐
    │              │
    ▼              ▼
 Anthropic      Google
 Claude API     Gemini API

⚙️ 部署配置

必需环境变量

在 HuggingFace Space Settings → Secrets 中配置:

变量名说明示例
PGSTORE_DSNPostgreSQL 连接字符串postgresql://user:pass@host:6543/postgres?sslmode=require
MANAGEMENT_PASSWORD管理后台密码your-secure-password

🔑 添加 API Key

服务启动后,通过管理接口添加你的 API Key:

bash
# 添加 Claude Key
curl -X POST https://[user_name]-[space_name].hf.space/management/clients \
  -H "Authorization: Bearer $MANAGEMENT_PASSWORD" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "my-client",
    "claude-keys": ["sk-ant-api03-xxxxx"]
  }'

# 添加 Gemini Key  
curl -X POST https://[user_name]-[space_name].hf.space/management/clients \
  -H "Authorization: Bearer $MANAGEMENT_PASSWORD" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "my-client",
    "gemini-keys": ["AIzaSy-xxxxx"]
  }'

<div align="center"> <br/>

Built with ❤️ · Powered by CLIProxyAPI · Hosted on HuggingFace

<br/>

</div>