Guides
SDKs
There is no Libremodel SDK to install. Point the OpenAI or Anthropic SDK you already use at Libremodel, with your key.
OpenAI SDK
Set the base URL to https://api.libremodel.ai/v1. Chat Completions, Responses and the model list work as they do with OpenAI.
curl https://api.libremodel.ai/v1/chat/completions \
-H "Authorization: Bearer $LIBREMODEL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash-1017",
"messages": [{"role": "user", "content": "Hello, Libremodel"}]
}'# pip install openai
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.libremodel.ai/v1",
api_key=os.environ["LIBREMODEL_API_KEY"],
)
response = client.chat.completions.create(
model="deepseek-v4.1-flash-1017",
messages=[{"role": "user", "content": "Hello, Libremodel"}],
)
print(response.choices[0].message.content)// npm install openai
import OpenAI from 'openai'
const client = new OpenAI({
baseURL: 'https://api.libremodel.ai/v1',
apiKey: process.env.LIBREMODEL_API_KEY,
})
const response = await client.chat.completions.create({
model: 'deepseek-v4.1-flash-1017',
messages: [{ role: 'user', content: 'Hello, Libremodel' }],
})
console.log(response.choices[0].message.content)The Responses API works the same way, with client.responses.create:
curl https://api.libremodel.ai/v1/responses \
-H "Authorization: Bearer $LIBREMODEL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash-1017",
"input": "Hello, Libremodel",
"reasoning": {"effort": "high"}
}'# pip install openai
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.libremodel.ai/v1",
api_key=os.environ["LIBREMODEL_API_KEY"],
)
response = client.responses.create(
model="deepseek-v4.1-flash-1017",
input="Hello, Libremodel",
reasoning={"effort": "high"},
)
print(response.output_text)// npm install openai
import OpenAI from 'openai'
const client = new OpenAI({
baseURL: 'https://api.libremodel.ai/v1',
apiKey: process.env.LIBREMODEL_API_KEY,
})
const response = await client.responses.create({
model: 'deepseek-v4.1-flash-1017',
input: 'Hello, Libremodel',
reasoning: { effort: 'high' },
})
console.log(response.output_text)Anthropic SDK
Set the base URL to https://api.libremodel.ai, without /v1: the SDK adds /v1/messages itself. It sends the key in x-api-key, and that works too.
curl https://api.libremodel.ai/v1/messages \
-H "x-api-key: $LIBREMODEL_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash-1017",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello, Libremodel"}]
}'# pip install anthropic
import os
from anthropic import Anthropic
client = Anthropic(
base_url="https://api.libremodel.ai",
api_key=os.environ["LIBREMODEL_API_KEY"],
)
message = client.messages.create(
model="deepseek-v4.1-flash-1017",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello, Libremodel"}],
)
print(message.content[0].text)// npm install @anthropic-ai/sdk
import Anthropic from '@anthropic-ai/sdk'
const client = new Anthropic({
baseURL: 'https://api.libremodel.ai',
apiKey: process.env.LIBREMODEL_API_KEY,
})
const message = await client.messages.create({
model: 'deepseek-v4.1-flash-1017',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello, Libremodel' }],
})
console.log(message.content)With thinking on, the first content block is thinking. Read the text blocks for the answer.
Other libraries
Any library or tool that talks to the OpenAI API and lets you change its base URL works the same way: base URL https://api.libremodel.ai/v1, your key, and a model ID from Models. For coding agents such as Claude Code, Codex or OpenCode there is a step-by-step guide in Integrations.
Errors and retries
The SDKs raise our errors as their own exceptions, with the status code and the body. Retry 429 and 503 after a short wait, and don't retry the rest. Every code: Limits and errors.