/api-proxy

OpenAI、Gemini Pro Proxy | 代理服务

Primary LanguageJavaScriptMIT LicenseMIT

api-proxy

该项目为代理服务器,仅供学习和研究使用。

快速开始

  • 安装

    git clone https://github.com/TheRamU/api-proxy.git
    cd api-proxy
    npm install
  • 配置证书

    app.js

    const PRIVATE_KEY = "./certs/key.pem";
    const CERT_CHAIN = "./certs/cert.pem";
  • 运行

    npm start

以 Systemctl 方式运行

  • 安装

    git clone https://github.com/TheRamU/api-proxy.git
    cd api-proxy
    sh install.sh
  • 配置证书

    app.js

    const PRIVATE_KEY = "./certs/key.pem";
    const CERT_CHAIN = "./certs/cert.pem";
  • 启动服务 & 配置自启动

    sudo systemctl start api-proxy
    sudo systemctl enable api-proxy

    启动失败

    vim /etc/sysconfig/selinux
    SELINUX=disabled
    

部署服务

代理API

  • OpenAIhttps://proxyhost/api/proxy/openai

    curl https://proxyhost/api/proxy/openai/v1/completions \
      -H "Authorization: Bearer $OPENAI_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"prompt": YOUR_PROMPT, "model": MODEL}'
  • Googlehttps://proxyhost/api/proxy/google

    curl \
      -H 'Content-Type: application/json' \
      -d '{"contents":[{"parts":[{"text":"Hello"}]}]}' \
      -X POST https://proxyhost/api/proxy/google/v1beta/models/gemini-pro:generateContent?key=YOUR_API_KEY
  • Anthropichttps://proxyhost/api/proxy/anthropic

    curl https://proxyhost/api/proxy/anthropic/v1/messages \
        --header "x-api-key: $ANTHROPIC_API_KEY" \
        --header "anthropic-version: 2023-06-01" \
        --header "content-type: application/json" \
        --data \
    '{
        "model": "claude-3-opus-20240229",
        "max_tokens": 1024,
        "messages": [
            {"role": "user", "content": "Hello, world"}
        ]
    }'