DEV Community

dougame
dougame

Posted on

How to Configure Third-Party APIs for AI Coding Agents (Claude Code, Cursor, Cline, Codex)

If you're using AI coding tools like Claude Code, Cursor, Cline, or Codex, you've probably wondered: can I use a different API provider than the default? The answer is yes - almost all of these tools support custom API endpoints.

This guide covers how to configure third-party APIs for the most popular AI coding agents, plus a tool that makes switching between configurations much easier.

Why configure a third-party API?

Before we get into the how, let's talk about why you'd want to do this in the first place:

  • Cost savings: Frontier models are expensive. Routine coding tasks don't need the most expensive model.
  • More model choice: Maybe you want to use DeepSeek, Qwen, Kimi, or GLM instead of only Claude or GPT.
  • No vendor lock-in: Don't want to be tied to one provider's pricing or TOS.
  • Better performance: Some providers are faster or cheaper for specific tasks.

The common pattern

Almost all modern AI coding tools follow the same pattern: they speak the OpenAI-compatible API format. That means you just need three things:

  1. A Base URL for the API endpoint
  2. An API Key for authentication
  3. A model name to specify which model to use

Let's go through each tool.

Claude Code

Claude Code uses Anthropic's Messages API format. To configure a custom endpoint:

# Set environment variables
export ANTHROPIC_BASE_URL="https://your-api-endpoint.com"
export ANTHROPIC_API_KEY="your-api-key"
Enter fullscreen mode Exit fullscreen mode

Or in your Claude Code settings file, set:

  • ANTHROPIC_BASE_URL
  • ANTHROPIC_AUTH_TOKEN

Note: Claude Code uses the Messages protocol (/v1/messages), not Chat Completions. Make sure your API provider supports the Messages format.

Cursor

Cursor supports custom OpenAI-compatible endpoints out of the box:

  1. Open Cursor Settings
  2. Go to Models
  3. Click Add Model
  4. Select OpenAI API as the provider
  5. Enter:
    • Base URL: your API endpoint (e.g., https://your-api.com/v1)
    • API Key: your key
    • Model Name: the model you want to use

That's it. Now you can select this model from the dropdown in the chat.

Cline (VS Code extension)

Cline also supports custom OpenAI-compatible providers:

  1. Open Cline settings
  2. Go to API Configuration
  3. Select OpenAI Compatible as the API Provider
  4. Enter:
    • Base URL: your endpoint URL
    • API Key: your key
    • Model ID: the model name

Cline is very flexible - you can add multiple providers and switch between them.

Codex (OpenAI's CLI)

OpenAI's Codex CLI also supports custom endpoints:

# Set environment variables
export OPENAI_BASE_URL="https://your-api-endpoint.com/v1"
export OPENAI_API_KEY="your-api-key"
Enter fullscreen mode Exit fullscreen mode

Or in your config.toml, set the provider settings.

Zed Editor

Zed has built-in support for custom model providers:

  1. Open Zed Settings
  2. Go to Assistant
  3. Under Model Providers, click Add Provider
  4. Select OpenAI Compatible
  5. Enter the Base URL and API key

Switching between configurations: CC Switch

Once you have multiple API configurations (e.g., one for work, one for personal, one for testing different models), managing them all gets tedious. That's where CC Switch comes in.

CC Switch is a simple tool that lets you:

  • Save multiple API configurations (different endpoints, keys, models)
  • Switch between them with one click
  • No need to manually edit config files or environment variables every time

It supports Claude Code, Cursor, and other tools. If you're juggling multiple API providers, it saves a lot of context switching.

Which API provider to use?

You need an API provider that:

  1. Is OpenAI-compatible (or supports the Messages protocol for Claude Code)
  2. Has the models you want
  3. Has transparent pricing
  4. Doesn't require a monthly subscription

I've been using JZS Token (https://jzstoken.com) as my API gateway. It's a single OpenAI-compatible endpoint at https://jzstoken.com/api/v1 that gives you access to 40+ models: DeepSeek, Qwen, Kimi, GLM, Claude, GPT, Grok, Doubao, and more.

Why I like it:

  • One key, all models: No more juggling 10 different API keys
  • All three protocols: Chat Completions, Responses, and Messages
  • Pay as you go: Credits don't expire, no monthly commitment
  • Transparent pricing: All rates listed upfront, no surprise bills

The setup for any tool is the same:

  • Base URL: https://jzstoken.com/api/v1
  • API Key: your JZS Token key
  • Model: whatever model you want to use

Putting it all together

  1. Get an API key from a provider like JZS Token
  2. Configure your AI coding tool with the Base URL and key
  3. Use CC Switch to manage multiple configurations if you have more than one

The whole setup takes 5 minutes, and then you can use whatever model makes the most sense for each task - instead of being locked into one provider's pricing.

Have you configured custom APIs for your AI coding tools yet? What's your setup? Let me know in the comments.

Top comments (0)