API documentation
/model speaks the OpenAI and Anthropic APIs. Point the SDK or tool you already use at our base URL, use one of your API keys, and pick any model from the price list.
Quick start
- Create an account and top up your balance.
- Create an API key on the API keys page. The key is shown only once, so store it somewhere safe. A new key routes Cheapest first; you can choose Stable first or your own channels instead (see Routing).
- Set the base URL below in your client, use your key, and send a request.
Base URL for OpenAI SDKs
https://api.slashmodel.com/v1Base URL for Anthropic SDKs and Claude Code
https://api.slashmodel.comAuthentication
Every request needs an API key, except the model list and the price list. Keys look like sk-sm-…. Send yours in either of these headers:
Authorization: Bearer sk-sm-…
# or
x-api-key: sk-sm-…Keep keys secret: anyone with a key can spend your balance. Use a separate key for each app, limit it with its settings, and revoke it on the API keys page if it leaks.
Key settings
Each key has its own settings. Set them when you create a key on the API keys page, or change them there later: changes apply from the key's next request.
| Setting | What it does | When it refuses a request |
|---|---|---|
| Routing | Cheapest first (the default), Stable first, or My channels: only the channels you tick. See Routing. | With My channels, a model none of the key's channels serves: 403 model_not_allowed. |
| Spending caps | A daily and a monthly limit in USD. The daily limit resets at 00:00 UTC, the monthly one at 00:00 UTC on the 1st. | 402 key_limit_reached. Close to the limit, max_tokens is lowered to what's left first. |
| Maximum prices | The most the key pays per 1M input tokens and per 1M output tokens. Channels priced above it are skipped. A request's own provider.max_price applies too: the lower one counts. Image models bill per image, so these limits don't apply to them. | When every channel is above it: 503 with x-should-retry: false. |
| Allowed IP addresses | The IPv4 and IPv6 addresses and CIDR ranges the key works from, up to 50. Empty: any address. | 403 ip_not_allowed. The message names the address the request came from. |
| Models | All models, including ones we add later, or only the ones you choose. | 403 model_not_allowed. |
| Expiry | The key stops working at the end of the day you pick, in your time zone. Never, by default. | 401 invalid_api_key. |
| Disable or revoke | A disabled key stops working until you enable it again. A revoked key stops for good. | 401 invalid_api_key. |
Endpoints
| Endpoint | What it does |
|---|---|
| POST/v1/chat/completions | OpenAI Chat Completions format. Serves every chat model. |
| POST/v1/responses | OpenAI Responses format. Serves the GPT models. |
| POST/v1/messages | Anthropic Messages format. Serves Claude models from Claude 4 on, and GLM 5 models. |
| POST/v1/messages/count_tokens | Counts a request's input tokens: exact for GPT models, an estimate for the others. |
| POST/v1/embeddings | Embeddings for text, in the OpenAI format. |
| POST/v1/images/generations | Makes an image from a prompt, in the OpenAI format. |
| GET/v1/models | The models you can use now, with their prices and channels. Add a model id to the path to get one model. No key needed. |
| GET/v1/credits | Your balance: the total, the amount held for requests in progress, and what is available. |
| GET/v1/channels | The price table: every model's channels, each with its prices, whether it is Stable or Best effort, and its last 24 hours. No key needed. |
OpenAI SDK
Set base_url to the base URL with /v1, and api_key to your key. The rest of your code stays the same.
pip install openainpm install openaiimport os
from openai import OpenAI
client = OpenAI(
base_url="https://api.slashmodel.com/v1",
api_key=os.environ["SLASHMODEL_API_KEY"],
)
response = client.chat.completions.create(
model="gpt-6.1-sol",
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.slashmodel.com/v1",
apiKey: process.env.SLASHMODEL_API_KEY,
});
const response = await client.chat.completions.create({
model: "gpt-6.1-sol",
messages: [{ role: "user", content: "Hello!" }],
});
console.log(response.choices[0].message.content);Any OpenAI-compatible client or framework works the same way, in any language: set its base URL and API key.
Setup guides for Claude Code, Cursor, Cline, Zed, LangChain and other tools are under Guides.
Responses API
GPT models also answer on OpenAI's Responses API, POST /v1/responses, with the same base URL and key. Some tools and libraries speak only this API. Claude, Gemini and Grok models are not on it: asked for here, they answer 404 model_not_found with the endpoints to use instead.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.slashmodel.com/v1",
api_key=os.environ["SLASHMODEL_API_KEY"],
)
response = client.responses.create(
model="gpt-6.1-sol",
instructions="You are a concise assistant.",
input="Hello!",
)
print(response.output_text)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.slashmodel.com/v1",
apiKey: process.env.SLASHMODEL_API_KEY,
});
const response = await client.responses.create({
model: "gpt-6.1-sol",
instructions: "You are a concise assistant.",
input: "Hello!",
});
console.log(response.output_text);curl https://api.slashmodel.com/v1/responses \
-H "Authorization: Bearer $SLASHMODEL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6.1-sol",
"instructions": "You are a concise assistant.",
"input": "Hello!"
}'Responses are not stored. Send the whole conversation in input on every turn: your messages, and the output items of the earlier answers as they came. previous_response_id, conversation, background and stored prompts answer 400 unsupported_parameter, and a response can't be fetched, cancelled or deleted by its id.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.slashmodel.com/v1",
api_key=os.environ["SLASHMODEL_API_KEY"],
)
conversation = [{"role": "user", "content": "My name is Maria."}]
first = client.responses.create(model="gpt-6.1-sol", input=conversation)
# The answer's output items go back as they came, then the next message.
conversation += first.output
conversation.append({"role": "user", "content": "What is my name?"})
second = client.responses.create(model="gpt-6.1-sol", input=conversation)
print(second.output_text)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.slashmodel.com/v1",
apiKey: process.env.SLASHMODEL_API_KEY,
});
const conversation = [{ role: "user", content: "My name is Maria." }];
const first = await client.responses.create({ model: "gpt-6.1-sol", input: conversation });
// The answer's output items go back as they came, then the next message.
conversation.push(...first.output, { role: "user", content: "What is my name?" });
const second = await client.responses.create({ model: "gpt-6.1-sol", input: conversation });
console.log(second.output_text);Function tools, images in the input, reasoning settings and JSON output (text.format) work as at OpenAI. To carry a model's reasoning into the next turn, add reasoning.encrypted_content to include and send the reasoning items back with the rest of the output.
With "stream": true the answer arrives as the API's own events, from response.created to response.completed, whose response carries the usage. When nothing has been sent for 15 seconds, the stream gets a : keep-alive comment line, which the SDKs skip. A stream that breaks after it has started ends with an error event, code stream_interrupted, and you pay only for what was delivered. See Errors.
A request is billed per token at the channel's prices, like a chat completion. As at OpenAI, usage.input_tokens includes the cached tokens, which usage.input_tokens_details.cached_tokens counts.
Anthropic SDK
Set base_url to the base URL without /v1, because the SDK adds the path itself. The Messages API serves Claude models from Claude 4 on and GLM 5 models, and any anthropic-version header is accepted.
pip install anthropicnpm install @anthropic-ai/sdkimport os
import anthropic
client = anthropic.Anthropic(
base_url="https://api.slashmodel.com",
api_key=os.environ["SLASHMODEL_API_KEY"],
)
message = client.messages.create(
model="claude-sonnet-5-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}],
)
# Claude may think before it answers: print the text blocks, not content[0].
for block in message.content:
if block.type == "text":
print(block.text)import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://api.slashmodel.com",
apiKey: process.env.SLASHMODEL_API_KEY,
});
const message = await client.messages.create({
model: "claude-sonnet-5-5",
max_tokens: 1024,
messages: [{ role: "user", content: "Hello!" }],
});
// Claude may think before it answers: print the text blocks, not content[0].
for (const block of message.content) {
if (block.type === "text") console.log(block.text);
}Recent Claude models can think before they answer, even when the request doesn't ask them to, so a response may start with a thinking block whose text is empty. Read the text blocks, as above, rather than content[0].text. See Thinking.
curl
An OpenAI-format request, with the key in the Authorization header:
curl https://api.slashmodel.com/v1/chat/completions \
-H "Authorization: Bearer $SLASHMODEL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6.1-sol",
"messages": [{"role": "user", "content": "Hello!"}]
}'An Anthropic-format request, with the key in x-api-key:
curl https://api.slashmodel.com/v1/messages \
-H "x-api-key: $SLASHMODEL_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello!"}]
}'Claude Code
Claude Code reads its base URL and key from the environment. Its model names, including the [1m] ones, work as they are.
export ANTHROPIC_BASE_URL="https://api.slashmodel.com"
export ANTHROPIC_AUTH_TOKEN="$SLASHMODEL_API_KEY"
claudeSome channels take requests only from Claude Code: the CLI (claude -p included), the desktop app and the VS Code extension. They are Stable, backed by the provider's service level agreement. Give Claude Code a key set to Stable first to use them first; if they fail, its requests move on to Best effort channels. Other apps never use these channels.
Models
The pricing page lists every model with its id and prices, and so does Models once you sign in, with a button to copy each id. GET /v1/models returns the models you can use right now, with their prices, and needs no key.
curl https://api.slashmodel.com/v1/models \
-H "Authorization: Bearer $SLASHMODEL_API_KEY"Use the model id as shown, such as claude-opus-5-5. OpenRouter-style ids such as anthropic/claude-opus-5.5 work too, with dots or dashes.
/v1/chat/completions serves every chat model. /v1/messages serves Claude models from Claude 4 on, and GLM 5 models. /v1/responses serves the GPT models. Embedding models are on /v1/embeddings and image models on /v1/images/generations. In GET /v1/models, each model's endpoints lists the ones it takes.
On the pricing page and in GET /v1/channels, a maker's latest models always show, marked unavailable while none of their channels answers. Older models show only while a channel answers them.
Streaming
Both endpoints answer either way. With "stream": true the answer arrives as server-sent events, the same events OpenAI and Anthropic send. Without it, or with false, you get one JSON answer once the model has finished. Tool calls, thinking and usage work in both.
OpenAI format: /v1/chat/completions
The stream reports usage only if you ask for it, as at OpenAI: set stream_options.include_usage to true, and the last chunk before [DONE] carries it.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.slashmodel.com/v1",
api_key=os.environ["SLASHMODEL_API_KEY"],
)
stream = client.chat.completions.create(
model="gpt-6.1-sol",
messages=[{"role": "user", "content": "Hello!"}],
stream=True,
stream_options={"include_usage": True},
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
if chunk.usage:
print("\n", chunk.usage)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.slashmodel.com/v1",
apiKey: process.env.SLASHMODEL_API_KEY,
});
const stream = await client.chat.completions.create({
model: "gpt-6.1-sol",
messages: [{ role: "user", content: "Hello!" }],
stream: true,
stream_options: { include_usage: true },
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
if (chunk.usage) console.log("\n", chunk.usage);
}curl https://api.slashmodel.com/v1/chat/completions -N \
-H "Authorization: Bearer $SLASHMODEL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6.1-sol",
"messages": [{"role": "user", "content": "Hello!"}],
"stream": true,
"stream_options": {"include_usage": true}
}'Anthropic format: /v1/messages
Usage comes in the message_start and message_delta events, as at Anthropic. The SDK's stream helper gives you the text as it arrives and the whole message at the end.
import os
import anthropic
client = anthropic.Anthropic(
base_url="https://api.slashmodel.com",
api_key=os.environ["SLASHMODEL_API_KEY"],
)
with client.messages.stream(
model="claude-sonnet-5-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}],
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)
print("\n", stream.get_final_message().usage)import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://api.slashmodel.com",
apiKey: process.env.SLASHMODEL_API_KEY,
});
const stream = client.messages.stream({
model: "claude-sonnet-5-5",
max_tokens: 1024,
messages: [{ role: "user", content: "Hello!" }],
});
stream.on("text", (text) => process.stdout.write(text));
const message = await stream.finalMessage();
console.log("\n", message.usage);curl https://api.slashmodel.com/v1/messages -N \
-H "x-api-key: $SLASHMODEL_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello!"}],
"stream": true
}'When nothing has been sent for 15 seconds, for example while a model thinks before its first token, a stream gets a keep-alive: the comment line : keep-alive on /v1/chat/completions, a ping event on /v1/messages. The SDKs skip both. If you read the stream yourself, ignore lines that start with : and ping events.
Stream for chat interfaces and long answers. A non-streaming request gets nothing back until the whole answer is ready, so its client timeout must be longer than the answer takes (see Limits and timeouts). Only non-streaming responses give the charge in x-sm-cost-usd; a stream's charge shows under Usage.
If a stream breaks after it has started, it ends with a stream_interrupted error event, and you pay only for what was delivered. See Errors.
Tool calls
Describe your functions in tools, and the model can ask to call one: instead of text, it answers with the function's name and arguments. You run the function, send its result back, and the model answers with it. The model never runs anything itself. GPT and Claude models take tools in the OpenAI format, and Claude also in the Anthropic format.
OpenAI format: /v1/chat/completions
The calls arrive in message.tool_calls, and finish_reason is tool_calls. Add the assistant message to the conversation, then one tool message per call with its tool_call_id, and send the request again.
import json
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.slashmodel.com/v1",
api_key=os.environ["SLASHMODEL_API_KEY"],
)
def get_weather(city): # your function
return {"city": city, "temp_c": 18, "sky": "clear"}
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Current weather in a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
},
}]
messages = [{"role": "user", "content": "What is the weather in Paris?"}]
response = client.chat.completions.create(model="gpt-6.1-sol", messages=messages, tools=tools)
message = response.choices[0].message
if message.tool_calls:
messages.append(message)
for call in message.tool_calls:
result = get_weather(**json.loads(call.function.arguments))
messages.append({"role": "tool", "tool_call_id": call.id, "content": json.dumps(result)})
response = client.chat.completions.create(model="gpt-6.1-sol", messages=messages, tools=tools)
print(response.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.slashmodel.com/v1",
apiKey: process.env.SLASHMODEL_API_KEY,
});
const getWeather = ({ city }) => ({ city, temp_c: 18, sky: "clear" }); // your function
const tools = [{
type: "function",
function: {
name: "get_weather",
description: "Current weather in a city",
parameters: {
type: "object",
properties: { city: { type: "string" } },
required: ["city"],
},
},
}];
const messages = [{ role: "user", content: "What is the weather in Paris?" }];
let response = await client.chat.completions.create({ model: "gpt-6.1-sol", messages, tools });
const message = response.choices[0].message;
if (message.tool_calls?.length) {
messages.push(message);
for (const call of message.tool_calls) {
const result = getWeather(JSON.parse(call.function.arguments));
messages.push({ role: "tool", tool_call_id: call.id, content: JSON.stringify(result) });
}
response = await client.chat.completions.create({ model: "gpt-6.1-sol", messages, tools });
}
console.log(response.choices[0].message.content);curl https://api.slashmodel.com/v1/chat/completions \
-H "Authorization: Bearer $SLASHMODEL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6.1-sol",
"messages": [{"role": "user", "content": "What is the weather in Paris?"}],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Current weather in a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}
}]
}'Anthropic format: /v1/messages
The calls arrive as tool_use blocks, and stop_reason is tool_use. Add Claude's whole answer to the conversation unchanged, thinking blocks included, then a user message with a tool_result block per call, and send the request again.
import json
import os
import anthropic
client = anthropic.Anthropic(
base_url="https://api.slashmodel.com",
api_key=os.environ["SLASHMODEL_API_KEY"],
)
def get_weather(city): # your function
return {"city": city, "temp_c": 18, "sky": "clear"}
tools = [{
"name": "get_weather",
"description": "Current weather in a city",
"input_schema": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
}]
messages = [{"role": "user", "content": "What is the weather in Paris?"}]
message = client.messages.create(
model="claude-sonnet-5-5", max_tokens=1024, messages=messages, tools=tools,
)
if message.stop_reason == "tool_use":
# Send the whole answer back, thinking blocks included, then one result for each call.
messages.append({"role": "assistant", "content": message.content})
results = []
for block in message.content:
if block.type == "tool_use":
result = json.dumps(get_weather(**block.input))
results.append({"type": "tool_result", "tool_use_id": block.id, "content": result})
messages.append({"role": "user", "content": results})
message = client.messages.create(
model="claude-sonnet-5-5", max_tokens=1024, messages=messages, tools=tools,
)
for block in message.content:
if block.type == "text":
print(block.text)import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://api.slashmodel.com",
apiKey: process.env.SLASHMODEL_API_KEY,
});
const getWeather = ({ city }) => ({ city, temp_c: 18, sky: "clear" }); // your function
const tools = [{
name: "get_weather",
description: "Current weather in a city",
input_schema: {
type: "object",
properties: { city: { type: "string" } },
required: ["city"],
},
}];
const messages = [{ role: "user", content: "What is the weather in Paris?" }];
const ask = () =>
client.messages.create({ model: "claude-sonnet-5-5", max_tokens: 1024, messages, tools });
let message = await ask();
if (message.stop_reason === "tool_use") {
// Send the whole answer back, thinking blocks included, then one result for each call.
messages.push({ role: "assistant", content: message.content });
const results = [];
for (const block of message.content) {
if (block.type !== "tool_use") continue;
const result = getWeather(block.input);
results.push({ type: "tool_result", tool_use_id: block.id, content: JSON.stringify(result) });
}
messages.push({ role: "user", content: results });
message = await ask();
}
for (const block of message.content) {
if (block.type === "text") console.log(block.text);
}curl https://api.slashmodel.com/v1/messages \
-H "x-api-key: $SLASHMODEL_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "What is the weather in Paris?"}],
"tools": [{
"name": "get_weather",
"description": "Current weather in a city",
"input_schema": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}]
}'Images
GPT and Claude models read images sent with the text. An image counts as input tokens, more for a bigger image.
OpenAI format: /v1/chat/completions
Add an image_url part with the image's URL, or with the image itself as a data URL: data:image/png;base64, followed by the base64 data. A URL must be public and point straight at the image file. If the image can't be downloaded, for example because it needs a login, the request fails with a 400 invalid_request, so send such images as data URLs.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.slashmodel.com/v1",
api_key=os.environ["SLASHMODEL_API_KEY"],
)
response = client.chat.completions.create(
model="gpt-6.1-sol",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "What is in this image?"},
{"type": "image_url", "image_url": {"url": "https://slashmodel.com/icon-512.png"}},
],
}],
)
print(response.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.slashmodel.com/v1",
apiKey: process.env.SLASHMODEL_API_KEY,
});
const response = await client.chat.completions.create({
model: "gpt-6.1-sol",
messages: [{
role: "user",
content: [
{ type: "text", text: "What is in this image?" },
{ type: "image_url", image_url: { url: "https://slashmodel.com/icon-512.png" } },
],
}],
});
console.log(response.choices[0].message.content);curl https://api.slashmodel.com/v1/chat/completions \
-H "Authorization: Bearer $SLASHMODEL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6.1-sol",
"messages": [{"role": "user", "content": [
{"type": "text", "text": "What is in this image?"},
{"type": "image_url", "image_url": {"url": "https://slashmodel.com/icon-512.png"}}
]}]
}'Anthropic format: /v1/messages
Send the image itself, base64-encoded, in an image block. Images and documents given as a URL don't work on this endpoint: the request is refused with a 400.
import base64
import os
import anthropic
client = anthropic.Anthropic(
base_url="https://api.slashmodel.com",
api_key=os.environ["SLASHMODEL_API_KEY"],
)
with open("photo.png", "rb") as f:
data = base64.standard_b64encode(f.read()).decode()
image = {"type": "base64", "media_type": "image/png", "data": data}
message = client.messages.create(
model="claude-sonnet-5-5",
max_tokens=1024,
messages=[{
"role": "user",
"content": [
{"type": "image", "source": image},
{"type": "text", "text": "What is in this image?"},
],
}],
)
for block in message.content:
if block.type == "text":
print(block.text)import { readFileSync } from "node:fs";
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://api.slashmodel.com",
apiKey: process.env.SLASHMODEL_API_KEY,
});
const data = readFileSync("photo.png").toString("base64");
const image = { type: "base64", media_type: "image/png", data };
const message = await client.messages.create({
model: "claude-sonnet-5-5",
max_tokens: 1024,
messages: [{
role: "user",
content: [
{ type: "image", source: image },
{ type: "text", text: "What is in this image?" },
],
}],
});
for (const block of message.content) {
if (block.type === "text") console.log(block.text);
}IMAGE=$(base64 < photo.png | tr -d '\n')
curl https://api.slashmodel.com/v1/messages \
-H "x-api-key: $SLASHMODEL_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": [
{"type": "image", "source": {
"type": "base64", "media_type": "image/png", "data": "'"$IMAGE"'"
}},
{"type": "text", "text": "What is in this image?"}
]}]
}'JSON output
Give the model a JSON schema, and it answers with JSON that matches it, with no text around it, ready to parse.
OpenAI format: /v1/chat/completions
For GPT models, set response_format to type json_schema with your schema, as below, or to type json_object for JSON of any shape. Claude models ignore response_format: use the Anthropic format for them.
import json
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.slashmodel.com/v1",
api_key=os.environ["SLASHMODEL_API_KEY"],
)
schema = {
"type": "object",
"properties": {"name": {"type": "string"}, "age": {"type": "integer"}},
"required": ["name", "age"],
"additionalProperties": False,
}
response = client.chat.completions.create(
model="gpt-6.1-sol",
messages=[{"role": "user", "content": "Ada Lovelace died at 36. Give her name and age."}],
response_format={
"type": "json_schema",
"json_schema": {"name": "person", "strict": True, "schema": schema},
},
)
person = json.loads(response.choices[0].message.content)
print(person["name"], person["age"])import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.slashmodel.com/v1",
apiKey: process.env.SLASHMODEL_API_KEY,
});
const schema = {
type: "object",
properties: { name: { type: "string" }, age: { type: "integer" } },
required: ["name", "age"],
additionalProperties: false,
};
const response = await client.chat.completions.create({
model: "gpt-6.1-sol",
messages: [{ role: "user", content: "Ada Lovelace died at 36. Give her name and age." }],
response_format: { type: "json_schema", json_schema: { name: "person", strict: true, schema } },
});
const person = JSON.parse(response.choices[0].message.content);
console.log(person.name, person.age);curl https://api.slashmodel.com/v1/chat/completions \
-H "Authorization: Bearer $SLASHMODEL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6.1-sol",
"messages": [{"role": "user", "content": "Ada Lovelace died at 36. Give her name and age."}],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "person",
"strict": true,
"schema": {
"type": "object",
"properties": {"name": {"type": "string"}, "age": {"type": "integer"}},
"required": ["name", "age"],
"additionalProperties": false
}
}
}
}'Anthropic format: /v1/messages
For Claude, set output_config.format to type json_schema with your schema. The JSON is the answer's text.
import json
import os
import anthropic
client = anthropic.Anthropic(
base_url="https://api.slashmodel.com",
api_key=os.environ["SLASHMODEL_API_KEY"],
)
schema = {
"type": "object",
"properties": {"name": {"type": "string"}, "age": {"type": "integer"}},
"required": ["name", "age"],
"additionalProperties": False,
}
message = client.messages.create(
model="claude-sonnet-5-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Ada Lovelace died at 36. Give her name and age."}],
output_config={"format": {"type": "json_schema", "schema": schema}},
)
person = json.loads("".join(block.text for block in message.content if block.type == "text"))
print(person["name"], person["age"])import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://api.slashmodel.com",
apiKey: process.env.SLASHMODEL_API_KEY,
});
const schema = {
type: "object",
properties: { name: { type: "string" }, age: { type: "integer" } },
required: ["name", "age"],
additionalProperties: false,
};
const message = await client.messages.create({
model: "claude-sonnet-5-5",
max_tokens: 1024,
messages: [{ role: "user", content: "Ada Lovelace died at 36. Give her name and age." }],
output_config: { format: { type: "json_schema", schema } },
});
const text = message.content
.filter((block) => block.type === "text")
.map((block) => block.text)
.join("");
const person = JSON.parse(text);
console.log(person.name, person.age);curl https://api.slashmodel.com/v1/messages \
-H "x-api-key: $SLASHMODEL_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Ada Lovelace died at 36. Give her name and age."}],
"output_config": {
"format": {
"type": "json_schema",
"schema": {
"type": "object",
"properties": {"name": {"type": "string"}, "age": {"type": "integer"}},
"required": ["name", "age"],
"additionalProperties": false
}
}
}
}'Thinking
Claude models think before they answer when a question calls for it. On /v1/messages, output_config.effort sets how hard they try: low, medium, high, xhigh or max. More effort means more thinking on hard questions, and more output tokens.
import os
import anthropic
client = anthropic.Anthropic(
base_url="https://api.slashmodel.com",
api_key=os.environ["SLASHMODEL_API_KEY"],
)
message = client.messages.create(
model="claude-sonnet-5-5",
max_tokens=16000, # room for the thinking as well as the answer
thinking={"type": "adaptive"},
output_config={"effort": "high"}, # low, medium, high, xhigh or max
messages=[{"role": "user", "content": "Is 3599 a prime number?"}],
)
for block in message.content:
if block.type == "text":
print(block.text)
print(message.usage.output_tokens, "output tokens, thinking included")import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://api.slashmodel.com",
apiKey: process.env.SLASHMODEL_API_KEY,
});
const message = await client.messages.create({
model: "claude-sonnet-5-5",
max_tokens: 16000, // room for the thinking as well as the answer
thinking: { type: "adaptive" },
output_config: { effort: "high" }, // low, medium, high, xhigh or max
messages: [{ role: "user", content: "Is 3599 a prime number?" }],
});
for (const block of message.content) {
if (block.type === "text") console.log(block.text);
}
console.log(message.usage.output_tokens, "output tokens, thinking included");curl https://api.slashmodel.com/v1/messages \
-H "x-api-key: $SLASHMODEL_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"max_tokens": 16000,
"thinking": {"type": "adaptive"},
"output_config": {"effort": "high"},
"messages": [{"role": "user", "content": "Is 3599 a prime number?"}]
}'Thinking is billed as output tokens and counts toward max_tokens, so leave room for it: a limit sized for the answer alone can cut the answer short.
Thinking blocks come back without their text, so read the answer from the text blocks. In a tool loop, send them back unchanged with the rest of Claude's answer.
On /v1/chat/completions, Claude decides how much to think by itself. Leave out reasoning_effort for Claude models there, because it is refused, and use /v1/messages to set the effort.
Prompt caching
When your requests start with the same long text, such as instructions, a document or tool definitions, Claude can keep that text in a cache. The next request reads it from the cache, which is faster, and cheaper than input on most channels. Each channel's cache prices are on the pricing page.
On /v1/messages, put cache_control on the last block of the part that repeats, as below. Everything before it, tools and system included, is cached with it. Or put one cache_control at the top level of the request, and the cache follows the conversation as it grows.
import os
import anthropic
client = anthropic.Anthropic(
base_url="https://api.slashmodel.com",
api_key=os.environ["SLASHMODEL_API_KEY"],
)
# The long part that stays the same from request to request.
with open("handbook.txt") as f:
handbook = f.read()
for question in ["How do I reset my password?", "Who do I call after hours?"]:
message = client.messages.create(
model="claude-sonnet-5-5",
max_tokens=1024,
system=[{"type": "text", "text": handbook, "cache_control": {"type": "ephemeral"}}],
messages=[{"role": "user", "content": question}],
)
usage = message.usage
print("written:", usage.cache_creation_input_tokens,
"read:", usage.cache_read_input_tokens,
"uncached:", usage.input_tokens)import { readFileSync } from "node:fs";
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://api.slashmodel.com",
apiKey: process.env.SLASHMODEL_API_KEY,
});
// The long part that stays the same from request to request.
const handbook = readFileSync("handbook.txt", "utf8");
for (const question of ["How do I reset my password?", "Who do I call after hours?"]) {
const message = await client.messages.create({
model: "claude-sonnet-5-5",
max_tokens: 1024,
system: [{ type: "text", text: handbook, cache_control: { type: "ephemeral" } }],
messages: [{ role: "user", content: question }],
});
const usage = message.usage;
console.log(
"written:", usage.cache_creation_input_tokens,
"read:", usage.cache_read_input_tokens,
"uncached:", usage.input_tokens,
);
}curl https://api.slashmodel.com/v1/messages \
-H "x-api-key: $SLASHMODEL_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"max_tokens": 1024,
"system": [{
"type": "text",
"text": "<your long instructions or document>",
"cache_control": {"type": "ephemeral"}
}],
"messages": [{"role": "user", "content": "How do I reset my password?"}]
}'The cached part must be the same, word for word, every time. A date or an id near the start makes each request new, and nothing is read from the cache.
An entry lasts 5 minutes from when it was last used. For an hour, add "ttl": "1h" to cache_control; writing it costs twice the channel's input price.
The usage shows the tokens written to the cache (cache_creation_input_tokens), the tokens read from it (cache_read_input_tokens), and the rest (input_tokens). On /v1/chat/completions, Claude caches long prompts that repeat without being asked, and prompt_tokens_details.cached_tokens shows the tokens read from the cache.
Embeddings
POST /v1/embeddings turns text into vectors, in the OpenAI format. Send the model and the input: a string, or a list of up to 2,048 strings or token lists, none of them empty. encoding_format can be float or base64; the OpenAI SDKs ask for base64 and decode it for you.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.slashmodel.com/v1",
api_key=os.environ["SLASHMODEL_API_KEY"],
)
response = client.embeddings.create(
model="text-embedding-3-small",
input=["The cat sat on the mat.","A dog slept by the door."],
)
for item in response.data:
print(item.index, len(item.embedding))
print("input tokens:", response.usage.prompt_tokens)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.slashmodel.com/v1",
apiKey: process.env.SLASHMODEL_API_KEY,
});
const response = await client.embeddings.create({
model: "text-embedding-3-small",
input: ["The cat sat on the mat.","A dog slept by the door."],
});
for (const item of response.data) console.log(item.index, item.embedding.length);
console.log("input tokens:", response.usage.prompt_tokens);curl https://api.slashmodel.com/v1/embeddings \
-H "Authorization: Bearer $SLASHMODEL_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "text-embedding-3-small", "input": ["The cat sat on the mat.","A dog slept by the door."]}'An embeddings request is billed for its input tokens at the channel's input price, and usage.prompt_tokens in the answer is the count. There is no output to bill. The embedding models and their prices are on the pricing page, under Type.
Image generation
POST /v1/images/generations makes an image from a text prompt, in the OpenAI format. Send the model and a prompt of up to 32,000 characters. Each request makes one image: leave out n or set it to 1, and send one request per image. Image requests don't stream.
import base64
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.slashmodel.com/v1",
api_key=os.environ["SLASHMODEL_API_KEY"],
)
result = client.images.generate(
model="gemini-2.5-flash-image",
prompt="A lighthouse on a cliff at dawn, in watercolor",
)
image = result.data[0]
if image.url:
print(image.url) # works for 24 hours
else:
with open("image.png", "wb") as f:
f.write(base64.b64decode(image.b64_json))import fs from "node:fs";
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.slashmodel.com/v1",
apiKey: process.env.SLASHMODEL_API_KEY,
});
const result = await client.images.generate({
model: "gemini-2.5-flash-image",
prompt: "A lighthouse on a cliff at dawn, in watercolor",
});
const image = result.data[0];
if (image.url) console.log(image.url); // works for 24 hours
else fs.writeFileSync("image.png", Buffer.from(image.b64_json, "base64"));curl https://api.slashmodel.com/v1/images/generations \
-H "Authorization: Bearer $SLASHMODEL_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "gemini-2.5-flash-image", "prompt": "A lighthouse on a cliff at dawn, in watercolor"}'The answer's data[0] holds the image as a link (url) or as base64 data (b64_json). response_format asks for one or the other, on models that offer both. A link is on our API's address, needs no key, and works for 24 hours, so save the image if you want to keep it.
Each image is billed at the channel's price per image. The prices on the pricing page are for one standard-size image (1024x1024). On a model whose maker charges more for bigger or HD images, such an image counts as two or three, as listed under the model's channels, and a size that isn't on the list is refused with invalid_value, which names the sizes it makes.
An image is billed once it's made, even if your app stops waiting: closing the connection doesn't cancel the request.
Routing
Most models are served over several channels, each with its own price, speed and success rate. Every channel is Stable, backed by the provider's service level agreement, or Best effort: cheaper, but it can slow down or stop without notice. A request tries up to 3 channels, in the order its key's routing sets. If a channel fails before it starts answering, the next one takes over, and you never see the failed attempt. You pay the prices of the channel that served the request.
| Strategy | Best for | Channel order | Per request |
|---|---|---|---|
| Smart (default) | A low price, without slow or failing channels | Channels that are doing well (a success rate of at least 95% and a median time to first token within 2× the fastest), cheapest first. Then the rest, by success rate. | smart · :auto |
| Price | The lowest cost | Cheapest first (input + output price), then by success rate. | price · :floor |
| Speed | A fast first token | Shortest median time to first token first. The value throughput sorts by tokens per second instead. | speed · :nitro |
| Success | Reliability | Highest success rate first. | success |
Each key routes in one of three ways, chosen on the API keys page. Cheapest first, the default, uses every channel. Stable first tries the stable channels before the best-effort ones. My channels uses only the channels ticked on the key, and refuses a model none of them serves. Within each, the key's strategy from the table above orders the channels (Smart unless you change it), and ties go to the cheaper channel. Some channels take requests from one app only, such as Claude Code; requests from other apps skip them.
To change the strategy for one request, send the x-sm-route header (smart, price, speed, throughput or success), or add a suffix to the model id, such as claude-opus-5-5:floor. The suffix :stable makes one request Stable first: the stable channels first, then the best-effort ones, each by success rate. OpenRouter's provider object works too, with our channel names: order, only, ignore, sort, allow_fallbacks and max_price.
curl https://api.slashmodel.com/v1/chat/completions \
-H "Authorization: Bearer $SLASHMODEL_API_KEY" \
-H "x-sm-route: speed" \
-H "Content-Type: application/json" \
-d '{"model": "gpt-6.1-sol", "messages": [{"role": "user", "content": "Hello!"}]}'To use one channel only, send its name in x-sm-channel; with My channels, it must be one of the key's channels. Responses name the channel that served them in the same header, and non-streaming responses give the charge in USD in x-sm-cost-usd.
Each channel's tags show on the pricing page and on each model's page. In GET /v1/channels and GET /v1/models, every channel has tier, which is stable or best_effort, and clients: null when it serves every app, or the only apps it serves, such as ["claude-code"].
{
"name": "gpt-d",
"available": true,
"per_million": { "input": 0.164, "output": 0.817, … },
"share_of_official": 0.082,
"tier": "stable",
"clients": null,
"last_24h": { "success_rate": 0.998, "ttft_ms": 1840, … }
}Limits and timeouts
Every account starts with these limits. To raise the rate limits, contact us.
| Limit | Value | What happens |
|---|---|---|
| Requests per minute | 300 per account, all its keys together | 429 rate_limit_exceeded. retry-after says how many seconds to wait, and the rate-limit headers show how many requests are left this minute. |
| Requests at once | 50 per account | 429 rate_limit_exceeded until one of them finishes. |
| Request size | 20 MB | 413 request_too_large. |
| Prompt and answer length | Each model's context_length and max_output_tokens, in GET /v1/models | A prompt that doesn't fit: 400 context_length_exceeded. |
| Waiting for the first token | 30 seconds a channel (90 for models that think first), 3 minutes in all | The next channel takes over, unseen. When no channel has started answering after 3 minutes: 504 timeout. |
| Silence in the middle of an answer | 60 seconds | A stream ends with a stream_interrupted error event, and you pay for what was delivered. A non-streaming request costs nothing: within its first 3 minutes the next channel takes over; after that, you get an error to retry. |
| A streamed answer | No time limit, as long as tokens keep coming | Keep-alives every 15 seconds hold the connection open while the model thinks. |
| A non-streaming answer | 15 minutes | Nothing comes back until the answer is complete, and the connection closes after 15 minutes. The OpenAI and Anthropic SDKs stop waiting after 10 minutes unless you set timeout, and the Anthropic SDK asks you to stream when max_tokens is large. Stream long answers. |
Errors
Errors use OpenAI's format on /v1/chat/completions and Anthropic's on /v1/messages, so each SDK raises its usual exceptions. The OpenAI format carries the code from the table below and, for a bad parameter, its name in param. The Anthropic format has only type and message: go by the status and the message. Every response, error or not, has a request id in x-request-id and request-id, and an error repeats it as request_id. Include it when you contact us.
{
"error": {
"message": "Missing API key. Send it as 'Authorization: Bearer <key>' or 'x-api-key: <key>'.",
"type": "invalid_request_error",
"param": null,
"code": "invalid_api_key",
"request_id": "req_…"
}
}{
"type": "error",
"error": {
"type": "authentication_error",
"message": "Missing API key. Send it as 'Authorization: Bearer <key>' or 'x-api-key: <key>'."
},
"request_id": "req_…"
}Once a stream has started, its status is already 200, so an error arrives as the stream's last event instead: a data: line with the error on /v1/chat/completions, an error event on /v1/messages.
| Status | Code, and type (OpenAI / Anthropic) | Meaning | What to do |
|---|---|---|---|
| 400 | invalid_jsoninvalid_request_error | The body is empty or isn't valid JSON. | Send the body as a JSON object. |
| 400 | invalid_requestinvalid_request_error | The request doesn't have the shape the endpoint expects, or the model rejected it as invalid. The message says what. | Fix the request as the message says. |
| 400 | invalid_valueinvalid_request_error | A parameter has the wrong type or value. param names it. | Fix that parameter. |
| 400 | missing_required_parameterinvalid_request_error | A required parameter, such as model or messages, is missing. param names it. | Add it. |
| 400 | unsupported_parameterinvalid_request_error | A parameter we don't support, such as logprobs or audio input. param names it. | Leave it out. |
| 400 | context_length_exceededinvalid_request_error | The prompt is too long for the model's context window. | Shorten the conversation, or pick a model with a larger context_length in GET /v1/models. |
| 400 | content_filterinvalid_request_error | The model's provider refused the content. | Change the prompt: the same request is refused again. |
| 401 | invalid_api_keyinvalid_request_error / authentication_error | The API key is missing or wrong, or the key is disabled, revoked or past its expiry date. | Check the key on the API keys page. |
| 402 | insufficient_quotainsufficient_quota / billing_error | Your balance is too low for this request. The message says how many output tokens it covers. | Top up on the credits page, or lower max_tokens. |
| 402 | key_limit_reachedinsufficient_quota / billing_error | The key has reached its daily or monthly cap. Close to the cap, a request is still served with max_tokens lowered to what's left, but not below 1,024 tokens. Below that it is refused, and the message says how many output tokens are left. | Lower max_tokens, raise the cap on the API keys page, or wait for the reset: daily caps at 00:00 UTC, monthly caps on the 1st. |
| 403 | account_suspendedpermission_error | Your account is suspended. | Contact us. |
| 403 | ip_not_allowedpermission_error | The key doesn't work from the IP address the request came from. The message names it. | Add the address to the key's allowed IP addresses, or send from an allowed one. |
| 403 | model_not_allowedpermission_error | The key can't use this model: the key is limited to other models, or it routes by My channels and none of its channels serves this model. | Change the key's settings on the API keys page, or use another key. |
| 403 | channel_not_allowedpermission_error | The channel you pinned isn't one of the key's channels, or the channels left serve one app only, such as Claude Code, and the request came from another app. | Pin another channel, leave the pin out, or set the key's routing to Cheapest first. |
| 404 | model_not_foundinvalid_request_error / not_found_error | There is no model with that id, or the model isn't served on this endpoint. The message names the endpoint that serves it. | Use an id from GET /v1/models, on an endpoint it lists. |
| 404 | not_foundinvalid_request_error / not_found_error | There is no endpoint at that path. | Check the base URL: with /v1 for OpenAI SDKs, without it for Anthropic SDKs. |
| 405 | method_not_allowedinvalid_request_error | The endpoint exists, but not with that HTTP method, such as GET on /v1/chat/completions. | Use the method listed under Endpoints. |
| 413 | request_too_largeinvalid_request_error / request_too_large | The request body is over 20 MB. | Send smaller images or files, or shorten the conversation. |
| 429 | rate_limit_exceededrate_limit_error | Your account sent more than 300 requests in the last minute, or already has 50 requests running. | Wait retry-after seconds; the SDKs do this for you. See Limits and timeouts. |
| 500 | server_errorserver_error / api_error | Something went wrong on our side. | Retry. If it keeps happening, contact us with the request id. |
| In a stream | stream_interruptedserver_error / api_error | The answer broke off after it had started. You pay only for what was delivered. | Retry the request for the whole answer. |
| 503 (529) | overloadedserver_error / overloaded_error | Every channel for the model is busy right now. | Retry after retry-after seconds. |
| 503 (529) | model_unavailableserver_error / overloaded_error | No channel can serve the model right now. When your own limits ruled out every channel (a pinned channel, My channels, a maximum price, only or ignore), x-should-retry is false. | Retry later, or loosen those limits. |
| 503 (529) | service_unavailableserver_error / overloaded_error | The model, or the service, is unavailable for a moment. | Retry after retry-after seconds. |
| 504 | timeoutserver_error / timeout_error | No channel started answering within 3 minutes. | Retry. The speed strategy (:nitro) tries the fastest channels first. |
Every error has x-should-retry, and 429 and 503 errors have retry-after too. The OpenAI and Anthropic SDKs follow both and retry 429 and 5xx errors by themselves. Don't retry a 4xx error unchanged: it fails the same way again.
Balance
GET /v1/credits returns your account's balance in USD. This endpoint is our own; it isn't part of the OpenAI or Anthropic APIs.
curl https://api.slashmodel.com/v1/credits \
-H "Authorization: Bearer $SLASHMODEL_API_KEY"{
"object": "credits",
"currency": "USD",
"balance": "12.500000",
"held": "0.020000",
"available": "12.480000"
}held is reserved for requests in progress: the most each one can cost, released when it finishes and is billed. available is what new requests can spend. Top up on the credits page, and see every charge under Usage.
Besides tokens: web search, Anthropic's server tool, is charged per search at the same discount as the channel's tokens (Anthropic's price is $10 per 1,000 searches), and one-hour cache writes cost twice the channel's input price, as at Anthropic. A call's cost can rise a few minutes after it ends if the provider bills it for more than we estimated, for example when a reply broke off before reporting its usage; Usage shows the final cost.