> ## Documentation Index
> Fetch the complete documentation index at: https://inference-docs.cerebras.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Started with Kong API Gateway

> Learn how to route Cerebras Inference requests through Kong API Gateway using the AI Proxy plugin for enhanced security, monitoring, and traffic management.

Kong API Gateway is a cloud-native API gateway that provides powerful traffic management, security, and observability features. When combined with Cerebras's ultra-fast inference, Kong enables you to build scalable, secure AI applications with advanced routing, authentication, and monitoring capabilities.

## Prerequisites

* **Cerebras API Key** - Get a free API key at [cloud.cerebras.ai](https://cloud.cerebras.ai/?utm_source=3pi_kong\&utm_campaign=integrations)
* **Kong Konnect Account** - Sign up for free at [Kong Konnect](https://konghq.com/products/kong-konnect/register)

## Quick Start

This guide uses Kong Konnect (cloud-managed) with a local data plane for testing. All commands are copy-paste ready.

<Steps>
  <Step title="Get your Cerebras API Key">
    1. Go to [https://cloud.cerebras.ai](https://cloud.cerebras.ai/?utm_source=3pi_kong\&utm_campaign=integrations)
    2. Sign in or create an account
    3. Navigate to **API Keys** in the dashboard
    4. Click **Create API Key**
    5. Copy the key (starts with `csk-`)
  </Step>

  <Step title="Generate Kong Konnect Personal Access Token">
    1. Sign in to [Kong Konnect](https://cloud.konghq.com)
    2. Click your profile icon (top-right corner)
    3. Select **Personal Access Tokens**
    4. Click **Generate Token**
    5. Give it a name like `cerebras-integration`
    6. Click **Generate**
    7. Copy the token immediately (starts with `kpat_`)
  </Step>

  <Step title="Set up environment variables">
    Export your API keys:

    ```bash theme={null}
    export KONNECT_TOKEN=kpat_your-token-here
    export CEREBRAS_API_KEY=csk_your-key-here
    ```
  </Step>

  <Step title="Install decK">
    Install decK (Kong's configuration tool):

    <Tabs>
      <Tab title="macOS">
        ```bash theme={null}
        brew install kong/deck/deck

        # Verify installation
        deck version
        ```
      </Tab>

      <Tab title="Linux">
        ```bash theme={null}
        curl -sL https://github.com/Kong/deck/releases/download/v1.43.0/deck_1.43.0_linux_amd64.tar.gz -o deck.tar.gz
        tar -xf deck.tar.gz -C /tmp
        sudo cp /tmp/deck /usr/local/bin/

        # Verify installation
        deck version
        ```
      </Tab>

      <Tab title="Windows">
        ```powershell theme={null}
        # Download from GitHub releases
        curl -sL https://github.com/Kong/deck/releases/download/v1.43.0/deck_1.43.0_windows_amd64.tar.gz -o deck.tar.gz

        # Extract and add to PATH
        # Or use: choco install deck

        # Verify installation
        deck version
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="Deploy Kong Gateway">
    Run Kong's quickstart script to deploy a local data plane connected to Konnect:

    ```bash theme={null}
    curl -Ls https://get.konghq.com/quickstart | bash
    ```

    This script:

    * Creates a control plane in Konnect
    * Deploys a local Kong Gateway data plane using Docker
    * Configures everything to work together

    Wait for the script to complete. You should see confirmation that Kong Gateway is running.
  </Step>

  <Step title="Create Gateway Service and Route">
    Create a service and route for Cerebras:

    ```bash theme={null}
    echo '
    _format_version: "3.0"
    services:
      - name: cerebras-service
        url: https://api.cerebras.ai
    routes:
      - name: cerebras-route
        paths:
          - /chat
        methods:
          - POST
        service:
          name: cerebras-service
    ' | deck gateway apply -
    ```
  </Step>

  <Step title="Configure AI Proxy Plugin">
    Add the AI Proxy plugin to route traffic to Cerebras:

    ```bash theme={null}
    echo '
    _format_version: "3.0"
    plugins:
      - name: ai-proxy
        config:
          route_type: llm/v1/chat
          auth:
            header_name: Authorization
            header_value: Bearer '${CEREBRAS_API_KEY}'
          model:
            provider: cerebras
            name: gpt-oss-120b
            options:
              max_tokens: 1024
              temperature: 0.7
    ' | deck gateway apply -
    ```
  </Step>

  <Step title="Test your integration">
    Send a test request:

    ```bash theme={null}
    curl -X POST http://localhost:8000/chat \
      --header "Content-Type: application/json" \
      --json '{
        "messages": [
          {"role": "system", "content": "You are a helpful assistant"},
          {"role": "user", "content": "Hello! What can you help me with?"}
        ]
      }'
    ```

    You should receive a response from Cerebras routed through Kong!
  </Step>
</Steps>

## What's Happening?

1. **Kong Gateway** runs locally in Docker (port 8000)
2. **Kong Konnect** manages the control plane in the cloud
3. **AI Proxy plugin** intercepts requests to `/chat` and routes them to Cerebras
4. Your **Cerebras API key** is securely injected by the plugin
5. Responses flow back through Kong to your client

## Using Different Models

To use a different Cerebras model, update the plugin configuration:

```bash theme={null}
echo '
_format_version: "3.0"
plugins:
  - name: ai-proxy
    config:
      route_type: llm/v1/chat
      auth:
        header_name: Authorization
        header_value: Bearer '${CEREBRAS_API_KEY}'
      model:
        provider: cerebras
        name: gpt-oss-120b  # or gpt-oss-120b, zai-glm-4.7
        options:
          max_tokens: 512
          temperature: 0.5
' | deck gateway apply -
```

## Advanced Configuration

### Using Different Cerebras Models

Kong's AI Proxy plugin supports all Cerebras models. Simply update the model configuration:

```yaml theme={null}
# For faster responses with Llama 3.1 8B
model:
  provider: cerebras
  name: gpt-oss-120b
  options:
    max_tokens: 512
    temperature: 0.5

# For maximum capability with GPT-OSS 120B
model:
  provider: cerebras
  name: gpt-oss-120b
  options:
    max_tokens: 2048
    temperature: 0.8
```

## Benefits of Using Kong with Cerebras

* **Centralized Management**: Manage all AI API traffic through a single gateway
* **Security**: Add authentication, rate limiting, and IP whitelisting
* **Observability**: Monitor request patterns, latency, and errors
* **Load Balancing**: Distribute traffic across multiple Cerebras endpoints
* **Caching**: Reduce costs and improve response times with intelligent caching
* **Transformation**: Modify requests and responses without changing your application code

## Available Models

Kong AI Proxy supports all Cerebras models:

| Model            | Parameters | Best For                                                         |
| ---------------- | ---------- | ---------------------------------------------------------------- |
| **gpt-oss-120b** | 120B       | Largest model for the most demanding tasks                       |
| **zai-glm-4.7**  | 357B       | Advanced 357B parameter model with strong reasoning capabilities |

Update the `model.name` field in your Kong configuration to switch between models.

## Troubleshooting

<Accordion title="Why am I getting 401 Unauthorized errors?">
  This usually indicates an issue with your Cerebras API key configuration:

  1. Verify your `CEREBRAS_API_KEY` environment variable is set correctly
  2. Check that the API key is valid and active in your Cerebras dashboard
  3. Ensure the header value format is correct: `Bearer YOUR_API_KEY`
  4. Test direct Cerebras API access to isolate the issue:

  ```bash theme={null}
  curl -X POST https://api.cerebras.ai/v1/chat/completions \
    --header "Authorization: Bearer $CEREBRAS_API_KEY" \
    --header "Content-Type: application/json" \
    --data '{"model":"gpt-oss-120b","messages":[{"role":"user","content":"test"}]}'
  ```
</Accordion>

<Accordion title="How do I debug plugin configuration issues?">
  Enable debug logging in Kong to troubleshoot plugin issues:

  ```bash theme={null}
  # Enable debug logging
  curl -X PATCH http://localhost:8001/config \
    --data "log_level=debug"

  # Check plugin configuration
  curl -X GET http://localhost:8001/plugins

  # View specific plugin details
  curl -X GET http://localhost:8001/plugins/{plugin-id}
  ```

  Common issues to check:

  * Plugin is enabled and properly configured
  * Environment variables are correctly set
  * Service and route configurations match
  * Upstream connectivity to Cerebras API
</Accordion>

<Accordion title="Can I use streaming responses with Kong?">
  Yes! Kong's AI Proxy plugin fully supports streaming responses from Cerebras. Simply include `"stream": true` in your request:

  ```bash theme={null}
  curl -X POST http://localhost:8000/chat \
    --header "Content-Type: application/json" \
    --data '{
      "messages": [
        {"role": "user", "content": "Write a short story"}
      ],
      "stream": true,
      "max_tokens": 500
    }'
  ```

  The streaming response will be passed through Kong in real-time, maintaining the low latency benefits of Cerebras inference.
</Accordion>

<Accordion title="How do I monitor Cerebras usage through Kong?">
  Kong provides several ways to monitor your Cerebras API usage:

  1. **Kong Vitals**: Built-in analytics for request metrics
  2. **Prometheus Metrics**: Export metrics for monitoring systems
  3. **Custom Logging**: Configure detailed request/response logging
  4. **Datadog Integration**: Send metrics and logs to Datadog

  Example Prometheus metrics setup:

  ```bash theme={null}
  curl -X POST http://localhost:8001/plugins \
    --data "name=prometheus" \
    --data "config.per_consumer=true"
  ```

  Access metrics at: `http://localhost:8001/metrics`
</Accordion>

## Next Steps

* Explore the [Kong AI Proxy documentation](https://docs.konghq.com/hub/kong-inc/ai-proxy/?utm_source=cerebras\&utm_campaign=integrations) for advanced configuration options
* Configure [advanced security plugins](https://docs.konghq.com/hub/?utm_source=cerebras\&utm_campaign=integrations) for production deployments
* Implement [monitoring and alerting](https://docs.konghq.com/enterprise/latest/monitoring/?utm_source=cerebras\&utm_campaign=integrations) for your AI workloads
* Try different [Cerebras models](/models) to optimize for your specific use case
* Set up [high availability](https://docs.konghq.com/enterprise/latest/high-availability/?utm_source=cerebras\&utm_campaign=integrations) configurations for production workloads
* **Migrate to GLM4.7**: Ready to upgrade? Follow our [migration guide](https://inference-docs.cerebras.ai/resources/glm-47-migration) to start using our latest model

## Additional Resources

* [Kong Gateway Documentation](https://docs.konghq.com/gateway/?utm_source=cerebras\&utm_campaign=integrations)
* [AI Proxy Plugin Reference](https://docs.konghq.com/hub/kong-inc/ai-proxy/?utm_source=cerebras\&utm_campaign=integrations)
* [Kong Konnect Getting Started](https://docs.konghq.com/konnect/?utm_source=cerebras\&utm_campaign=integrations)
* [Cerebras API Reference](/api-reference/chat-completions)
* [Kong Community](https://discuss.konghq.com/?utm_source=cerebras\&utm_campaign=integrations)
* [Kong GitHub Repository](https://github.com/Kong/kong?utm_source=cerebras\&utm_campaign=integrations)
