本文へスキップ

Cloudflare OpenAI Azure Proxy

停滞
haibbo/cf-openai-azure-proxy

OpenAI API へのリクエストを Azure OpenAI Service へプロキシする軽量な Cloudflare Worker スクリプト。OpenAI 互換のクライアントでコスト効率の高い Azure を利用できます。

GitHub で見る
スター
1606
フォーク
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 プロジェクト →