Using Secrets in Routes
Learn how to inject encrypted secrets into your route requests using KnoxCall’s template system.Template Syntax
Secrets are injected using template syntax in your route configuration.Basic Format
{{- Opening delimitersecret:- Type identifier (required)SECRET_NAME- Your secret’s name}}- Closing delimiter
Example
If you have a secret namedstripe_prod_key:
Injecting Secrets in Headers
The most common use case - adding secrets to HTTP headers.Step 1: Edit Route
- Go to Routes
- Click on your route
- Scroll to Inject Headers section
Step 2: Add Header with Secret
Click Add Header or edit the JSON directly:Step 3: Save
Click Save Changes ✅ All requests through this route now have the secret injected!Common Header Patterns
Bearer Token
API Key Header
Basic Authentication
username:password
Custom Headers
Injecting Secrets in the Request Body
KnoxCall can substitute placeholders inside the request body your client sends — not just headers. This lets your application reference secrets by name (or by ID) without ever holding the actual values. KnoxCall resolves the placeholders server-side, swaps them for the real decrypted values, and forwards the rewritten body upstream.How it works
- Your client sends a POST/PUT/PATCH with placeholder tokens in the body
- KnoxCall reads the body, scans for
{{secret:name}}/{{secret_id:uuid}}/{{var:key}} - KnoxCall resolves each reference against your tenant’s secrets for the route’s active environment
- KnoxCall rewrites
Content-Lengthand forwards the substituted body to the upstream API - Your application never needs to possess the raw credential
Placeholder forms accepted in the body
| Form | Lookup | Example | Recommended |
|---|---|---|---|
{{secret_id:UUID}} | By secret UUID — stable, rename-safe | {{secret_id:550e8400-e29b-41d4-a716-446655440000}} | ✅ Preferred |
{{secret:NAME}} | By secret name — legacy, human-friendly | {{secret:stripe_prod_key}} | ⚠️ Works, but breaks on rename |
{{var:QUERY_PARAM}} | Value of an incoming query string parameter | {{var:user_id}} | — |
create_secret API / onboarding-agent tool call.
Example — JSON body
Your client code sends this to KnoxCall (UUID form recommended):Example — form-urlencoded
Example — plain text / XML
Supported Content-Types
KnoxCall only rewrites bodies for text-shaped Content-Types, so binary uploads stay byte-identical:| Content-Type | Body injection |
|---|---|
application/json | ✅ |
application/xml, text/xml, application/*+xml | ✅ |
application/*+json (e.g. application/vnd.api+json) | ✅ |
application/x-www-form-urlencoded | ✅ |
application/javascript, application/ecmascript | ✅ |
text/* (plain, html, csv, etc.) | ✅ |
multipart/form-data | ❌ passed through unchanged |
application/octet-stream, image/*, audio/*, video/*, application/pdf | ❌ passed through unchanged |
Safety rules
- Tenant isolation — clients can only reference secrets belonging to their own tenant. A UUID guessed from another tenant will hard-fail.
- Environment-aware — KnoxCall resolves secrets against the route’s active environment. If the secret has no value for that environment, the request fails with a clear error (no silent fallback).
- Size limit — bodies larger than 1 MiB pass through without substitution to protect the proxy (configurable via
BODY_INJECTION_MAX_BYTES). - UTF-8 required — the body must be valid UTF-8 with no NUL bytes; anything else is treated as binary and passed through untouched.
- Hard-fail on missing secrets — referencing a secret that doesn’t exist (or has no value in the active environment) returns an error instead of sending an empty string upstream.
- Logs are scrubbed — audit logs store the body with placeholders intact, never the resolved secret values.
Do I still need headers?
Header injection and body placeholders are independent and can be combined in the same request. Use headers for stable auth (e.g.Authorization: Bearer) and body placeholders for APIs that expect credentials in the payload or for per-call secret selection.
Common Body Patterns
All examples use the recommended UUID form — substitute your actual secret IDs.Simple API key in body (UUID, rename-safe)
Nested objects
Legacy name form (works, but breaks if the secret is renamed)
Multiple secrets in one request
Mixing a secret with a query-string variable
Multiple Secrets in One Route
You can use multiple different secrets in the same route configuration.Example: Multi-Service Integration
Route:notification-service
Headers:
Environment-Specific Secrets
Use different secrets per environment (dev, staging, production).Setup
Create environment-specific secrets:-
Production:
-
Staging:
-
Development:
Configure Route Per Environment
Base environment (production):How to Set Up
- Go to route → Environment tab
- Select “staging”
- Edit Inject Headers:
- Save
- Repeat for “development”
- Production uses:
stripe_prod_key - Staging uses:
stripe_staging_key - Development uses:
stripe_dev_key
Method-Specific Secrets
Different secrets for different HTTP methods on the same route.Example Scenario
Route handles both GET (read) and POST (write) to same API:- GET needs read-only key
- POST needs full-access key
Setup
GET method config:- GET requests use read-only key
- POST requests use full-access key
Secret Resolution Order
When multiple environments and methods are involved, KnoxCall resolves secrets in this order:- Method-specific environment override
- Environment override (if method not specified)
- Base route configuration
Example
Template Syntax Rules
✅ Correct Syntax
- Double curly braces:
{{and}} - Prefix:
secret: - No spaces inside braces
- Lowercase with underscores for secret names
❌ Common Mistakes
Real-World Examples
Example 1: Stripe Payments
Secret:Example 2: SendGrid Email
Secret:Example 3: Database Access
Secret:Example 4: PrintNode Printing
Secret:Example 5: Multi-Service Orchestration
Secrets:Combining Secrets with Other Templates
You can combine secrets with other template variables (coming soon):{{secret:name}}- Inject secrets
{{header:name}}- Pass through headers{{env:name}}- Environment variables{{uuid}}- Generate UUID
Security Considerations
What Gets Logged
In KnoxCall logs:- Template syntax shown:
{{secret:stripe_key}} - Actual value: Never logged
Secret Transmission
Flow:Best Practices
✅ Do:- Use secrets for all sensitive values
- Separate secrets per environment
- Rotate secrets regularly
- Use descriptive secret names
- Document what each secret is for
- Hardcode API keys in route configs
- Use production secrets in development
- Share secrets via email or chat
- Commit secrets to git
- Use generic names like “key” or “secret”
Troubleshooting
Secret Not Replacing
Symptom: Backend receives{{secret:stripe_key}} literally.
Causes:
- Syntax error in template
- Secret doesn’t exist
- Secret name typo
- Check template syntax:
{{secret:name}} - Verify secret exists: Resources → Secrets
- Check spelling matches exactly (case-sensitive)
- Look at logs for error messages
Wrong Value Injected
Symptom: Wrong API key being used. Causes:- Using wrong environment
- Wrong secret name
- Secret not configured for environment
- Check which environment request is using
- Verify environment override has correct secret
- Check secret name spelling
Secret Not Found Error
Error:Secret 'api_key' not found
Solution:
- Go to Resources → Secrets
- Check secret exists
- Verify name matches template exactly
- Check no typos:
api_keyvsapi_key_
Value Not Decrypting
Symptom: Encrypted value sent instead of plaintext. Cause: KnoxCall internal error (very rare). Solution:- Check KnoxCall status
- Try creating new secret version
- Contact support if persists
Testing Secret Injection
Test Endpoint
Use a test endpoint to verify secret injection:-
Create test route:
- Target:
https://httpbin.org/anything - Method: POST
- Target:
-
Add secret in header:
-
Make request:
-
Check response:
Quick Reference
| Use Case | Template Syntax | Example |
|---|---|---|
| Header | {{secret:name}} | "Authorization": "Bearer {{secret:api_key}}" |
| Body | {{secret:name}} | "api_key": "{{secret:api_key}}" |
| Multiple | Multiple templates | {{secret:key1}} and {{secret:key2}} |
| Environment | Different secret per env | Production: {{secret:prod_key}} |
Next Steps
Creating Secrets
How to create and manage secrets
Secrets Overview
Complete secrets guide
Environment Basics
Environment-specific secrets
OAuth2 Flow
Auto-refreshing OAuth2 tokens
Pro Tip: Always test secret injection with a test endpoint (like httpbin.org) before using in production. This lets you verify the actual decrypted value is correct.