# Connect Cursor, LiteLLM or the OpenAI SDK with the base URL

**OpenCheap** speaks the OpenAI API, so Cursor, LiteLLM and the OpenAI SDK connect with three values: the base URL `https://api.opencheap.si/v1`, an OpenCheap API key, and a model id. In **Cursor**, paste the key under OpenAI API Key, turn on Override OpenAI Base URL, and add the model as `opencheap/claude-sonnet-5`. In **LiteLLM**, call `openai/claude-sonnet-5` with `api_base` set to the same URL. In the **OpenAI SDK**, set `base_url` (or `OPENAI_BASE_URL`) and the key.

[Get API key](https://opencheap.si/start?onboarding=signin)

Updated November 17, 2026

**3** values to set: base URL, key, model id

**901** chat models behind that one URL

**/v1** where the base URL ends

## The three values

Every tool below takes the same three. Get the key in the console under API keys.

| Value | Set it to | Watch for |
| --- | --- | --- |
| Base URL | `https://api.opencheap.si/v1` | It ends in /v1. Do not paste a full request URL: the tool adds /chat/completions itself. |
| API key | Your OpenCheap key, starting kl_live_ | Sent as `Authorization: Bearer <key>`. A key from OpenAI or another provider does not work here. |
| Model id | `claude-sonnet-5` | The plain id from the [Models](https://opencheap.si/models) page. `opencheap/` in front works everywhere, and Cursor needs it for ids that start with claude-. |

## Environment variables

Keep the key out of your code. The examples on this page read it from one variable.

| Variable | Value | Read by |
| --- | --- | --- |
| `OPENCHEAP_API_KEY` | Your OpenCheap key | The examples on this page and in the docs, and the LiteLLM config below (os.environ/…). |
| `OPENAI_BASE_URL` | `https://api.opencheap.si/v1` | The OpenAI Python and JavaScript SDKs, when the client is built with no base URL. |
| `OPENAI_API_KEY` | Your OpenCheap key | The same SDKs, when the client is built with no key. |

With the two `OPENAI_` variables set, code that already builds `OpenAI()` with no arguments calls OpenCheap without a change. Set them only for the program that should call OpenCheap: any other tool that reads them would send its requests here too.

terminal

```
# The OpenAI SDKs read these two when the client is built with no arguments
export OPENAI_BASE_URL=https://api.opencheap.si/v1
export OPENAI_API_KEY=<your OpenCheap key>

# Python: client = OpenAI()      JavaScript: const client = new OpenAI()
```

## The OpenAI SDK

The base URL and the key change; your prompts, tools and parsing stay the same.

python

```
from openai import OpenAI
import os

client = OpenAI(
    base_url="https://api.opencheap.si/v1",
    api_key=os.environ["OPENCHEAP_API_KEY"],
)

r = client.chat.completions.create(
    model="claude-sonnet-5",
    messages=[{"role": "user", "content": "Say hello in five words."}],
)
print(r.choices[0].message.content)
print(r.usage)  # tokens, and cost: what this request was charged in USD
```

javascript

```
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.opencheap.si/v1",
  apiKey: process.env.OPENCHEAP_API_KEY,
});

const r = await client.chat.completions.create({
  model: "claude-sonnet-5",
  messages: [{ role: "user", content: "Say hello in five words." }],
});
console.log(r.choices[0].message.content);
```

Streaming is the same call with `stream=True`. The answer arrives as server-sent events in OpenAI's shape; with `stream_options` `include_usage` set, as with OpenAI, a last chunk carries `usage` and its cost.

python

```
stream = client.chat.completions.create(
    model="claude-sonnet-5",
    messages=[{"role": "user", "content": "Write a haiku about routers."}],
    stream=True,
    stream_options={"include_usage": True},  # a last chunk with usage and its cost
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
```

## Cursor

Cursor takes the key and the base URL in its own settings.

1. **Open Cursor Settings, then Models.**
2. **Under OpenAI API Key, paste your key.** The key from the console.
3. **Turn on Override OpenAI Base URL, paste the URL and click Verify.** `https://api.opencheap.si/v1`
4. **Click Add Custom Model, type the name as it is here (opencheap/ and the model id), and enable it.** For example `opencheap/claude-sonnet-5`: opencheap/ and any id from the Models page.
5. **Pick it in the chat's model menu.**

Keep the opencheap/ in front of the model id: Cursor keeps names that start with claude- for its own Anthropic connection and answers "Model name is not valid", so a plain claude-sonnet-5.5 never reaches the base URL. OpenCheap accepts opencheap/ in front of every model id.

Two things Cursor's own documentation says about your own keys: they work for chat models only, and Tab completion keeps using Cursor's built-in models; and requests made with them are routed through Cursor's servers. So the base URL has to be reachable from the internet. OpenCheap's is; a LiteLLM proxy on `localhost` is not.

## LiteLLM

An openai/ model name, an api_base and your key, in the Python SDK and in the proxy.

python

```
import os
import litellm

response = litellm.completion(
    model="openai/claude-sonnet-5",
    api_base="https://api.opencheap.si/v1",
    api_key=os.environ["OPENCHEAP_API_KEY"],
    messages=[{"role": "user", "content": "Say hello in five words."}],
)
print(response.choices[0].message.content)
```

The `openai/` in front is LiteLLM's own prefix: it picks LiteLLM's OpenAI-compatible route, and `claude-sonnet-5` is what OpenCheap receives. Add `stream=True` to stream; tool calls and `acompletion` take the same three arguments.

For the proxy, list the models it offers. The second entry lets a client ask for any OpenCheap id as opencheap/<id>.

config.yaml

```
model_list:
  - model_name: claude-sonnet-5
    litellm_params:
      model: openai/claude-sonnet-5
      api_base: https://api.opencheap.si/v1
      api_key: os.environ/OPENCHEAP_API_KEY
  # any other model, as opencheap/<id>
  - model_name: opencheap/*
    litellm_params:
      model: openai/*
      api_base: https://api.opencheap.si/v1
      api_key: os.environ/OPENCHEAP_API_KEY
```

Clients of the proxy send the proxy's own key (`LITELLM_MASTER_KEY` or a virtual key LiteLLM issues); your OpenCheap key stays on the proxy. The full setup is in the [LiteLLM docs page](https://docs.opencheap.si/integrations/litellm).

## Common errors

What the API answers when one of the three values is off, and the fix.

| You see | Why | Fix |
| --- | --- | --- |
| `401` invalid_api_key | The key is wrong, revoked, or from another provider; or the variable that holds it is empty in the shell the program runs in. | Copy the key again from the console; check `echo $OPENCHEAP_API_KEY` in that shell. Behind the LiteLLM proxy, clients send the proxy's key, not this one. |
| `402` with an `accepts` list | No Authorization header reached the API, so it answered with the price of paying for that one call in USDC (x402). | Send the key: `Authorization: Bearer <key>`. In the SDK, check that `api_key` is set. |
| `402` insufficient_balance | The balance does not cover the request. The message says how much it may need and how much is available. | Top up in the console, or set a lower max_tokens. |
| `404` not_found | The path is wrong: the base URL lacks `/v1`, has it twice, or is a full request URL. | Use `https://api.opencheap.si/v1` exactly. |
| `404` model_not_found | That id is not listed. | Copy the id from the Models page, or list them with `GET /v1/models`. |
| Cursor: “Model name is not valid” | Cursor keeps names that start with claude- for its own Anthropic connection. | Add the model as `opencheap/claude-sonnet-5`. |
| A long answer is cut off, or the call times out | Without streaming, nothing comes back until the whole answer is written, and many apps close a call after a fixed 30 or 60 seconds. A closed call can still be charged for what the model wrote. | Set `stream` to true, or raise the client's timeout. |

Every code, and which ones to retry, is in the [errors](https://docs.opencheap.si/errors) docs.

## Check it works

Before you open a tool, check the key and the URL from a terminal.

terminal

```
# 1. The key and the URL: lists the models your key can call
curl https://api.opencheap.si/v1/models -H "Authorization: Bearer $OPENCHEAP_API_KEY"

# 2. One call: the answer, and usage with the cost
curl https://api.opencheap.si/v1/chat/completions \
  -H "Authorization: Bearer $OPENCHEAP_API_KEY" -H "Content-Type: application/json" \
  -d '{ "model": "claude-sonnet-5", "messages": [{ "role": "user", "content": "Hello" }] }'
```

The first command lists models; the second answers with `usage`, where `cost` is what that request was charged in USD. The request also shows in the console under Usage › Requests. Then open the tool: in Cursor, pick the model and send a message; behind the LiteLLM proxy, call the proxy's own `/v1/chat/completions` with its key.

Cursor's behaviour as its own documentation described it on November 17, 2026.

## Questions, answered

### What is OpenCheap's OpenAI-compatible base URL?

https://api.opencheap.si/v1. Use it exactly as written, ending in /v1: the SDK or tool adds /chat/completions itself.

### How do I use OpenCheap in Cursor?

Open Cursor Settings, then Models. Paste your OpenCheap key under OpenAI API Key, turn on Override OpenAI Base URL and paste https://api.opencheap.si/v1, then add a custom model named opencheap/ followed by the model id, for example opencheap/claude-sonnet-5, and pick it in the chat's model menu.

### How do I use OpenCheap with LiteLLM?

Call it as an OpenAI-compatible endpoint: model="openai/<model id>", api_base="https://api.opencheap.si/v1" and your OpenCheap key as api_key. In the LiteLLM proxy, put the same three values under litellm_params in config.yaml.

### Which environment variables do I need?

One: your key. The examples here read it from OPENCHEAP_API_KEY. Code built on the OpenAI SDK can instead set OPENAI_BASE_URL=https://api.opencheap.si/v1 and OPENAI_API_KEY to the OpenCheap key and switch with no code change.

### Why does Cursor say “Model name is not valid”?

Cursor keeps model names that start with claude- for its own Anthropic connection, so a plain claude-sonnet-5 never reaches your base URL. Add the model as opencheap/claude-sonnet-5: OpenCheap accepts opencheap/ in front of every model id.

### Why do I get 402 Payment Required with a list called accepts?

The request reached the API with no Authorization header, so it was treated as a call paid in USDC (x402) and the answer is that call's price. Send your key as a bearer token: Authorization: Bearer <key>.

### Does streaming work?

Yes. Set stream to true and the answer comes back as server-sent events in the shape OpenAI uses. Add stream_options with include_usage set to true, as with OpenAI, to get a last chunk with usage and what the request cost. Tool calls stream the same way.

## More guides

- [An LLM router that sends each request to the cheapest provider](https://opencheap.si/guides/cheapest-llm-router): OpenCheap routes each request to the cheapest healthy provider of your model, fails over before the first byte, and bills that provider's price.
- [One OpenAI-compatible API key for every model](https://opencheap.si/guides/openai-compatible-api): One OpenCheap key calls Anthropic, Google, OpenAI, DeepSeek, Moonshot, Qwen and more through the OpenAI SDK: change the base URL and the key.
- [Pay for LLM API calls with USDC, without an account or an API key](https://opencheap.si/guides/pay-for-llm-api-with-usdc): An AI agent can pay OpenCheap for one completion in USDC on Base with x402: call with no key, read the 402 price, sign, and get the answer in the same request.
- [Set a daily spend limit on each API key your agents use](https://opencheap.si/guides/llm-api-spend-limits): Give each OpenCheap key a daily, weekly, monthly or lifetime spend limit, so an agent left running overnight can't spend more than you allow.
- [OpenCheap vs OpenRouter for cheapest pricing and failover](https://opencheap.si/guides/opencheap-vs-openrouter): OpenCheap routes to the cheapest provider by default; OpenRouter balances price, speed and uptime. Compare live prices, failover and fees.
- [Run Claude Code for less](https://opencheap.si/guides/claude-code-cheaper): Point Claude Code at OpenCheap and pick a model per task: Claude at the provider's price, or open models for a fraction, on one key with a spend limit.

---

Source: https://opencheap.si/guides/cursor-litellm-openai-sdk · All models: https://opencheap.si/models · Prices as JSON: https://api.opencheap.si/v1/prices · Index for agents: https://opencheap.si/llms.txt
