Custom Templates¶
Export chains to any format using Jinja2 templates.
Built-in Templates¶
FallbackRabbit ships with 4 built-in templates:
Terraform¶
Generates Terraform provider configuration.
Docker Compose¶
Generates Docker Compose with environment variables.
Kubernetes ConfigMap¶
Generates a Kubernetes ConfigMap.
Environment File¶
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(',') }}
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 |