# Switch the OpenAI SDK to open-weight models in three changes

> Point the OpenAI SDK at open-weight models such as DeepSeek, Qwen and gpt-oss by changing the base URL, the key and the model name. Python, Node.js and curl.

- URL: https://llmwithcrypto.com/guides/switch-openai-sdk-to-open-models/
- Last updated: 2026-10-23
- Publisher: LLMwithCrypto (https://llmwithcrypto.com)

If your code already calls OpenAI through its SDK, moving a workload to an open-weight model is a configuration change, not a rewrite. This guide shows the three values to change, which of our models to try for which job, and what behaves differently.

**Quick answer — How do I use the OpenAI SDK with open-weight models?**

Change three values: the base URL, the API key and the model name. With **LLMwithCrypto**, set the base URL to `https://llmwithcrypto.com/api/v1`, use a key from your dashboard and pick a model id such as `deepseek-v4-pro` or `gpt-oss-120b`. As of 23 October 2026, DeepSeek V4 Pro costs $1.254 per million input tokens. The rest of your code stays the same.

## What are the three changes?

1. **Base URL** — Point the client at https://llmwithcrypto.com/api/v1 instead of OpenAI. Both the Python and the Node.js SDK accept a base_url / baseURL option, and read the OPENAI_BASE_URL environment variable.
2. **API key** — Create a key in your dashboard and keep it in LLMWITHCRYPTO_API_KEY. Pass your API key as a Bearer token in the Authorization header, as the OpenAI SDK does.
3. **Model name** — Replace gpt-… with one of our ids, for example deepseek-v4-pro. GET https://llmwithcrypto.com/api/v1/models lists every id your key can call.

*switch.py*

```python
import os

from openai import OpenAI

client = OpenAI(
    base_url="https://llmwithcrypto.com/api/v1",
    api_key=os.environ["LLMWITHCRYPTO_API_KEY"],
)

reply = client.chat.completions.create(
    model="deepseek-v4-pro",
    messages=[{"role": "user", "content": "Summarise this changelog in three bullet points: ..."}],
)
print(reply.choices[0].message.content)
print(reply.usage)

```

*switch.mjs*

```javascript
import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://llmwithcrypto.com/api/v1',
  apiKey: process.env.LLMWITHCRYPTO_API_KEY,
});

const reply = await client.chat.completions.create({
  model: 'gpt-oss-120b',
  messages: [{ role: 'user', content: 'Write a regex that matches ISO 8601 dates.' }],
});
console.log(reply.choices[0].message.content);

```

## Which open model should I try for which job?

A starting point by job, from what each model's maker built it for. Test on your own prompts before you switch: no model is a drop-in copy of another. Prices per 1M input / output tokens, as of 23 October 2026.

| Job | Model to try | API id | Context | Price (in / out) |
| --- | --- | --- | --- | --- |
| General chat, reasoning and code | [DeepSeek V4 Pro](https://llmwithcrypto.com/models/deepseek-v4-pro/) | `deepseek-v4-pro` | 1M | $1.254 / $3.762 |
| High-volume, low-cost calls | [DeepSeek V4.1 Flash](https://llmwithcrypto.com/models/deepseek-v4-1-flash/) | `deepseek-v4.1-flash` | 1M | $0.285 / $1.14 |
| Reasoning and tool use | [gpt-oss-120b](https://llmwithcrypto.com/models/gpt-oss-120b/) | `gpt-oss-120b` | 128K | $0.142 / $0.57 |
| Small, fast reasoning | [gpt-oss-20b](https://llmwithcrypto.com/models/gpt-oss-20b/) | `gpt-oss-20b` | 128K | $0.033 / $0.161 |
| Coding and agents | [GLM-4.7](https://llmwithcrypto.com/models/glm-4-7/) | `glm-4.7` | 200K | $0.57 / $2.09 |
| Multilingual chat and long documents | [Qwen3 235B A22B Instruct](https://llmwithcrypto.com/models/qwen3-235b-a22b-instruct-2507/) | `qwen3-235b-a22b-instruct-2507` | 256K | $0.161 / $0.57 |
| Step-by-step reasoning | [DeepSeek R1](https://llmwithcrypto.com/models/deepseek-r1/) | `deepseek-r1` | 160K | $0.57 / $2.208 |
| A European model | [Mistral Large 3](https://llmwithcrypto.com/models/mistral-large-3/) | `mistral-large-3` | 256K | $0.475 / $1.424 |

*Prices checked on October 23, 2026.*

The [models page](https://llmwithcrypto.com/models/) lists all twelve, with their licences.

## What behaves differently after the switch?

- **Token counts.** You pay per token from your balance: input and output tokens are counted by the model’s own tokenizer and charged at that model’s price per 1M tokens. A call that ends in an error costs nothing. Each model has its own tokenizer, so the same text can count as a different number of tokens than on OpenAI.
- **Features per model.** Streaming works on every model; tool calling and JSON output follow what each model itself supports. Check the [models page](https://llmwithcrypto.com/models/) before you rely on tool calling or JSON output.
- **Output style and quality.** Different models answer differently. Run your own test prompts, especially for structured output.
- **Closed-model features.** OpenAI-only endpoints and models are not available here. We do not sell access to GPT, Claude, Gemini or Grok: their makers forbid reselling API access without their approval, and we do not have it.

## Why do teams move workloads to open models?

Mostly for price and control. Open-weight models are served by many hosts, and the median price of DeepSeek V4 Pro across 7 hosts was $1.32 per million input tokens on 23 October 2026. Usage follows: in the week to 21 October 2026, DeepSeek V4.1 Flash was the most-used model on OpenRouter's public rankings.

With **LLMwithCrypto** you can also pay without a card: BTC, USDT, USDC, ETH, SOL, LTC, from a $25 top-up, with no KYC.

## Switching from OpenAI: common questions

### Does streaming still work?

Yes, with `stream: true`, as with OpenAI. The [streaming docs](https://llmwithcrypto.com/docs/streaming/) show the event format.

### Do I need a new SDK?

No. The official OpenAI SDKs work; only the base URL, the key and the model name change. LangChain works the same way, see the [LangChain docs](https://llmwithcrypto.com/docs/langchain/).

### Can I keep GPT for some calls?

Yes, by keeping a second client pointed at OpenAI with your OpenAI key. We do not sell GPT models.

### How do I check what a call cost?

Each response carries a `usage` object with input and output tokens; the dashboard shows the cost of every call, and `GET https://llmwithcrypto.com/api/v1/credits` returns what is left.

## Sources

1. [OpenRouter rankings](https://openrouter.ai/rankings) — OpenRouter (read 2026-10-23)

---

LLMwithCrypto: LLMwithCrypto is an OpenAI-compatible LLM API for open-weight models — DeepSeek V4 Pro, DeepSeek V4.1 Flash, DeepSeek R1, Qwen3.5 397B A17B, Qwen3 235B A22B Instruct, gpt-oss-120b, gpt-oss-20b, GLM-4.7, Llama 3.3 70B Instruct, Gemma 4 31B, Mistral Large 3, Mistral Small 4 — paid per token from a prepaid crypto balance, at 5% below the median price of the public hosts. No KYC: no ID, no selfie, no documents. Prompts and outputs are not stored.
