Skip to content

albcunha/Cursor-Azure-Claude

 
 

Repository files navigation

Azure Anthropic Proxy for Cursor

Proxy server để kết nối Cursor IDE với Azure Anthropic API (Claude).

🌐 Production URLs

📋 Endpoints

Root Endpoint

  • GET / - Thông tin về server và các endpoints có sẵn

Health Check

  • GET /health - Kiểm tra trạng thái server

Chat Endpoints

  • POST /chat/completions - Endpoint chính cho Cursor IDE (OpenAI format)
  • POST /v1/chat/completions - OpenAI format
  • POST /v1/messages - Anthropic native format

🚀 Cách sử dụng

Cấu hình trong Cursor IDE

  1. Mở Cursor Settings
  2. Tìm phần "Model" hoặc "Model Settings" Mở "Opus 4.5"
  3. API Keys mucj OpenAI Custom API URL: https://cursor-azure-claude-proxy-production.up.railway.app
  4. Đặt API Key: Giá trị phải trùng khớp chính xác với biến môi trường SERVICE_API_KEY trong file .env của server. Bật OpenAI API key

Cấu hình Model trong Cursor IDE

Cấu hình Chat trong Cursor IDE

Lưu ý quan trọng: API Key trong Cursor IDE (Cursor Settings > Models > API Keys > OpenAI API Key) phải khớp chính xác với giá trị SERVICE_API_KEY trong file .env của server. Nếu không khớp, request sẽ bị từ chối với lỗi authentication.

Ví dụ Request

curl -X POST https://cursor-azure-claude-proxy-production.up.railway.app/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_SERVICE_API_KEY" \
  -d '{
    "model": "claude-opus-4-5",
    "messages": [
      {"role": "user", "content": "Hello!"}
    ]
  }'

Lưu ý: Thay YOUR_SERVICE_API_KEY bằng giá trị thực từ biến môi trường SERVICE_API_KEY.

⚙️ Environment Variables

Claude (Azure Anthropic)

  • AZURE_ENDPOINT - Foundry resource base URL, e.g. https://<resource>.services.ai.azure.com (bare host, no path). The server appends /anthropic/v1/messages for Claude and reuses the same host for the Azure OpenAI calls. The legacy full-URL form (.../anthropic/v1/messages) is still accepted for backward compatibility.
  • AZURE_API_KEY - Azure API key (shared with the OpenAI endpoint on the same Foundry resource)
  • AZURE_CLAUDE_DEPLOYMENT_NAME - Default Claude deployment name, e.g. claude-opus-4-7. Used for every Claude request unless a family-specific override is set.
  • (optional) AZURE_CLAUDE_OPUS_DEPLOYMENT, AZURE_CLAUDE_SONNET_DEPLOYMENT, AZURE_CLAUDE_HAIKU_DEPLOYMENT - override the deployment per model family

GPT-5.4 (Azure OpenAI)

Azure OpenAI uses a different host than Anthropic (cognitiveservices.azure.com instead of services.ai.azure.com), so AZURE_OPENAI_ENDPOINT is required for GPT. Leave it unset to disable the GPT route — Claude keeps working either way.

  • AZURE_OPENAI_ENDPOINT - Azure OpenAI endpoint. Two forms are supported:
    • v1 API (recommended): https://<resource>.cognitiveservices.azure.com/openai/v1
      • Request URL becomes <endpoint>/chat/completions?api-version=preview — the api-version is fixed and AZURE_OPENAI_API_VERSION is ignored.
    • Legacy deployment URL: https://<resource>.cognitiveservices.azure.com
      • Request URL becomes <host>/openai/deployments/<deployment>/chat/completions?api-version=<AZURE_OPENAI_API_VERSION>.
  • AZURE_GPT_DEPLOYMENT - Exact name of the gpt-5.4 deployment in your Azure resource. Default gpt-5.4
  • AZURE_OPENAI_API_VERSION - Only used with the legacy endpoint form. Default 2025-04-01-preview.
  • GPT_REASONING_EFFORT - Fallback effort (minimal / low / medium / high) when Cursor sends the bare gpt-5.4 id without a suffix. Default medium
  • (optional) AZURE_OPENAI_API_KEY - defaults to AZURE_API_KEY

Service

  • SERVICE_API_KEY - Key used to authenticate Cursor against this proxy (must match Cursor's OpenAI API Key field)
  • PORT - Server port (default 8080; Railway assigns its own)
  • (optional) LOG_TOOL_CALLS, LOG_MESSAGES - verbose logging toggles (true/false)

🤖 Using GPT-5.4 in Cursor

Azure Foundry ships gpt-5.4 with native Chat Completions support since 2026-03-05, so the proxy forwards Cursor's OpenAI request almost unchanged (only swapping the model name to the deployment, stripping temperature/top_p, and converting max_tokensmax_completion_tokens, as required by reasoning models).

  1. Deploy gpt-5.4 in the same Foundry resource you use for Claude. Note that gpt-5.4 and gpt-5.4-pro currently require access registration on Azure.

  2. Set the AZURE_OPENAI_* env vars above on Railway and redeploy.

  3. In Cursor Settings → Models → Custom Models, add any of these model ids. Each one maps to the same Azure deployment, only reasoning_effort changes:

    Cursor model id reasoning_effort
    gpt-5.4 falls back to GPT_REASONING_EFFORT (default medium)
    gpt-5.4-minimal minimal
    gpt-5.4-low low
    gpt-5.4-medium medium
    gpt-5.4-high high
  4. Keep the OpenAI API Key field set to your SERVICE_API_KEY and the base URL pointing at this proxy — both Claude and GPT-5.4 share the same proxy endpoint and auth key.

Quick smoke test

curl -X POST https://cursor-azure-claude-proxy-production.up.railway.app/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $SERVICE_API_KEY" \
  -d '{
    "model": "gpt-5.4-medium",
    "messages": [{"role": "user", "content": "Say hi in one word."}]
  }'

📦 Installation

npm install
npm start

🔧 Development

npm run dev

🚂 Deploy trên Railway

Cấu hình nhanh

  1. Tạo project mới trên Railway

    • Truy cập Railway
    • Tạo project mới từ GitHub repository hoặc Deploy từ GitHub
  2. Cấu hình Environment Variables

    • Vào tab Variables trong Railway project
    • Thêm các biến môi trường sau:
      # Azure Anthropic
      AZURE_ENDPOINT=https://<resource>.services.ai.azure.com
      AZURE_API_KEY=your-azure-api-key
      AZURE_CLAUDE_DEPLOYMENT_NAME=claude-opus-4-7
      AZURE_CLAUDE_SONNET_DEPLOYMENT=claude-sonnet-4-6
      AZURE_CLAUDE_HAIKU_DEPLOYMENT=claude-haiku-4-6
      
      # Azure OpenAI (gpt-5.4) — note different host from AZURE_ENDPOINT
      AZURE_OPENAI_ENDPOINT=https://<resource>.cognitiveservices.azure.com/openai/v1
      AZURE_GPT_DEPLOYMENT=gpt-5.4
      GPT_REASONING_EFFORT=high
      # Only needed with the legacy (non-/openai/v1) endpoint form:
      # AZURE_OPENAI_API_VERSION=2025-04-01-preview
      
      # Service
      SERVICE_API_KEY=your-random-secret-key
      PORT=3000
      LOG_TOOL_CALLS=false
      LOG_MESSAGES=false
      
    • Lưu ý: SERVICE_API_KEY để bảo vệ dịch vụ của bạn. Hãy đặt nó thành một chuỗi ký tự ngẫu nhiên.

    Cấu hình Environment Variables trên Railway

  3. Cấu hình Build Settings

    • Railway sẽ tự động detect Node.js project
  4. Deploy

    • Railway sẽ tự động deploy khi bạn push code lên GitHub
    • Hoặc click Deploy trong Railway dashboard
    • Sau khi deploy thành công, Railway sẽ cung cấp một public URL
  5. Kiểm tra Health Check

    • Truy cập: https://your-app.up.railway.app/health
    • Nếu trả về {"status":"ok"}, server đã chạy thành công
  6. Cấu hình Custom Domain (tùy chọn)

    • Vào tab Settings > Networking
    • Thêm custom domain nếu cần

    Cấu hình Custom Domain trên Railway

Lưu ý khi deploy

  • Railway tự động cung cấp PORT qua biến môi trường, nhưng bạn vẫn có thể set PORT=8080 để đảm bảo
  • SERVICE_API_KEY phải khớp chính xác với API Key bạn cấu hình trong Cursor IDE
  • Kiểm tra logs trong Railway dashboard nếu gặp lỗi

📝 License

MIT

🙏 Tham khảo

Dự án này được tham khảo từ Cursor-Azure-GPT-5 - một service cho phép Cursor sử dụng Azure GPT-5 deployments.

About

Proxy server to connect Cursor IDE with Azure Anthropic API (Claude). Transform OpenAI format to Anthropic format. Supports Claude Opus 4.5, streaming, and Railway deployment.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • JavaScript 100.0%