跳到正文

Cloudflare OpenAI Azure Proxy

不活跃
haibbo/cf-openai-azure-proxy

轻量的 Cloudflare Worker 脚本,将 OpenAI API 请求代理到 Azure OpenAI 服务,让任何兼容 OpenAI 的客户端都能使用 Azure 的高性价比服务。

在 GitHub 查看
星标
1606
Fork
194
关注
1606
未关闭 Issue
17

该介绍目前仅提供英文版本。

Bridge the gap between OpenAI clients and Azure OpenAI Service with a serverless proxy.

Overview

Most OpenAI clients don’t natively support Azure OpenAI Service, despite Azure offering simpler application processes, easier payment methods, and generous free tiers. This project solves that problem by providing a free Cloudflare Worker script that acts as a proxy, enabling any OpenAI-compatible client to seamlessly use Azure OpenAI Service.

Key Features

  • 🌐 Serverless Architecture: Runs on Cloudflare Workers with no server required
  • 💰 Cost-Effective: Free tier includes 100,000 requests per day
  • 🔌 Easy Integration: Works with virtually any OpenAI client
  • 🖨️ Streaming Support: Implements “printer mode” for streaming responses
  • 🎨 Multiple Model Support: Compatible with GPT-3, GPT-4, and DALL-E-3
  • 🐳 Docker Ready: Includes Docker deployment option (based on Wrangler)
  • 🔧 Customizable: Easy to configure for different deployments and models

Supported Models

The proxy works with a variety of Azure OpenAI models including:

  • GPT-3.5 Turbo
  • GPT-4
  • DALL-E-3

Adding support for additional model variants is straightforward through the deployment mapper configuration.

Quick Deployment

Cloudflare Worker Setup

  1. Register and log in to your Cloudflare account
  2. Create a new Cloudflare Worker
  3. Copy and paste the cf-openai-azure-proxy.js code into the Cloudflare Worker editor
  4. Configure your Azure resource name and deployment mapper (details below)
  5. Save and deploy your Worker
  6. Optional: Bind a custom domain name in Worker details → Triggers → Custom Domains

Configuration

You need to configure two main parameters:

  1. Resource Name: Your Azure OpenAI resource name
  2. Deployment Mapper: Maps OpenAI model names to your Azure deployments

Option 1: Direct Code Modification

// The name of your Azure OpenAI Resource
const resourceName = "codegpt";

// Deployment model mapper
const mapper = {
  'gpt-3.5-turbo': 'gpt3',
  'gpt-4': 'gpt4',
  'dall-e-3': 'dalle3'
};

Option 2: Environment Variables

Set these values through Cloudflare Worker console:

  1. Navigate to Workers script → Settings
  2. Add variables under Environment Variables
  3. Create variables for resourceName and mapper

Client Setup

Once deployed, you can use the proxy with any OpenAI client by setting your custom API endpoint to your Worker’s URL.

For example, with OpenCat:

  1. Go to Settings
  2. Enter your custom API domain (the domain you bound to your Worker)
  3. Use your Azure OpenAI API key

Technical Details

The proxy works by:

  1. Intercepting API calls meant for OpenAI
  2. Transforming the request format to match Azure OpenAI’s requirements
  3. Routing to the appropriate Azure deployment based on the requested model
  4. Converting Azure’s streaming responses to match OpenAI’s format
  5. Returning the results to the client in the expected format

Benefits Over Direct Azure API Usage

  • Compatibility: Use existing tools and clients without modification
  • Streaming Responses: Proper handling of streaming for chat completions
  • No Server Costs: Leverage Cloudflare’s generous free tier
  • Simple Configuration: Minimal setup compared to modifying clients

Requirements

  • Cloudflare account (free)
  • Azure account with OpenAI Service access
  • Azure OpenAI API key

License

This project is available under the MIT License.

按共同分类和标签排序的同类开源项目。

全部 AI 项目 →