Skip to content

Custom Templates

Export chains to any format using Jinja2 templates.

Built-in Templates

FallbackRabbit ships with 4 built-in templates:

Terraform

fallbackrabbit export my-chain.yaml --format template --template terraform

Generates Terraform provider configuration.

Docker Compose

fallbackrabbit export my-chain.yaml --format template --template docker

Generates Docker Compose with environment variables.

Kubernetes ConfigMap

fallbackrabbit export my-chain.yaml --format template --template k8s

Generates a Kubernetes ConfigMap.

Environment File

fallbackrabbit export my-chain.yaml --format template --template env

Generates a .env file with provider configuration.

Custom Templates

Write your own Jinja2 templates:

# my-template.j2
# Generated by FallbackRabbit
{% for provider in chain.providers %}
PROVIDER_{{ provider.name | upper }}={{ provider.model_id }}
PROVIDER_{{ provider.name | upper }}_PRIORITY={{ provider.priority }}
{% endfor %}

FALLBACK_CHAIN={{ chain.providers | map(attribute='name') | join(',') }}
fallbackrabbit export my-chain.yaml --format template --template my-template.j2

API Template Export

# Built-in template
curl -X POST http://localhost:8000/export-template \
  -H "Content-Type: application/json" \
  -d '{"chain_id": "abc123", "template_name": "terraform"}'

# Custom template file
curl -X POST http://localhost:8000/export-template \
  -H "Content-Type: application/json" \
  -d '{"chain_id": "abc123", "template_content": "..."}'

# With extra variables
curl -X POST http://localhost:8000/export-template \
  -H "Content-Type: application/json" \
  -d '{"chain_id": "abc123", "template_name": "terraform", "extra_vars": {"env": "prod"}}'

Template Variables

All templates receive:

Variable Type Description
chain Chain The full chain object with providers and rules
chain.name str Chain name
chain.providers list Provider list with name, model_id, priority
chain.fallback_rules list Fallback rules
extra_vars dict Any extra variables passed via CLI or API