> ## Documentation Index
> Fetch the complete documentation index at: https://www.truefoundry.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SiliconFlow

> Add and configure SiliconFlow models in TrueFoundry's AI Gateway using Custom Endpoints.

[SiliconFlow](https://www.siliconflow.com/) provides an **OpenAI-compatible** chat completions API for open-source and proprietary models. Use **Custom Endpoints** in the AI Gateway to register SiliconFlow once, keep the SiliconFlow API key on the AI Gateway, and let your applications call models through a single TrueFoundry API key with access control and tracing.

### Prerequisites

<Steps>
  <Step title="Create a SiliconFlow account">
    Sign up at [cloud.siliconflow.com](https://cloud.siliconflow.com/) if you do not already have an account.
  </Step>

  <Step title="Generate a SiliconFlow API key">
    In the SiliconFlow dashboard, open [API Keys](https://cloud.siliconflow.com/account/ak) and create a new key.

    Store the key securely. You will paste it into the AI Gateway's **Custom Headers** configuration — not in client application code.
  </Step>

  <Step title="Get your TrueFoundry API key and gateway URL">
    You need a **TrueFoundry API key** (`TFY_API_KEY`) and your **gateway base URL** to call models through the AI Gateway. See [Gateway base URL](/docs/ai-gateway/quick-start#gateway-base-url) and [Authentication](/docs/ai-gateway/authentication).
  </Step>
</Steps>

### Adding models

Add SiliconFlow to the AI Gateway using **Custom Endpoints**.

<Steps>
  <Step title="Create a Custom Endpoint model account">
    In the TrueFoundry dashboard, go to **AI Gateway** → **Models** → **Custom Endpoints** and click **Add Custom Endpoint**.

    In **Configure Account**, set:

    * **Name** (Account Name): any unique label for this provider (for example, `siliconflow`) — this is your **model account name** and appears as the first path segment in every request URL (`{providerAccountName}`)
    * **Endpoint Type**: `None`
    * **Header Auth**: keep **disabled**
  </Step>

  <Step title="Add a SiliconFlow endpoint">
    On the **Endpoints** step, add an integration and configure:

    * **Display Name**: any unique label for this endpoint (for example, `chat`) — this is your **custom endpoint display name** and appears as the second path segment in every request URL (`{endpointName}`)
    * **Base URL**: `https://api.siliconflow.com/v1/chat/completions`

    Enable **Custom Headers** and add:

    * `Content-Type`: `application/json`
    * `Authorization`: `Bearer <SILICONFLOW_API_KEY>`

    Keep **Header Auth** and **TLS Settings** disabled unless your deployment requires them.

    <Frame caption="Endpoint settings — Base URL and upstream headers">
      <img src="https://mintcdn.com/truefoundry/jdsfgRxU6K0wjCiU/images/SiliconFlow1.png?fit=max&auto=format&n=jdsfgRxU6K0wjCiU&q=85&s=7ef4ed287a2260372d7e5be7eb8e267e" alt="Custom Endpoint form for SiliconFlow with Base URL and custom headers" width="1055" height="952" data-path="images/SiliconFlow1.png" />
    </Frame>

    <Note>
      The **Authorization** header here is sent **from the AI Gateway to SiliconFlow**. Your application should only send the **TrueFoundry API key** to the AI Gateway.
    </Note>

    <Tip>
      You can click **+ Add Custom Endpoint** to register **multiple endpoints** under the same account (for example, `chat`, `vision`, or `fast-inference`). Each gets its own **Display Name** in the URL, but they can all point to the same SiliconFlow **Base URL** and headers. Which SiliconFlow model runs is chosen in the request body `model` field — not by the display name.
    </Tip>
  </Step>

  <Step title="Set access control and save">
    On the **Access Control** step, choose who can manage and use this model account, then **Save**.

    * **Manager**: users/teams who can edit or delete the custom endpoint
    * **User**: users/teams who can call the endpoint (for example, `everyone`)
  </Step>
</Steps>

### Inference

Once saved, call SiliconFlow through the AI Gateway's **proxy-api** path. URL shape and path rules are documented under [Custom Endpoints](/docs/ai-gateway/custom-endpoints#endpoint-structure).

After saving, TrueFoundry shows a **Usage code snippet** for the endpoint with the Base URL, Model ID, and a TrueFoundry API key.

<Frame caption="Usage code snippet for the SiliconFlow custom endpoint">
  <img src="https://mintcdn.com/truefoundry/jdsfgRxU6K0wjCiU/images/SiliconFlowCode.png?fit=max&auto=format&n=jdsfgRxU6K0wjCiU&q=85&s=fe112beaf55652c61118f862fc38fb4c" alt="Usage code snippet modal showing Base URL, Model ID, and API Key for SiliconFlow" width="1332" height="787" data-path="images/SiliconFlowCode.png" />
</Frame>

<Note>
  Because the integration **Base URL** already includes `/v1/chat/completions`, leave `PROXY_PATH` empty (or omit any upstream path). The AI Gateway forwards the request directly to SiliconFlow's chat completions endpoint.
</Note>

#### How the request URL is built

The AI Gateway URL has two values **you configure in the dashboard** — they are not SiliconFlow model IDs:

| URL segment             | Dashboard field                                   | Example in this guide |
| ----------------------- | ------------------------------------------------- | --------------------- |
| `{providerAccountName}` | **Account Name** (Configure Account → **Name**)   | `siliconflow`         |
| `{endpointName}`        | **Custom endpoint Display Name** (Endpoints step) | `chat`                |

Full URL pattern:

```
{GATEWAY_BASE_URL}/proxy-api/{providerAccountName}/{endpointName}
```

With the example configuration above:

```
{GATEWAY_BASE_URL}/proxy-api/siliconflow/chat
```

| Segment              | Example value                                       | Meaning                  |
| -------------------- | --------------------------------------------------- | ------------------------ |
| `{GATEWAY_BASE_URL}` | `https://internal.devtest.truefoundry.tech/api/llm` | Your AI Gateway base URL |
| `siliconflow`        | Account Name you set in **Configure Account**       | `{providerAccountName}`  |
| `chat`               | Display Name you set for the custom endpoint        | `{endpointName}`         |

The AI Gateway forwards the request to:

```
https://api.siliconflow.com/v1/chat/completions
```

#### Choosing a SiliconFlow model

SiliconFlow hosts **many models** available in your workspace. You do **not** need a separate custom endpoint per model — set the `model` field in the JSON request body to whichever SiliconFlow model ID you want to run (for example, `Qwen/Qwen3-32B`). See the [SiliconFlow models catalog](https://cloud.siliconflow.com/models) for the full list.

If you add multiple custom endpoints under the same account (different **Display Name** values), use the matching `{endpointName}` in the URL; each endpoint can still call any SiliconFlow model via the request body.

<Note>
  Replace `siliconflow` and `chat` in the URL with your own **Account Name** and **Display Name** if you used different values during setup.
</Note>

### Supported APIs

| API                                   | Endpoint                                          | Tracing | Cost Tracking                                               |
| ------------------------------------- | ------------------------------------------------- | ------- | ----------------------------------------------------------- |
| [Chat Completions](#chat-completions) | `/proxy-api/{providerAccountName}/{endpointName}` | **✅**   | <Icon icon="circle-xmark" iconType="regular" color="red" /> |

<AccordionGroup>
  <Accordion title="Chat Completions">
    **Before you start:** Replace `{GATEWAY_BASE_URL}` with your gateway base URL ([how to find it](/docs/ai-gateway/quick-start#gateway-base-url)) and set `TFY_API_KEY` to your TrueFoundry API key.

    #### Request headers (client → gateway)

    | Header            | Value                  |
    | ----------------- | ---------------------- |
    | `Authorization`   | `Bearer <TFY_API_KEY>` |
    | `Content-Type`    | `application/json`     |
    | `Accept-Encoding` | `identity`             |

    #### Python (`requests`)

    ```python lines theme={"dark"}
    import os

    import requests

    GATEWAY_BASE_URL = "{GATEWAY_BASE_URL}"  # e.g. https://internal.devtest.truefoundry.tech/api/llm
    TFY_API_KEY = os.environ.get("TFY_API_KEY", "your-tfy-api-key")

    # providerAccountName = Account Name from Configure Account (e.g. siliconflow)
    # endpointName = Custom endpoint Display Name (e.g. chat)
    # model in BODY = SiliconFlow model ID (e.g. Qwen/Qwen3-32B)
    PROVIDER_ACCOUNT_NAME = "siliconflow"
    ENDPOINT_NAME = "chat"
    URL = f"{GATEWAY_BASE_URL}/proxy-api/{PROVIDER_ACCOUNT_NAME}/{ENDPOINT_NAME}"

    HEADERS = {
        "Authorization": f"Bearer {TFY_API_KEY}",
        "Content-Type": "application/json",
        "Accept-Encoding": "identity",
    }

    BODY = {
        "model": "Qwen/Qwen3-32B",  # any SiliconFlow model ID
        "messages": [
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": "Tell me about TrueFoundry AI Gateway"},
        ],
        "temperature": 0.7,
        "stream": False,
    }

    response = requests.post(URL, headers=HEADERS, json=BODY, timeout=120)
    response.raise_for_status()

    print(response.json())
    ```

    #### cURL

    ```bash theme={"dark"}
    curl -X POST "{GATEWAY_BASE_URL}/proxy-api/siliconflow/chat" \
      -H "Authorization: Bearer $TFY_API_KEY" \
      -H "Content-Type: application/json" \
      -H "Accept-Encoding: identity" \
      -d '{
        "model": "Qwen/Qwen3-32B",
        "messages": [
          {"role": "system", "content": "You are a helpful assistant."},
          {"role": "user", "content": "Tell me about TrueFoundry AI Gateway"}
        ],
        "temperature": 0.7,
        "stream": false
      }'
    ```

    <Info>
      **Support scope:** Custom Endpoints proxy requests transparently to SiliconFlow. For gateway limitations on Custom Endpoints (HTTPS, streaming, and so on), see [Custom Endpoints](/docs/ai-gateway/custom-endpoints).
    </Info>
  </Accordion>
</AccordionGroup>
