Disclosure: I'm Alex, and I run MartLLM, the endpoint in these examples. The base_url pattern works with any OpenAI-compatible gateway. The routing fields near the end are MartLLM's own.

Most LLM code in production is written against the OpenAI Python or TypeScript SDK, even when the model isn't OpenAI's. The SDK is good, the wire format is everywhere, and every framework (LangChain, LlamaIndex, LiteLLM, the Vercel AI SDK, Pydantic AI) can talk to it. So the cheapest way to try Claude, Gemini or DeepSeek in an existing codebase usually isn't a new SDK. It's a different base_url.

This post shows that swap against one endpoint that serves all of them, then covers the parts that don't carry over cleanly.

The swap

MartLLM implements the OpenAI Chat Completions API at https://api.martllm.com/v1. The OpenAI SDK guide puts it plainly: set base_url and api_key, and messages, tools, response_format, stream, max_tokens and temperature stay the same.

import os from openai import OpenAI client = OpenAI( base_url="https://api.martllm.com/v1", # the trailing /v1 is required api_key=os.environ["MARTLLM_API_KEY"], ) MODELS = [ "anthropic/claude-sonnet-5.5", "google/gemini-3.8-flash", "deepseek/deepseek-v4.1-flash", "z-ai/glm-5.3", "moonshotai/kimi-k3", ] for model in MODELS: resp = client.chat.completions.create( model=model, messages=[{"role": "user", "content": "In one sentence: what is a vector database?"}], max_tokens=120, ) u = resp.usage cost = getattr(u, "cost_usd", None) # MartLLM adds usage.cost_usd to every reply print(f"{resp.model:32} {u.prompt_tokens:>4} in {u.completion_tokens:>4} out ${cost}") print(" ", resp.choices[0].message.content.strip()[:160]) 

Five makers, one client, one loop. Model ids are maker/model. GET /v1/models returns the ones you can call right now, in the OpenAI list shape.

TypeScript is the same two settings:

import OpenAI from "openai"; const client = new OpenAI({ baseURL: "https://api.martllm.com/v1", apiKey: process.env.MARTLLM_API_KEY, }); const resp = await client.chat.completions.create({ model: "anthropic/claude-sonnet-5.5", messages: [{ role: "user", content: "Explain idempotency keys in two sentences." }], }); console.log(resp.choices[0].message.content); 

If your code uses the Anthropic SDK instead

The same endpoint also speaks Anthropic's Messages API. Note the base URL has no /v1 here, because the SDK adds /v1/messages itself:

from anthropic import Anthropic client = Anthropic(base_url="https://api.martllm.com", api_key=os.environ["MARTLLM_API_KEY"]) msg = client.messages.create( model="google/gemini-3.8-flash", # any catalog model, not only Claude max_tokens=256, messages=[{"role": "user", "content": "Say hello in one sentence."}], ) print(msg.content[0].text) 

The gateway translates between the two shapes, streaming included (Anthropic SDK guide). That's also how tools like Claude Code can run on non-Claude models.

What it costs: live prices for the five models

Read from the public catalog on 2026-11-28 at 03:51 UTC, per million tokens (input / output). "List" is the maker's official price. "Cheapest offer now" is the lowest live seller price at that moment. "Paid, last 7 days" is the average buyers were actually billed over the previous week, which is the more honest number for budgeting.

Model List Cheapest offer now Paid, last 7 days
anthropic/claude-sonnet-5.5 $2.00 / $10.00 $1.008 / $5.04 $1.07 / $5.37
google/gemini-3.8-flash $0.75 / $3.75 $0.126 / $0.63 $0.120 / $0.602
deepseek/deepseek-v4.1-flash $0.21 / $0.78 $0.1345 / $0.4996 $0.0208 / $0.0771
z-ai/glm-5.3 $1.40 / $4.40 $0.0243 / $0.0901 $0.0492 / $0.1827
moonshotai/kimi-k3 $3.00 / $15.00 $0.2764 / $1.4175 $0.1064 / $0.5457

Each request is sent to a third-party provider serving that model and billed what the provider charged, so the price moves with the market. The full board is at martllm.com/llm-api-pricing. If you need a hard ceiling, set one per request (below).

What carries over, and what doesn't

Carries over unchanged: messages, system prompts, stream, max_tokens, temperature, response_format, tool definitions. A reply that calls a tool always ends with finish_reason: "tool_calls", whichever provider served it. The reply shape is normalized too. You get the standard fields (id, model, choices, usage), and provider-specific extras are stripped, so code that parses resp.choices[0].message doesn't need per-model branches.

Needs care:

  1. Tool calls round-trip as received. Some providers attach extra data to a tool call. Gemini's thought signature arrives in an extra_content field, and the model needs it back on the next turn. If you rebuild tool-call messages by hand from only name and arguments, multi-step tool use on Gemini degrades. Append the assistant message you received as is.
  2. Reasoning text has two names. Reasoning models put their thinking in both reasoning and reasoning_content, with the same text, so a client that reads either works. Models that don't reason have neither field. Don't assume it exists.
  3. Modalities differ. Sending an image to a text-only model gets a clear 400 rather than a silent drop. Check input_modalities in GET /v1/models before you route pictures, audio or files to a model. Of the five models above, the catalog lists Claude Sonnet 5.5, Gemini 3.8 Flash, DeepSeek V4.1 Flash and Kimi K3 as taking images (Gemini also takes audio and video). GLM 5.3 is text only.
  4. Tuning knobs aren't universal. Fields that only tune the answer (top_k, verbosity, thinking and similar) are dropped for providers that refuse them instead of failing the call. If your evals depend on one of them, confirm the model supports it (supported_parameters in the model list).
  5. Stateful Responses API. client.responses.create works on every chat model. previous_response_id and stored conversations need saving turned on for the key. Otherwise send the full conversation each call.

Two request fields worth knowing

These are MartLLM extensions, passed through the OpenAI SDK's extra_body (details in models and routing):

resp = client.chat.completions.create( model="deepseek/deepseek-v4.1-flash", messages=[{"role": "user", "content": "Summarize this ticket: ..."}], extra_body={ # Tried in order only if nobody can serve the first model right now. "models": ["z-ai/glm-5.3", "google/gemini-3.8-flash"], # Never pay more than this per million tokens; refused (and free) if nobody sells that low. "provider": {"max_price": {"prompt": 0.5, "completion": 1.5}}, }, ) print(resp.model) # the model that actually answered 
  • models: fallbacks, at most 5 models in total. The next one is tried only when the one before has no available provider (or none within your price cap). A bad request or an empty balance is answered right away, not passed down the list.
  • provider.max_price: with both prompt and completion set, the request is never billed above those rates for the tokens it used. If no provider sells that low right now, you get 400 max_price_exceeded and pay nothing.

When this pattern is the wrong choice

One OpenAI-compatible key is a good fit when you want to compare models on your own prompts, keep one code path, and pay one prepaid balance. It's a worse fit when you need a maker's newest feature on day one, if it only exists in their native SDK, or when a contract requires you to buy from the maker directly. In those cases, keep the native SDK for that one model and route everything else through the shared client.

For everything in between, the change really is two lines.

Alex, CEO, MartLLM