AI Gateway
AI Gateway is a service-based solution integrated within Traefik Hub, designed to simplify the management and integration of multiple Large Language Model (LLM) providers.
Configuration Example
- Create a Kubernetes Secret to store your AI provider token or API key:
apiVersion: v1
kind: Secret
metadata:
name: ai-apikey
type: Opaque
stringData:
key: YOUR_AI_PROVIDER_KEY
- Define your
AIService
:
- Anthropic
- AzureOpenAI
- Bedrock
- Cohere
- DeepSeek
- Gemini
- Mistral
- Ollama
- OpenAI
- Qwen
apiVersion: hub.traefik.io/v1alpha1
kind: AIService
metadata:
name: ai-anthropic
namespace: traefik
spec:
anthropic:
token:
secretName: "YOUR_KUBERNETES_SECRET_NAME"
model: "anthropic-model-name"
apiVersion: hub.traefik.io/v1alpha1
kind: AIService
metadata:
name: ai-azureopenai
namespace: traefik
spec:
azureOpenai:
apiKeySecret:
secretName: "YOUR_KUBERNETES_SECRET_NAME"
baseUrl: "https://your-azure-openai-endpoint.azure.com/"
deploymentName: your-deployment-name
model: "azureopenai-model-name"
apiVersion: hub.traefik.io/v1alpha1
kind: AIService
metadata:
name: ai-bedrock
namespace: traefik
spec:
bedrock:
model: "bedrock-model-name"
systemMessage: true
info
When using Bedrock, Traefik Hub will automatically detect the necessary AWS credentials needed from your environmental variables.
apiVersion: hub.traefik.io/v1alpha1
kind: AIService
metadata:
name: ai-cohere
namespace: traefik
spec:
cohere:
token:
secretName: "YOUR_KUBERNETES_SECRET_NAME"
model: "cohere-model-name"
apiVersion: hub.traefik.io/v1alpha1
kind: AIService
metadata:
name: ai-deepseek
namespace: traefik
spec:
deepSeek:
token:
secretName: "YOUR_KUBERNETES_SECRET_NAME"
model: "deepseek-model-name"
apiVersion: hub.traefik.io/v1alpha1
kind: AIService
metadata:
name: ai-gemini
namespace: traefik
spec:
gemini:
apiKey:
secretName: "YOUR_KUBERNETES_SECRET_NAME"
model: "gemini-model-name"
apiVersion: hub.traefik.io/v1alpha1
kind: AIService
metadata:
name: ai-mistral
namespace: traefik
spec:
mistral:
token:
secretName: "YOUR_KUBERNETES_SECRET_NAME"
model: "mistral-model-name"
apiVersion: hub.traefik.io/v1alpha1
kind: AIService
metadata:
name: ai-ollama
namespace: traefik
spec:
ollama:
baseUrl: "http://ollama.ollama.svc.cluster.local:11434"
model: "llama3.2"
apiVersion: hub.traefik.io/v1alpha1
kind: AIService
metadata:
name: ai-openai
namespace: traefik
spec:
openai:
baseUrl: "YOUR_BASE_URL"
token:
secretName: "YOUR_KUBERNETES_SECRET_NAME"
model: "o1-preview"
apiVersion: hub.traefik.io/v1alpha1
kind: AIService
metadata:
name: ai-qwen
namespace: traefik
spec:
qWen:
token:
secretName: "YOUR_KUBERNETES_SECRET_NAME"
model: "qwen-model-name"
- Attach your preferred
AIService
to an ingressRoute as a TraefikService :
- IngressRoute
- IngressRoute with API Management Enabled
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: ai-test
namespace: traefik
spec:
routes:
- kind: Rule
match: Host(`ai.localhost`)
services:
- kind: TraefikService
name: traefik-ai-openai@ai-gateway-service
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
annotations:
hub.traefik.io/api: "ai@traefik"
name: ai-test
namespace: traefik
spec:
routes:
- kind: Rule
match: Host(`ai.localhost`)
services:
- kind: TraefikService
name: traefik-ai-openai@ai-gateway-service
Configuration Options
Below is a table outlining the available configuration options/fields for the AIService
resource:
AI Providers | Field | Description | Required | Possible Values / Examples |
---|---|---|---|---|
OpenAI, Cohere, Anthropic, qWen, DeepSeek | token.secretName | Authentication token for AI providers | Yes | A string referencing a Kubernetes Secret name used to store the API_KEY provided by the AI provider (e.g., open-ai-token ) |
Gemini, Mistral | apiKey.secretName | API Key for AI providers | Yes | A string referencing a Kubernetes Secret name used to store the API_KEY provided by the AI provider (e.g., open-ai-token ) |
AzureOpenAI | apiKeySecret.secretName | API Key for AI providers | Yes | A string referencing a Kubernetes Secret name used to store the API_KEY provided by the AI provider (e.g., open-ai-token ) |
Ollama, AzureOpenAI, DeepSeek, OpenAI, QWen | baseUrl | Base URL for AI providers that require it | Yes | A valid URL (e.g., https://api.ollama.com ) |
AzureOpenAI | deploymentName | Deployment name for AzureOpenAI | Yes | A string specifying the deployment (e.g., deployment1 ) |
All Providers | model | Specifies the AI model to use | Yes | Model name as a string (e.g., gpt-4 ) |
Bedrock | region | AWS region for Bedrock (auto-detected if AWS is the cloud provider) | Yes | AWS region codes (e.g., us-west-2 ) |
Bedrock | systemMessage | Enables system message for Bedrock | No | A boolean (e.g., true ) |
All Providers | params.frequencyPenalty | Penalty for frequency in model outputs | No | Float value (e.g., 0.5 ) |
All Providers | params.maxTokens | Maximum number of tokens per request | No | Integer value (e.g., 1500 ) |
All Providers | params.presencePenalty | Penalty for presence in model outputs | No | Float value (e.g., 0.3 ) |
All Providers | params.temperature | Controls randomness in responses | No | Float range typically between 0.0 and 2.0 (e.g., 0.7 ) |
All Providers | params.topP | Controls diversity via nucleus sampling | No | Float range typically between 0.0 and 1.0 (e.g., 0.9 ) |
Related Content
- Learn more about the AI Gateway feature in its dedicated section.