One Key, One Config File: Driving Claude Code, Cursor and a Script from the Same Endpoint
Learn how to configure Claude Code, Cursor, and plain scripts to use the same OpenAI-compatible endpoint with one API key, and avoid environment variable collisions across tools.
Why Use a Single Endpoint for Multiple Clients?
Managing separate API keys and endpoints for each tool is tedious and error-prone. By pointing all your clients to the same base URL and API key, you simplify configuration, reduce overhead, and ensure consistent access to the models you need.
This guide shows how to configure three common client types—a CLI agent (like Claude Code), an IDE plugin (like Cursor), and a plain script (Python or Node)—to use the same endpoint. We'll also cover how to avoid environment variable collisions between them.
Understanding the Shared Configuration
Most modern AI clients support OpenAI-compatible APIs. That means you can set a custom base URL and API key, and they'll work with any provider that implements the same interface.
Our service provides an OpenAI-compatible endpoint. You top up with USDC on Base (no KYC) and get one API key that works across many models. You pay the official price times 1.3, and key contributors are credited back at official price times 1.1 (or 1.2 for premium models) in USDC.
When using multiple clients, you'll typically need to set:
- Base URL: The endpoint for API requests (e.g.,
https://api.example.com/v1) - API Key: Your secret key for authentication
- Model: The model identifier you want to use
Configuring Claude Code
Claude Code is a CLI tool that can be configured via environment variables or a config file. To point it to our endpoint:
- Set the base URL environment variable. For OpenAI-compatible endpoints, Claude Code often respects
OPENAIBASEURLor a custom variable. Check its documentation for the exact variable name. - Set the API key variable (e.g.,
OPENAIAPIKEYorANTHROPICAPIKEY). - Specify the model you want to use.
Example (in your shell profile):
export OPENAI_BASE_URL="https://api.yourprovider.com/v1"
export OPENAI_API_KEY="sk-your-key"
If Claude Code uses a config file, you can set these values there instead. The key is to ensure the base URL points to our endpoint and the key is your unified API key.
Configuring Cursor
Cursor is an IDE that integrates AI features. It typically allows custom API endpoints in its settings:
- Open Cursor settings.
- Find the AI provider configuration section.
- Choose "OpenAI" or "Custom" and enter your base URL and API key.
- Select the model you want to use.
Cursor may store these settings in its own configuration, separate from environment variables. This is good—it avoids collisions with CLI tools.
Configuring a Plain Script (Python/Node)
For custom scripts, you have full control. Use the OpenAI SDK or plain HTTP requests.
Python Example
from openai import OpenAI
client = OpenAI(
base_url="https://api.yourprovider.com/v1",
api_key="sk-your-key"
)
response = client.chat.completions.create(
model="claude-3-5-sonnet",
messages=[{"role": "user", "content": "Hello"}]
)
print(response.choices[0].message.content)
Node Example
import OpenAI from 'openai';
const openai = new OpenAI({
baseURL: 'https://api.yourprovider.com/v1',
apiKey: 'sk-your-key'
});
const completion = await openai.chat.completions.create({
model: 'claude-3-5-sonnet',
messages: [{ role: 'user', content: 'Hello' }]
});
console.log(completion.choices[0].message.content);
You can also read these from environment variables to keep secrets out of code.
Avoiding Environment Variable Collisions
When multiple tools use the same environment variable names, conflicts can occur. For example, both Claude Code and a script might expect OPENAIAPIKEY. Here are strategies to avoid issues:
- Use tool-specific variable names if the tool supports it. For example, some tools accept
CLAUDEAPIKEYorCURSORAPIKEY. - Set variables per session instead of globally. In your terminal, export variables before running a specific tool:
- Use a
.envfile for scripts, and load it with a library likepython-dotenvordotenvfor Node. Keep CLI tools configured separately. - Rely on config files for IDEs like Cursor, so they don't depend on environment variables at all.
- Create wrapper scripts that set the correct variables for each tool, ensuring isolation.
```bash
OPENAIAPIKEY="sk-key" claude-code
```
Best Practices for Multi-Client Setup
- Store your API key securely—never commit it to version control.
- Use environment variables for secrets but be mindful of naming.
- Document your setup so you can reproduce it easily.
- Test each client after configuration to ensure they can reach the endpoint.
- Monitor usage to track which clients are consuming credits.
Conclusion
By pointing Claude Code, Cursor, and your scripts to the same base URL and API key, you streamline your workflow and reduce management overhead. With careful attention to environment variable naming and isolation, you can avoid collisions and ensure each tool works smoothly. Our service makes this easy with a unified OpenAI-compatible endpoint and a single key for many models.