Access SiliconFlow models — including free tiers — through TheRouter's OpenAI-compatible API. No code changes required beyond setting your base URL. Powered by SiliconFlow, a high-speed inference platform with 200+ optimized models.
This guide explains how to use the SiliconFlow OpenAI-compatible API through TheRouter. SiliconFlow is an international AI inference platform that provides OpenAI-compatible endpoints for models including DeepSeek R1, DeepSeek V3, Qwen3, and more. TheRouter routes to SiliconFlow automatically, providing unified billing and failover. The API is OpenAI-compatible — change the base URL and API key, and your existing code works without modification. Permanently free models available: Qwen3-8B, DeepSeek R1 Distill Qwen-7B, and DeepSeek OCR.
TheRouter is OpenAI-compatible. Set the base URL to https://api.therouter.ai/v1 and use your TheRouter API key. SiliconFlow routing happens automatically — your existing OpenAI SDK code works without modification.
from openai import OpenAI
client = OpenAI(
api_key="YOUR_THEROUTER_API_KEY",
base_url="https://api.therouter.ai/v1",
)
response = client.chat.completions.create(
model="qwen/qwen3-8b", # free model
messages=[
{"role": "user", "content": "Explain the difference between TCP and UDP."}
],
)
print(response.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.THE_ROUTER_API_KEY,
baseURL: "https://api.therouter.ai/v1",
});
const response = await client.chat.completions.create({
model: "qwen/qwen3-8b", // free model
messages: [
{ role: "user", content: "Explain the difference between TCP and UDP." },
],
});
console.log(response.choices[0].message.content);curl https://api.therouter.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $THE_ROUTER_API_KEY" \
-d '{
"model": "qwen/qwen3-8b",
"messages": [
{"role": "user", "content": "Explain the difference between TCP and UDP."}
]
}'Three SiliconFlow models are permanently free through TheRouter — no credit card required, no trial period:
| Model ID | Best for | Cost |
|---|---|---|
qwen/qwen3-8b | General chat, coding assistance, Q&A | Free |
deepseek/deepseek-r1-distill-qwen-7b | Chain-of-thought reasoning, math, logic | Free |
deepseek/deepseek-ocr | Text extraction from images and documents | Free |
In addition to free models, SiliconFlow provides access to high-performance paid models with automatic failover:
| Model ID | Description | Input / Output ($/MTok) |
|---|---|---|
deepseek/deepseek-r1 | Full reasoning model with chain-of-thought | $0.55 / $2.19 |
deepseek/deepseek-v3.2 | Fast, cost-efficient text model | $0.14 / $0.28 |
qwen/qwen3-235b | Alibaba flagship MoE model | $0.14 / $0.55 |
qwen/qwen3-32b | Dense model with tools + reasoning | $0.03 / $0.07 |
qwen/qwen3-coder-480b | Specialized code model | $0.35 / $1.40 |
Streaming works the same as any OpenAI-compatible provider:
from openai import OpenAI
client = OpenAI(
api_key="YOUR_THEROUTER_API_KEY",
base_url="https://api.therouter.ai/v1",
)
stream = client.chat.completions.create(
model="deepseek/deepseek-r1-distill-qwen-7b", # free reasoning model
messages=[{"role": "user", "content": "Write a haiku about distributed systems."}],
stream=True,
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
print()DeepSeek R1 models return a reasoning_content field alongside the main response. TheRouter preserves this field end-to-end.
The reasoning_content contains the model's internal chain-of-thought and is available in both streaming and non-streaming responses:
import json
import httpx
response = httpx.post(
"https://api.therouter.ai/v1/chat/completions",
headers={
"Authorization": "Bearer YOUR_THEROUTER_API_KEY",
"Content-Type": "application/json",
},
json={
"model": "deepseek/deepseek-r1-distill-qwen-7b", # free reasoning model
"messages": [
{"role": "user", "content": "What is 17 * 23? Show your reasoning."}
],
},
)
data = response.json()
choice = data["choices"][0]
# The main answer
print("Answer:", choice["message"]["content"])
# DeepSeek R1 chain-of-thought (preserved by TheRouter)
reasoning = choice["message"].get("reasoning_content")
if reasoning:
print("Reasoning:", reasoning[:200], "...")DeepSeek V3 and Qwen3 models support function calling via the standard OpenAI tools format:
from openai import OpenAI
client = OpenAI(
api_key="YOUR_THEROUTER_API_KEY",
base_url="https://api.therouter.ai/v1",
)
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "City name"},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
},
"required": ["city"],
},
},
}
]
response = client.chat.completions.create(
model="deepseek/deepseek-v3.2",
messages=[{"role": "user", "content": "What's the weather in Beijing?"}],
tools=tools,
tool_choice="auto",
)
print(response.choices[0].message.tool_calls)