Cursor Custom API Configuration

How to Configure a Custom API Key and Base URL in Cursor

Cursor AI IDE supports custom API keys and base URLs, allowing you to use your own API accounts, third-party providers, or relay services instead of the built-in Cursor subscription. This is essential for developers who need to control their API usage, use specific model versions, access models from restricted regions, or route requests through a centralized gateway.

Why Use a Custom API Key?

There are several reasons to configure your own API credentials in Cursor:

Step-by-Step Configuration

Configuring an OpenAI-Compatible API

Most relay services and alternative providers use the OpenAI-compatible API format. Here is how to configure it:

  1. Open Cursor and go to Settings (Cmd+, on macOS, Ctrl+, on Windows/Linux).
  2. Click on Cursor Settings in the left sidebar (not the VS Code settings).
  3. Navigate to the Models section.
  4. Find the OpenAI API Key field and enter your API key.
  5. Click on Override OpenAI Base URL and enter your custom endpoint.
  6. Click Verify to test the connection.
// Example configuration for claude4u.com relay service:
API Key: cr_your-relay-api-key-here
Base URL: https://claude4u.com/v1
After configuring the base URL, make sure to select the correct model in Cursor's model picker. The relay service must support the model you select. Check your relay service documentation for the list of available model identifiers.

Configuring Anthropic (Claude) API

To use Claude models directly or through a compatible endpoint:

  1. In Cursor Settings, go to the Models section.
  2. Find Anthropic API Key and enter your key.
  3. If using a relay service, you may need to configure the base URL to your relay endpoint.

Configuring Google (Gemini) API

  1. In Cursor Settings, go to the Models section.
  2. Find Google API Key and enter your Gemini API key.
  3. Select Gemini models from the model picker when starting a conversation.

Using a Relay Service as Your Provider

A relay service like claude4u.com acts as a unified gateway to multiple AI models. When configured as your API endpoint in Cursor, it provides several advantages:

// Configuration for relay service in Cursor:
//
// Step 1: Override OpenAI Base URL with the relay endpoint
// Step 2: Enter the relay API key as the OpenAI API Key
// Step 3: Select models that the relay service supports
//
// The relay service translates requests to the appropriate
// provider format automatically.

Verifying Your Configuration

After setting up your custom API key and base URL:

  1. Click the Verify button next to the API key field to test connectivity.
  2. Open a new chat (Cmd+L) and send a simple test message like "Hello, which model are you?"
  3. Check the response to confirm the correct model is responding.
  4. Try an inline edit (Cmd+K) on a small code block to verify all features work.

Troubleshooting Common Issues

Never share your API keys publicly or commit them to version control. If you accidentally expose a key, rotate it immediately through your provider's dashboard. Cursor stores API keys locally in your settings and does not transmit them except to the configured API endpoint.

Advanced Configuration

For team environments, you can configure Cursor settings at the project level by creating a .cursor/settings.json file in your repository. However, API keys should never be stored in project-level settings — always use personal settings or environment variables for credentials.

Get Started with 轻舟 AI

Stable, fast AI API relay — supports Claude, OpenAI, Gemini and more

Sign Up Free