NEWn1n v2.0.1 is live! Enterprise Unified LLM API Gateway with 500+ AI Models, up to 90% off, Try now

Running Claude Code, Cursor, and Codex CLI with a Single API Key

Authors
  • avatar
    Name
    Nino
    Occupation
    Senior Tech Editor

Modern AI-assisted software development relies on a fragmented stack of tools. Developers frequently switch between specialized command-line utilities like Claude Code, interactive IDE extensions such as Cursor, and autonomous agent frameworks like Cline or Aider. Managing separate subscriptions, token balances, rate limits, and API keys across multiple model providers—such as Anthropic, OpenAI, and DeepSeek—creates unnecessary operational overhead and security risk.

Most modern AI coding assistants allow developers to override the default API base URL. By leveraging a single LLM aggregator gateway like n1n.ai, you can route requests from all your developer tools through a unified endpoint. This approach allows you to consolidate your spending into a single pay-per-token balance while accessing premier models including Claude 3.5 Sonnet, DeepSeek-V3, and OpenAI o3-mini.

This guide explains how to configure your local development environment to run Claude Code, Cursor, Codex CLI, and custom scripts through a single API key, along with techniques for troubleshooting common gateway integration issues.


Architecture: How Multi-Protocol API Gateways Work

Developer tools generally format request payloads according to one of two industry-standard protocols:

  1. The Anthropic Messages API Specification: Used natively by tools like Claude Code and select Anthropic SDK integrations. Requests require specific HTTP headers (such as x-api-key and anthropic-version) and route to relative endpoints like /v1/messages.
  2. The OpenAI Chat Completions API Specification: Used by Cursor, Codex CLI, Aider, and standard Python/Node.js OpenAI SDKs. Requests typically use Bearer token authentication in the Authorization header and send payloads to /v1/chat/completions.

A unified gateway like n1n.ai acts as an intelligent protocol router. When configured properly, the gateway dynamically translates incoming payloads between schemas, allowing an Anthropic-formatted request from Claude Code to seamlessly access models hosted on OpenAI or DeepSeek infrastructure, and vice-versa.

Tool & Endpoint Protocol Matrix

Tool / SDKNative Protocol FormatBase URL Configuration PathDefault Auth Header
Claude CodeAnthropic MessagesRoot Base URL (https://api.n1n.ai)x-api-key or ANTHROPIC_AUTH_TOKEN
Cursor IDEOpenAI Chat Completions/v1 Base URL (https://api.n1n.ai/v1)Authorization: Bearer <KEY>
Codex CLI / AiderOpenAI Chat Completions/v1 Base URL (https://api.n1n.ai/v1)Authorization: Bearer <KEY>
Cline / Roo CodeDual (Anthropic / OpenAI)Configurable Root or /v1Tool Dependent
OpenAI Python SDKOpenAI Chat Completions/v1 Base URL (https://api.n1n.ai/v1)Authorization: Bearer <KEY>
Anthropic SDKAnthropic MessagesRoot Base URL (https://api.n1n.ai)x-api-key

Step 1: Configuring Claude Code CLI

Claude Code is Anthropic's agentic command-line tool. By default, it communicates directly with Anthropic's infrastructure. To redirect Claude Code through your unified gateway key, you must set two environment variables before executing the CLI.

macOS and Linux (Bash / Zsh)

Add the following exports to your shell configuration (~/.zshrc or ~/.bashrc):

export ANTHROPIC_BASE_URL="https://api.n1n.ai"
export ANTHROPIC_AUTH_TOKEN="your-n1n-api-key"

Apply the changes to your current terminal session:

source ~/.zshrc
claude

Windows (PowerShell)

For persistent sessions in Windows PowerShell, set the environment variables using $env:

$env:ANTHROPIC_BASE_URL = "https://api.n1n.ai"
$env:ANTHROPIC_AUTH_TOKEN = "your-n1n-api-key"
claude

To persist these environment variables across system reboots in Windows, execute:

[System.Environment]::SetEnvironmentVariable('ANTHROPIC_BASE_URL', 'https://api.n1n.ai', 'User')
[System.Environment]::SetEnvironmentVariable('ANTHROPIC_AUTH_TOKEN', 'your-n1n-api-key', 'User')

Step 2: Configuring Cursor IDE

Cursor is an AI-first code editor built as a fork of VS Code. It uses the OpenAI API format under the hood when overriding custom endpoints.

Setup Steps in Cursor:

  1. Open Cursor and navigate to Settings (Cmd + , on macOS or Ctrl + , on Windows) or click the gear icon in the top right.
  2. Go to Cursor Settings > Models > OpenAI API Key.
  3. Turn on the toggle switch labeled Override OpenAI Base URL.
  4. Enter your unified gateway endpoint: https://api.n1n.ai/v1 (Note: Ensure the /v1 path suffix is included).
  5. Paste your single API key into the OpenAI API Key field.
  6. Under the Model Names section, add your target model identifiers, such as claude-3-5-sonnet-20241022, deepseek-chat, or gpt-4o.

Once configured, Cursor routes all inline edits, chat interactions, and agentic workspace indexing commands through your unified endpoint.


Step 3: Configuring Codex CLI, Aider, and Agentic Extensions

Command-line coding frameworks like Aider, Codex CLI, and VS Code extensions like Cline or Roo Code support custom API proxy endpoints via standard environment variables or configuration files.

Configuring Aider

Aider supports multi-model operations natively. Set your base URL and API key using standard OpenAI environment variable names:

export OPENAI_API_BASE="https://api.n1n.ai/v1"
export OPENAI_API_KEY="your-n1n-api-key"

# Run Aider with Claude 3.5 Sonnet routed through your single key
aider --model openai/claude-3-5-sonnet-20241022

Configuring Cline / Roo Code (VS Code Extensions)

In the Cline or Roo Code extension settings window:

  1. Set API Provider to OpenAI Compatible or Anthropic Compatible.
  2. If selecting OpenAI Compatible, set Base URL to https://api.n1n.ai/v1.
  3. If selecting Anthropic Compatible, set Base URL to https://api.n1n.ai.
  4. Input your unified API key into the API Key field.

Step 4: Programmatic Access via Python and Node.js SDKs

If you build custom automated scripts, code reviewers, or CI/CD pipelines alongside your CLI tools, you can use standard official SDKs without installing proprietary client libraries.

Python Implementation (OpenAI SDK)

import os
from openai import OpenAI

# Initialize client using single unified gateway endpoint
client = OpenAI(
    api_key=os.getenv("N1N_API_KEY