Skip to main content

LLM Routing

DgiDgi's LLM Gateway provides flexible routing between multiple LLM providers, supporting platform-managed, tenant-provided, and development configurations.

LLM Source Types

DgiDgi supports three distinct LLM routing modes:

ModeDescriptionUse Case
Platform LLMPlatform-provided API keysDefault for all tenants
Tenant LLMTenant's own API keysEnterprise, data privacy
CLI LLMLocal model via CLISelf-hosted, offline

Architecture Overview

Platform LLM

Default mode where the platform provides LLM access using shared API keys.

Characteristics

  • Managed Keys: Platform maintains API keys for all providers
  • Usage Metering: Tracks token usage per tenant for billing
  • Rate Limiting: Enforces per-tenant rate limits
  • Cost Control: Budget limits and alerts

Flow

Configuration

// Tenant settings (default)
{
"llm": {
"source": "platform",
"preferredProvider": "anthropic",
"preferredModel": "claude-sonnet-4-20250514"
}
}

Tenant LLM

Enterprise mode where tenants provide their own API keys.

Characteristics

  • Data Privacy: Requests go directly to provider, no platform visibility
  • Own Billing: Tenant pays provider directly
  • Full Control: Choose any model, no platform limits
  • Key Management: Encrypted storage of tenant credentials

Flow

Configuration

// Tenant settings (own keys)
{
"llm": {
"source": "tenant",
"providers": {
"openai": { "configured": true },
"anthropic": { "configured": true }
}
}
}

Key Storage

Tenant API keys are stored encrypted in the database:

ColumnDescription
idPrimary key
tenant_idTenant identifier
providerProvider name (e.g., "openai", "anthropic")
encrypted_valueEncrypted API key (AES-256-GCM)
created_atCreation timestamp
rotated_atLast rotation timestamp

CLI LLM

Local model access via the DgiDgi CLI for self-hosted deployments.

Characteristics

  • Local Execution: Models run on user's machine
  • Offline Capable: No internet required
  • Privacy: Data never leaves local environment
  • Custom Models: Support for any Ollama-compatible model

Flow

Configuration

# CLI configuration
dgidgi config set llm.source cli
dgidgi config set llm.endpoint http://localhost:11434
dgidgi config set llm.model llama3

Routing Strategy

The gateway determines LLM source using this priority:

Provider Support

Supported Providers

ProviderModelsStreamingFunction Calling
OpenAIGPT-4o, GPT-4, GPT-3.5YesYes
AnthropicClaude 4, Claude 3.5YesYes
GoogleGemini Pro, Gemini FlashYesYes
GroqLlama 3, MixtralYesYes
MistralMistral Large, MediumYesYes
CohereCommand R+YesYes
PerplexitySonarYesNo
xAIGrokYesYes
DeepSeekDeepSeek CoderYesYes
OpenRouterMultipleYesVaries

Model Fallback

If a requested model is unavailable, the gateway attempts fallback:

Rate Limiting & Quotas

Platform LLM Limits

TierRequests/minTokens/dayConcurrent
Free1050,0002
Pro60500,00010
Team2002,000,00050
EnterpriseCustomCustomCustom

Tenant LLM Limits

When using tenant keys, limits are determined by the provider's API limits, not DgiDgi platform limits.

Monitoring & Analytics

All LLM requests are logged for analytics (excluding actual content for privacy):

{
"tenant_id": "...",
"provider": "anthropic",
"model": "claude-sonnet-4-20250514",
"source": "platform",
"tokens_input": 1500,
"tokens_output": 800,
"latency_ms": 2340,
"status": "success",
"timestamp": "..."
}