Tutorial: Integrating Relay API in Cursor with Custom Base URL

  • 发布时间
  • 语言en

Configure custom API Keys and Base URLs in Cursor's Settings → Models to use your own keys for accessing Claude, GPT, and Gemini models.

1. What is Cursor?

Cursor is an AI-native code editor built on top of VS Code, featuring deep integration with AI chat, code generation (Composer/Chat), and intelligent code completion. It supports BYOK (Bring Your Own Key), allowing you to connect your own model endpoints using your personal API key—perfect for scenarios where you prefer not to purchase an official subscription or want to consolidate your model usage.

By connecting through a relay service, you can use Claude, GPT, or Gemini models via your own sk- API key on a pay-per-token basis, without needing an official Cursor subscription.

2. Preparation

  1. Log in to the Azztimes console and generate your exclusive sk-xxxxxx key under "API Keys".
  2. Check the "Model Pricing" section to confirm the model slug you wish to use (e.g., claude-sonnet-5, gpt-5.4, gemini-3.7-flash).
  3. Confirm the gateway URL: https://www.relay-api.com.

3. Configuring in Cursor

Open Cursor → Settings → Models → API Keys (or simply search for Models in the settings):

  1. Select the model provider you wish to use (OpenAI for OpenAI, Anthropic for Claude, Google Gemini for Gemini).
  2. Enter your API Key: sk-your-key.
  3. Enter the Override Base URL: Use the corresponding gateway address based on your provider:
    • Claude / Anthropic: https://www.relay-api.com
    • GPT / OpenAI: https://www.relay-api.com/v1
    • Gemini: https://www.relay-api.com/v1beta
  4. Add the specific model ID in the Models list (copy the slug from the model library; do not use the display name).
  5. Click Verify to test the connection; then send a short message in a regular Chat window to ensure it returns a valid response.

4. Verification and Troubleshooting

IssueResolution
401 / 403Key is invalid, disabled, or has insufficient balance; verify the sk- key and add credit.
404 / Model unavailableThe model slug does not match the platform or the model is disabled; check the Model ID.
Verify succeeds but Agent failsDifferences in the /chat/completions protocol; verify basic connectivity via standard Chat first.
Tab completion not workingTab Completion and other dedicated features use Cursor's internal models; this is a product constraint and not related to the Base URL configuration.

Security Tip: Never commit your API keys to public repositories. It is recommended to create separate keys for each project and monitor your balance and usage details regularly.