Estimated time: 20–30 minutes. Complete Getting Started first. For the concepts behind budgets, rate limits, and model access, see LLM Controls.
Before You Begin
- A configured
provider "barndoor"block (see Getting Started) - An API key for at least one upstream LLM provider (this guide uses OpenAI)
Step 1: Add an upstream provider
barndoor_llm_provider
The api_key is write-only: the platform stores it in its secret store and never returns it. Keep it in a variable or TF_VAR_openai_api_key, never in committed configuration.
Step 2: Enable models with 1:1 mappings
A model mapping makes an upstream model servable through the gateway. A 1:1 mapping (alias equals upstream model) is the enablement:barndoor_llm_model_mapping
Step 3: Add a custom alias with failover
Custom aliases decouple what your agents call from what serves it — you can re-pointfast at a different model later without touching any agent:
priority (lower first). The retry_on_429_* settings control how the gateway rides out upstream rate limiting before failing over.
Step 4: Restrict which models can be used
An access policy allowlists (or denylists) models for a scope — the whole organization, an IdP group, or a single user:barndoor_llm_model_access
Targets can name a model alias pattern (as above), a specific upstream model (kind = "model"), an entire provider (kind = "provider"), or a provider+model pair.
Step 5: Add rate limits
Rate limits throttle a scope over a rolling 60-second window:barndoor_llm_rate_limit
Step 6: Set token budgets
Budgets cap total consumption over a day, week, or month — the spend-control counterpart to rate limits:barndoor_llm_token_budget
Alert thresholds default to [80, 90] (percent), and action_on_exhaust defaults to block; the softer warn lets traffic continue while notifying. One budget exists per (scope, traffic type, period).
Behavior worth knowing
- Scope immutability: the scope of a token budget forces replacement when changed; on model access policies, clearing a group/user scope back to org-wide also forces a new policy.
- Two-step creates: some LLM Gateway resources are created with a follow-up update under the hood (not every field is settable on create). If an apply is interrupted at exactly the wrong moment, a partially-configured object can exist — a re-apply converges it, or the next plan shows the difference.
- Verify in the app: everything in this guide is visible in the Barndoor app’s LLM Management hub — providers and routes under their sections, and budgets, rate limits, and model access under Controls (see LLM Controls).