FREE AI INDEX / 统一产品界面我的收藏提交资源 ↗

Free AI Index / 从零开始Getting started / SiliconFlow

FIRST API CALL / siliconflow

SiliconFlow:跑通第一次 API 调用Make your first SiliconFlow API call

先确认注册与免费条件,再按步骤获取密钥、安装依赖并验证返回结果。教程只使用环境变量读取密钥。Check signup and free terms first, then create a key, install dependencies and validate the response. Examples read credentials from environment variables.

官方文档复核Official docs reviewed: 2026-10-07独立 API 实测Independent API test: 尚未记录Not recorded

注册与网络前提Signup and network requirements

网络 / 地区
官方提供中国区 API endpoint;本指南未对不同运营商网络做连通性实测。
账号
SiliconFlow 账号;官方文档支持短信或邮箱登录。
手机号
可用短信或邮箱登录;注册环节是否要求手机号以当前页面提示为准。
实名认证
官方 Rate Limits 文档说明,使用全部免费模型需要完成实名认证。
信用卡 / 付款方式
官方将 ¥0 标价模型与付费模型区分;免费模型资格和限额按模型页及账号状态核对。

这些条件会因账号、地区和产品计划而变化。标注“待核验”表示 FreeLLM 尚未从当前链接的官方资料确认;不要据此推断为不需要。These requirements can vary by account, region and plan. “Unverified” means FreeLLM has not confirmed the condition from the linked official sources; it does not mean the requirement is absent.

获取并安全设置 API KeyGet and safely set your API key

在终端设置密钥Set the key in your terminal

以下命令只为当前终端会话设置环境变量。请在自己的电脑上把尖括号内容替换成真实密钥,不要把密钥发给 FreeLLM 或粘贴到公开代码。These commands set a variable for the current terminal session. Replace the angle-bracket text with your key on your own device; never send it to FreeLLM or commit it to source code.

Windows PowerShellWindows PowerShell

$env:SILICONFLOW_API_KEY = "<在此粘贴本地 API Key>"

macOS / LinuxmacOS / Linux

export SILICONFLOW_API_KEY="<在此粘贴本地 API Key>"

FreeLLM 资源记录FreeLLM resource records

详细操作步骤Detailed operation paths

每条路径都拆成前置条件、步骤、可复制命令和验证动作;免费条件仍以官方页面实时状态为准。curl 命令按 macOS / Linux shell 编写,Windows 用户可使用同页的 Python 或 Node.js 示例。Each path includes prerequisites, steps, copyable commands and a validation action; free terms still follow the provider's live official policy. The curl examples use a macOS/Linux shell; Windows users can run the Python or Node.js examples on this page.

调用 SiliconFlow 免费模型

api

EndpointEndpoint
https://api.siliconflow.cn/v1
认证Authentication
Authorization: Bearer API key
额度与限制Limits

调用额度与限流按提供商当前控制台和官方文档为准;免费条件可能按模型、账号和地区变化。

前置条件Prerequisites

  • 已注册 SiliconFlowSiliconFlow
  • 已创建 API keyAPI key
  • 已在模型广场确认模型的免费或赠送额度状态See official terms

操作步骤Steps

  1. 创建 API key

    进入 SiliconFlow 控制台的 API key 页面创建密钥,并保存为 SILICONFLOW_API_KEY 环境变量。

  2. 查看模型与余额

    在模型广场确认模型 ID、上下文限制和当前免费政策;免费模型不等于无限调用。

    操作Action:打开 https://siliconflow.cn/models

  3. 发送兼容请求

    使用模型广场展示的完整模型 ID。

    可复制命令Copyable command
    export SILICONFLOW_API_KEY="你的 Key"
    curl https://api.siliconflow.cn/v1/chat/completions -H "Authorization: Bearer $SILICONFLOW_API_KEY" -H 'Content-Type: application/json' --data '{"model":"Qwen/Qwen3-8B","messages":[{"role":"user","content":"Hello"}]}'

    预期结果Expected:返回 choices[0].message.content;余额不足时停止重试并查看控制台。

  4. Python SDK 示例

    安装 OpenAI SDK;在运行环境设置 SILICONFLOW_API_KEY,示例代码通过环境变量读取密钥。

    可复制命令Copyable command
    python -m pip install -U openai
    
    import os
    from openai import OpenAI
    
    client = OpenAI(
        api_key=os.environ["SILICONFLOW_API_KEY"],
        base_url="https://api.siliconflow.cn/v1",
    )
    response = client.chat.completions.create(
        model="XingChenAGI/Xing4.0-29B",
        messages=[{"role": "user", "content": "用一句话解释 API 是什么。"}],
    )
    print(response.choices[0].message.content)

    预期结果Expected:终端打印模型生成的回复;再到提供商控制台确认请求状态和额度扣减。

  5. Node.js SDK 示例

    安装 OpenAI SDK;在运行环境设置 SILICONFLOW_API_KEY,示例代码通过环境变量读取密钥。

    可复制命令Copyable command
    npm install openai
    
    import OpenAI from "openai";
    
    const client = new OpenAI({
      apiKey: process.env.SILICONFLOW_API_KEY,
      baseURL: "https://api.siliconflow.cn/v1",
    });
    const response = await client.chat.completions.create({
      model: "XingChenAGI/Xing4.0-29B",
      messages: [{ role: "user", content: "用一句话解释 API 是什么。" }],
    });
    console.log(response.choices[0].message.content);

    预期结果Expected:Node.js 打印模型生成的回复;再到提供商控制台确认请求状态和额度扣减。

验证动作Validation

GET /v1/models 返回 HTTP 200,并在控制台确认请求消耗与免费政策一致。

常见问题Common issues
  • 401:检查 API Key、环境变量和认证 Header。401: API Key、 Header。
  • 404:从官方模型清单复制当前模型 ID,并确认 endpoint 与账号地域一致。404: ID, endpoint 。
  • 429:查看当前限流和配额重置说明,降低请求频率后再重试。429: , 。

官方来源Official sources