# Set up Claude Code, Codex, OpenCode, Cline or Cursor

> Point the agent you already use at Modeless in a few minutes. Setup guides per tool, plus API basics: base URL, auth, endpoints, sessions, errors.

Source: https://modeless-web.vercel.app/integrations

Pick your tool, create a key and paste in the settings. Any client that speaks one of the three protocols below works with the same settings.

## Your agent

### Claude Code

Protocol: Anthropic Messages. Recommended model: `auto`.

1. **Create an API key** Sign up at modeless.ai and create a key in the console.
2. **Point Claude Code at Modeless** Add these to your shell profile, then open a new terminal.

   ```bash
   export ANTHROPIC_BASE_URL="https://api.modeless.ai"
   export ANTHROPIC_AUTH_TOKEN="<your-modeless-key>"
   export ANTHROPIC_MODEL="auto"
   ```

Check it works: Run `claude` and send one message. `/status` shows the Modeless base URL.

Notes:
- Routing survives context compaction: the session keeps its model.
- Sub-agents get their own routing state, separate from the parent.

### Codex CLI

Protocol: OpenAI Responses. Recommended model: `auto`.

1. **Create an API key** Sign up at modeless.ai and create a key in the console.
2. **Add a provider to ~/.codex/config.toml**

   ```toml
   model = "auto"
   model_provider = "modeless"
   
   [model_providers.modeless]
   name = "Modeless"
   base_url = "https://api.modeless.ai/v1"
   env_key = "MODELESS_API_KEY"
   wire_api = "responses"
   ```
3. **Export your key**

   ```bash
   export MODELESS_API_KEY="<your-modeless-key>"
   ```

Check it works: Run `codex` and send one message. The header shows model `auto`.

### OpenCode

Protocol: OpenAI Chat Completions. Recommended model: `auto`.

1. **Create an API key** Sign up at modeless.ai and create a key in the console.
2. **Add Modeless to opencode.json**

   ```json
   {
     "$schema": "https://opencode.ai/config.json",
     "provider": {
       "modeless": {
         "npm": "@ai-sdk/openai-compatible",
         "name": "Modeless",
         "options": {
           "baseURL": "https://api.modeless.ai/v1",
           "apiKey": "{env:MODELESS_API_KEY}"
         },
         "models": {
           "auto": { "name": "Auto" },
           "fusion": { "name": "Fusion" }
         }
       }
     },
     "model": "modeless/auto"
   }
   ```

Check it works: Run `opencode`, pick `modeless/auto` with /models, and send one message.

### Cline

Protocol: OpenAI Chat Completions. Recommended model: `auto`.

1. **Create an API key** Sign up at modeless.ai and create a key in the console.
2. **Open Cline settings** Set API Provider to OpenAI Compatible, then fill in:

   ```text
   Base URL   https://api.modeless.ai/v1
   API Key    <your-modeless-key>
   Model ID   auto
   ```

Check it works: Start a new task. The task header shows model `auto`.

### Cursor

Protocol: OpenAI Chat Completions. Recommended model: `fusion`.

1. **Create an API key** Sign up at modeless.ai and create a key in the console.
2. **Settings → Models** Enable Override OpenAI Base URL, paste your key, and add custom models:

   ```text
   OpenAI Base URL   https://api.modeless.ai/v1
   OpenAI API Key    <your-modeless-key>
   Custom models     auto, fusion
   ```

Check it works: Select `auto` in the chat model picker and send one message.

## API basics

Modeless accepts three API formats unchanged. Change the base URL and the model name, and your existing client keeps working.

- **Base URL**: `https://api.modeless.ai`. Add `/v1` for OpenAI clients. Anthropic clients take the bare host.
- **Authentication**: Your Modeless key, as `Authorization: Bearer` or `x-api-key`, the way your SDK already sends it.
- **Endpoints**:
  - `POST /v1/chat/completions`: OpenAI Chat Completions
  - `POST /v1/messages`: Anthropic Messages
  - `POST /v1/responses`: OpenAI Responses
  JSON or SSE streaming on all three.
- **Models**:
  - `auto`: picks the model as the session goes
  - `fusion`: panel plus aggregator
- **Sessions**: Auto treats each conversation as one session. If you build your own agent, send `X-Session-ID` with a stable id per task. Without it, Auto recognizes a session by its first user message. Claude Code's own session header is read automatically.
- **Errors**: Errors come back in the format of the protocol you called, so your SDK's error handling works unchanged. With Auto, a request too large for every model's context window returns 400.

### OpenAI SDK

```python
from openai import OpenAI

client = OpenAI(base_url="https://api.modeless.ai/v1", api_key="<your-modeless-key>")

stream = client.chat.completions.create(
    model="auto",
    messages=[{"role": "user", "content": "Write a migration for..."}],
    stream=True,
    extra_headers={"X-Session-ID": "task-1842"},
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")
```

### Anthropic SDK

```python
from anthropic import Anthropic

client = Anthropic(base_url="https://api.modeless.ai", api_key="<your-modeless-key>")

msg = client.messages.create(
    model="fusion",
    max_tokens=4096,
    messages=[{"role": "user", "content": "Review this design: ..."}],
)
print(msg.content[0].text)
```

### curl

```bash
curl https://api.modeless.ai/v1/responses \
  -H "Authorization: Bearer $MODELESS_API_KEY" \
  -H "Content-Type: application/json" \
  -H "X-Session-ID: task-1842" \
  -d '{"model": "auto", "input": "Explain this stack trace: ..."}'
```
