# Route Traffic to DeepSeek Models

[DeepSeek](https://www.deepseek.com/) provides high-performance language models at competitive pricing through an OpenAI-compatible API. API7 Gateway includes a dedicated DeepSeek driver, so you do not need to use the generic `openai-compatible` provider. This guide shows how to route traffic to DeepSeek through API7 Gateway using the [`ai-proxy`](https://docs.api7.ai/hub/ai-proxy.md) plugin.

## Prerequisites[​](#prerequisites "Direct link to Prerequisites")

* Install [Docker](https://docs.docker.com/get-docker/).

* Install [cURL](https://curl.se/) to send requests to the services for validation.

* Have a running API7 Gateway instance.

* Create a [token from the Dashboard](https://docs.api7.ai/api7-gateway/reference/obtain-dashboard-token.md) and save it to an environment variable:

  ```
  export API_KEY=your-dashboard-token   # replace with your Dashboard token
  ```

* Replace `{gateway_group_id}` with your gateway group ID. Use `default` if you are following the quickstart.

* If you are following the Admin API examples, create or reuse a service in API7 Gateway. If you do not have one yet, follow [Create or Reuse a Service](https://docs.api7.ai/api7-gateway/ai-gateway/get-started.md#create-or-reuse-a-service), then save its ID to an environment variable:

  ```
  export SERVICE_ID=your-service-id         # replace with your service ID
  ```

## Obtain a DeepSeek API Key[​](#obtain-a-deepseek-api-key "Direct link to Obtain a DeepSeek API Key")

Create an account at [platform.deepseek.com](https://platform.deepseek.com/) and generate an API key. Save the key to an environment variable:

```
export DEEPSEEK_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxx   # replace with your DeepSeek API key
```

## Configure the AI Proxy for DeepSeek[​](#configure-the-ai-proxy-for-deepseek "Direct link to Configure the AI Proxy for DeepSeek")

Create a route with the [`ai-proxy`](https://docs.api7.ai/hub/ai-proxy.md) plugin:

* Admin API
* ADC

```
curl -k "https://localhost:7443/apisix/admin/routes/deepseek-route?gateway_group_id={gateway_group_id}" -X PUT \

  -H "X-API-KEY: ${API_KEY}" \

  -H "Content-Type: application/json" \

  --data-binary @- <<EOF

  {

    "name": "deepseek-route",

    "service_id": "$SERVICE_ID",

    "paths": ["/deepseek"],

    "plugins": {

      "ai-proxy": {

        "provider": "deepseek",

        "auth": {

          "header": {

            "Authorization": "Bearer $DEEPSEEK_API_KEY"

          }

        },

        "options": {

          "model": "deepseek-chat"

        }

      }

    }

  }

EOF
```

❶ Set the provider to `deepseek`. This uses the dedicated DeepSeek driver.

❷ Attach the DeepSeek API key in the `Authorization` header.

❸ Set the model to `deepseek-chat`. Other available models include `deepseek-reasoner`.

adc.yaml

```
services:

  - name: DeepSeek Service

    routes:

      - uris:

          - /deepseek

        name: deepseek-route

        plugins:

          ai-proxy:

            provider: deepseek

            auth:

              header:

                Authorization: "Bearer ${DEEPSEEK_API_KEY}"

            options:

              model: deepseek-chat

    labels:

      docs-example: deepseek-service
```

❶ Set the provider to `deepseek`. This uses the dedicated DeepSeek driver.

❷ Attach the DeepSeek API key in the `Authorization` header.

❸ Set the model to `deepseek-chat`. Other available models include `deepseek-reasoner`.

Preview the changes owned by this example and confirm that the diff contains no unintended updates or deletions:

```
adc diff -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=deepseek-service
```

Synchronize the reviewed configuration:

```
adc sync -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=deepseek-service
```

## Multi-Model Routing with DeepSeek[​](#multi-model-routing-with-deepseek "Direct link to Multi-Model Routing with DeepSeek")

DeepSeek models offer significantly lower per-token pricing than many alternatives. Use [`ai-proxy-multi`](https://docs.api7.ai/hub/ai-proxy-multi.md) to route most traffic to DeepSeek while keeping a premium provider as fallback:

* Admin API
* ADC

```
curl -k "https://localhost:7443/apisix/admin/routes/deepseek-multi-route?gateway_group_id={gateway_group_id}" -X PUT \

  -H "X-API-KEY: ${API_KEY}" \

  -H "Content-Type: application/json" \

  --data-binary @- <<EOF

  {

    "service_id": "$SERVICE_ID",

    "name": "deepseek-multi-route",

    "paths": ["/deepseek-multi"],

    "plugins": {

      "ai-proxy-multi": {

        "fallback_strategy": ["http_429", "http_5xx"],

        "instances": [

          {

            "name": "deepseek-primary",

            "provider": "deepseek",

            "auth": { "header": { "Authorization": "Bearer $DEEPSEEK_API_KEY" } },

            "options": { "model": "deepseek-chat" },

            "weight": 1,

            "priority": 2

          },

          {

            "name": "openai-fallback",

            "provider": "openai",

            "auth": { "header": { "Authorization": "Bearer $OPENAI_API_KEY" } },

            "options": { "model": "gpt-4o-mini" },

            "weight": 1,

            "priority": 1

          }

        ]

      }

    }

  }

EOF
```

❶ `fallback_strategy` enables automatic failover on HTTP 429 (rate limited) or 5xx (server error).

❷ Set DeepSeek as the primary instance with highest priority.

❸ Set OpenAI as the fallback with lower priority. Traffic routes here only when DeepSeek is unavailable.

adc.yaml

```
services:

  - name: DeepSeek with Fallback

    routes:

      - uris:

          - /deepseek-multi

        name: deepseek-multi-route

        plugins:

          ai-proxy-multi:

            fallback_strategy:

              - http_429

              - http_5xx

            instances:

              - name: deepseek-primary

                provider: deepseek

                auth:

                  header:

                    Authorization: "Bearer ${DEEPSEEK_API_KEY}"

                options:

                  model: deepseek-chat

                weight: 1

                priority: 2

              - name: openai-fallback

                provider: openai

                auth:

                  header:

                    Authorization: "Bearer ${OPENAI_API_KEY}"

                options:

                  model: gpt-4o-mini

                weight: 1

                priority: 1

    labels:

      docs-example: deepseek-with-fallback
```

❶ `fallback_strategy` enables automatic failover on HTTP 429 (rate limited) or 5xx (server error).

❷ Set DeepSeek as the primary instance with highest priority.

❸ Set OpenAI as the fallback with lower priority. Traffic routes here only when DeepSeek is unavailable.

Preview the changes owned by this example and confirm that the diff contains no unintended updates or deletions:

```
adc diff -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=deepseek-with-fallback
```

Synchronize the reviewed configuration:

```
adc sync -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=deepseek-with-fallback
```

For more routing strategies, see [Multi-LLM Routing and Fallback](https://docs.api7.ai/api7-gateway/ai-gateway/use-cases/multi-llm-routing-and-fallback.md).

## Validate the Configuration[​](#validate-the-configuration "Direct link to Validate the Configuration")

Send this request to the multi-model route. To test the single-model route, use `/deepseek` instead of `/deepseek-multi`.

```
curl "http://127.0.0.1:9080/deepseek-multi" -X POST \

  -H "Content-Type: application/json" \

  -d '{

    "messages": [

      { "role": "user", "content": "What is the Fibonacci sequence?" }

    ]

  }'
```

You should receive a response similar to the following:

```
{

  "id": "chatcmpl-abc123",

  "object": "chat.completion",

  "model": "deepseek-chat",

  "choices": [

    {

      "index": 0,

      "message": {

        "role": "assistant",

        "content": "The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, typically starting with 0 and 1: 0, 1, 1, 2, 3, 5, 8, 13, 21, ..."

      },

      "finish_reason": "stop"

    }

  ],

  "usage": {

    "prompt_tokens": 10,

    "completion_tokens": 48,

    "total_tokens": 58

  }

}
```

To enable streaming responses, set `"stream": true` in the request body. Use the [`proxy-buffering`](https://docs.api7.ai/hub/proxy-buffering.md) plugin to disable NGINX `proxy_buffering` to avoid server-sent events (SSE) being buffered.

## Next Steps[​](#next-steps "Direct link to Next Steps")

You have learned how to route traffic to DeepSeek through API7 Gateway. See the [DeepSeek API documentation](https://platform.deepseek.com/api-docs) for more details about available models.

* [Multi-LLM Routing and Fallback](https://docs.api7.ai/api7-gateway/ai-gateway/use-cases/multi-llm-routing-and-fallback.md) — Combine DeepSeek with other providers for cost optimization.
* [Token Rate Limiting](https://docs.api7.ai/api7-gateway/ai-gateway/use-cases/token-rate-limiting-and-quota-management.md) — Control spending with token budgets.
