SiliconFlow OpenAI-Compatible API Integration Guide

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.

Prerequisites

Quick Start

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.

Python (openai SDK)

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)

TypeScript / Node.js

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

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."}
    ]
  }'

Free Models

Three SiliconFlow models are permanently free through TheRouter — no credit card required, no trial period:

Model IDBest forCost
qwen/qwen3-8bGeneral chat, coding assistance, Q&AFree
deepseek/deepseek-r1-distill-qwen-7bChain-of-thought reasoning, math, logicFree
deepseek/deepseek-ocrText extraction from images and documentsFree

Paid Models via SiliconFlow

In addition to free models, SiliconFlow provides access to high-performance paid models with automatic failover:

Model IDDescriptionInput / Output ($/MTok)
deepseek/deepseek-r1Full reasoning model with chain-of-thought$0.55 / $2.19
deepseek/deepseek-v3.2Fast, cost-efficient text model$0.14 / $0.28
qwen/qwen3-235bAlibaba flagship MoE model$0.14 / $0.55
qwen/qwen3-32bDense model with tools + reasoning$0.03 / $0.07
qwen/qwen3-coder-480bSpecialized code model$0.35 / $1.40

Streaming

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: Reasoning Content

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], "...")

Tool Use (Function Calling)

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)

Related

Help & contact