zuplo 7.14.5 → 7.14.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/docs/ai-gateway/cookbooks/data-residency.mdx +259 -0
  2. package/docs/ai-gateway/fallback.mdx +6 -4
  3. package/docs/ai-gateway/guardrails.mdx +283 -0
  4. package/docs/ai-gateway/observability/analytics.mdx +121 -0
  5. package/docs/ai-gateway/observability/data-handling.mdx +120 -0
  6. package/docs/ai-gateway/observability/tracing.mdx +203 -0
  7. package/docs/ai-gateway/overview.mdx +6 -4
  8. package/docs/ai-gateway/policies/overview.mdx +4 -0
  9. package/docs/ai-gateway/policy-chains.mdx +10 -3
  10. package/docs/ai-gateway/routing.mdx +277 -0
  11. package/docs/analytics/overview.md +3 -0
  12. package/docs/analytics/tabs/cache.md +89 -0
  13. package/docs/articles/connect-to-aws-alb-with-mtls.mdx +23 -0
  14. package/docs/articles/deployments-and-rollbacks.mdx +93 -0
  15. package/docs/articles/proxy-openai-realtime-api.mdx +247 -0
  16. package/docs/caching/gateway-caching.mdx +2 -1
  17. package/docs/caching/semantic-caching.mdx +133 -0
  18. package/docs/cli/lint.mdx +13 -0
  19. package/docs/cli/variable-delete.mdx +66 -0
  20. package/docs/concepts/source-control-and-deployment.mdx +6 -0
  21. package/docs/concepts/upstream-credentials.mdx +2 -1
  22. package/docs/guides/backend-failover.mdx +117 -0
  23. package/docs/guides/blue-green-deployments.mdx +199 -0
  24. package/docs/handlers/websocket-pipeline-handler.mdx +94 -0
  25. package/docs/mcp-server/authorize-tool-calls.mdx +284 -0
  26. package/docs/mcp-server/overview.mdx +3 -0
  27. package/docs/policies/mcp-capability-filter-inbound/doc.md +81 -0
  28. package/docs/policies/semantic-cache-inbound/doc.md +6 -5
  29. package/docs/policies/semantic-cache-inbound/schema.json +4 -4
  30. package/package.json +5 -5
@@ -0,0 +1,247 @@
1
+ ---
2
+ title: "Cookbook: Proxy the OpenAI Realtime API"
3
+ sidebar_label: OpenAI Realtime API proxy
4
+ description:
5
+ Proxy OpenAI Realtime API WebSocket sessions through Zuplo, keep your OpenAI
6
+ key on the gateway, and end sessions that break your rules with a message
7
+ policy.
8
+ applies_to:
9
+ product: gateway
10
+ hosting: [managed-edge]
11
+ plan: enterprise
12
+ ---
13
+
14
+ The [OpenAI Realtime API](https://platform.openai.com/docs/guides/realtime)
15
+ streams speech and text over a WebSocket. Server-side clients authenticate with
16
+ an `Authorization: Bearer` header that carries an OpenAI API key. This cookbook
17
+ puts a Zuplo route in front of that WebSocket so that:
18
+
19
+ - Clients authenticate with a Zuplo API key, and your OpenAI key stays on the
20
+ gateway.
21
+ - The gateway sets the model in the backend URL, so the model a client puts in
22
+ its own URL has no effect.
23
+ - A message policy ends any session in which the client sends its own
24
+ instructions or a `system` message.
25
+
26
+ <Diagram height="h-48">
27
+ <DiagramNode id="client">Client</DiagramNode>
28
+ <DiagramNode id="zuplo">Zuplo route</DiagramNode>
29
+ <DiagramNode id="openai">OpenAI Realtime API</DiagramNode>
30
+ <DiagramEdge
31
+ from="client"
32
+ to="zuplo"
33
+ label="Authorization: Bearer zpka_..."
34
+ />
35
+ <DiagramEdge from="zuplo" to="openai" label="Authorization: Bearer sk-..." />
36
+ </Diagram>
37
+
38
+ The route uses the
39
+ [WebSocket Pipeline Handler](../handlers/websocket-pipeline-handler.mdx), which
40
+ is an Enterprise feature.
41
+
42
+ ## Prerequisites
43
+
44
+ - A Zuplo project on Managed Edge.
45
+ - An OpenAI API key with access to a Realtime model.
46
+ - An [API Key Authentication](../policies/api-key-inbound.mdx) consumer for each
47
+ client that connects through the gateway.
48
+
49
+ ## 1. Store the OpenAI key and model
50
+
51
+ Add two [environment variables](./environment-variables.mdx) to your project:
52
+
53
+ | Name | Value | Secret |
54
+ | ----------------------- | ------------------------------------------------------ | ------ |
55
+ | `OPENAI_API_KEY` | Your OpenAI API key | Yes |
56
+ | `OPENAI_REALTIME_MODEL` | The Realtime model clients use, such as `gpt-realtime` | No |
57
+
58
+ ## 2. Add the policies
59
+
60
+ Add an API Key policy to authenticate clients, and a Set Headers policy that
61
+ replaces the client's `Authorization` header with your OpenAI key. Add both to
62
+ `config/policies.json`:
63
+
64
+ ```json title="config/policies.json"
65
+ {
66
+ "policies": [
67
+ {
68
+ "name": "api-key-inbound",
69
+ "policyType": "api-key-inbound",
70
+ "handler": {
71
+ "export": "ApiKeyInboundPolicy",
72
+ "module": "$import(@zuplo/runtime)",
73
+ "options": {
74
+ "allowUnauthenticatedRequests": false
75
+ }
76
+ }
77
+ },
78
+ {
79
+ "name": "set-openai-key",
80
+ "policyType": "set-headers-inbound",
81
+ "handler": {
82
+ "export": "SetHeadersInboundPolicy",
83
+ "module": "$import(@zuplo/runtime)",
84
+ "options": {
85
+ "headers": [
86
+ {
87
+ "name": "Authorization",
88
+ "value": "Bearer $env(OPENAI_API_KEY)"
89
+ }
90
+ ]
91
+ }
92
+ }
93
+ }
94
+ ]
95
+ }
96
+ ```
97
+
98
+ The API Key policy runs first and reads the client's Zuplo key from the
99
+ `Authorization` header. The Set Headers policy then overwrites that header, so
100
+ OpenAI receives your OpenAI key and never sees the client's key.
101
+
102
+ ## 3. Write the message policy
103
+
104
+ Create `modules/realtime-policies.ts`. This inbound policy reads each event the
105
+ client sends. Clients can change instructions in several ways: `session.update`,
106
+ `response.create` with its own `instructions`, or a `conversation.item.create`
107
+ that adds a `system` message. The policy checks every event for an
108
+ `instructions` field or a `system`-role item at any depth. When it finds one, it
109
+ closes the client connection, and the handler then closes the connection to
110
+ OpenAI. Every other event passes through unchanged.
111
+
112
+ ```ts title="modules/realtime-policies.ts"
113
+ import { ZuploContext, ZuploRequest } from "@zuplo/runtime";
114
+
115
+ // True when any object in the event sets instructions or adds a system message
116
+ function overridesInstructions(value: unknown): boolean {
117
+ if (Array.isArray(value)) {
118
+ return value.some(overridesInstructions);
119
+ }
120
+ if (value !== null && typeof value === "object") {
121
+ const obj = value as Record<string, unknown>;
122
+ if ("instructions" in obj || obj.role === "system") {
123
+ return true;
124
+ }
125
+ return Object.values(obj).some(overridesInstructions);
126
+ }
127
+ return false;
128
+ }
129
+
130
+ export async function protectInstructions(
131
+ data: string,
132
+ target: WebSocket,
133
+ source: WebSocket,
134
+ request: ZuploRequest,
135
+ context: ZuploContext,
136
+ ) {
137
+ // Forward anything that isn't a JSON event unchanged
138
+ let event: unknown;
139
+ try {
140
+ event = JSON.parse(data);
141
+ } catch {
142
+ return data;
143
+ }
144
+
145
+ if (overridesInstructions(event)) {
146
+ context.log.warn("Client tried to replace the instructions", {
147
+ consumer: request.user?.sub,
148
+ });
149
+ source.send(
150
+ JSON.stringify({
151
+ type: "error",
152
+ error: { message: "This gateway doesn't allow custom instructions." },
153
+ }),
154
+ );
155
+ // `source` is the client connection in an inbound policy
156
+ source.close(4003, "Custom instructions aren't allowed");
157
+ return undefined; // don't forward the event to OpenAI
158
+ }
159
+
160
+ return data;
161
+ }
162
+ ```
163
+
164
+ ## 4. Add the route
165
+
166
+ Add a `GET` route that uses the WebSocket Pipeline Handler. The `rewritePattern`
167
+ sets the model from the environment variable, so the model a client puts in its
168
+ own URL has no effect.
169
+
170
+ ```json title="config/routes.oas.json"
171
+ "/v1/realtime": {
172
+ "x-zuplo-path": {
173
+ "pathMode": "open-api"
174
+ },
175
+ "get": {
176
+ "summary": "OpenAI Realtime API",
177
+ "operationId": "openai-realtime",
178
+ "x-zuplo-route": {
179
+ "corsPolicy": "none",
180
+ "handler": {
181
+ "export": "webSocketPipelineHandler",
182
+ "module": "$import(@zuplo/runtime)",
183
+ "options": {
184
+ "rewritePattern": "wss://api.openai.com/v1/realtime?model=${env.OPENAI_REALTIME_MODEL}",
185
+ "policies": {
186
+ "inbound": [
187
+ {
188
+ "module": "$import(./modules/realtime-policies)",
189
+ "export": "protectInstructions"
190
+ }
191
+ ]
192
+ }
193
+ }
194
+ },
195
+ "policies": {
196
+ "inbound": ["api-key-inbound", "set-openai-key"]
197
+ }
198
+ }
199
+ }
200
+ }
201
+ ```
202
+
203
+ The route-level `policies` run once, when the client opens the connection. The
204
+ `policies` inside `handler.options` run on every message. See
205
+ [Two different policies blocks](../handlers/websocket-pipeline-handler.mdx#configuration).
206
+
207
+ ## 5. Connect a client
208
+
209
+ Connect to your gateway URL with a Zuplo API key instead of an OpenAI key. This
210
+ Node.js example uses the [`ws`](https://www.npmjs.com/package/ws) package:
211
+
212
+ ```ts
213
+ import WebSocket from "ws";
214
+
215
+ const ws = new WebSocket("wss://my-gateway.zuplo.app/v1/realtime", {
216
+ headers: {
217
+ Authorization: `Bearer ${process.env.ZUPLO_API_KEY}`,
218
+ },
219
+ });
220
+
221
+ ws.on("open", () => {
222
+ console.log("Connected through Zuplo");
223
+ });
224
+
225
+ ws.on("message", (message) => {
226
+ console.log(JSON.parse(message.toString()));
227
+ });
228
+
229
+ ws.on("close", (code, reason) => {
230
+ console.log(`Closed: ${code} ${reason.toString()}`);
231
+ });
232
+ ```
233
+
234
+ Replace `my-gateway.zuplo.app` with your gateway's hostname. A request without a
235
+ valid Zuplo API key gets a `401` response and no WebSocket connection. A client
236
+ that sends an event with `instructions`, such as `session.update` or
237
+ `response.create`, receives the error event and then a close with code `4003`.
238
+
239
+ ## Next steps
240
+
241
+ - Add a [Rate Limiting](../policies/rate-limit-inbound.mdx) policy to the
242
+ route-level `inbound` array to limit how many sessions each consumer opens.
243
+ - Run code when a session starts with the
244
+ [`onOpen` connection hook](../handlers/websocket-pipeline-handler.mdx#the-onopen-connection-hook).
245
+ - Read more about message policies in the
246
+ [WebSocket Pipeline Handler](../handlers/websocket-pipeline-handler.mdx)
247
+ reference.
@@ -303,7 +303,8 @@ the traffic they are built for:
303
303
  queries share an entry even when their bodies differ.
304
304
  - [Semantic Cache](../policies/semantic-cache-inbound.mdx) matches requests by
305
305
  meaning rather than exact text, which is what makes caching viable in front of
306
- an LLM.
306
+ an LLM. To keep each tenant's entries apart, see
307
+ [Isolate semantic cache entries by tenant](./semantic-caching.mdx).
307
308
 
308
309
  To cache a fragment of a response rather than all of it, or to drive the cache
309
310
  from your own code, see
@@ -0,0 +1,133 @@
1
+ ---
2
+ title: Isolate semantic cache entries by tenant
3
+ sidebar_label: Semantic cache per tenant
4
+ description:
5
+ Return a cache key and namespace from a custom function so the Semantic Cache
6
+ policy keeps each tenant's cached answers apart, then track hits in analytics.
7
+ applies_to:
8
+ product: gateway
9
+ hosting: all
10
+ plan: enterprise
11
+ ---
12
+
13
+ The [Semantic Cache policy](../policies/semantic-cache-inbound.mdx)
14
+ (`semantic-cache-inbound`) answers a request from an earlier response when the
15
+ new request means the same thing, even when the wording differs. That makes it a
16
+ good fit in front of an LLM or a natural-language search API. When several
17
+ tenants share a route, give each tenant its own **namespace** so that one
18
+ tenant's cached answer never reaches another tenant.
19
+
20
+ A namespace partitions the cache. A lookup only matches entries stored in the
21
+ same namespace, and the policy stores a response in the namespace of the request
22
+ that produced it.
23
+
24
+ ## Set the namespace for each request
25
+
26
+ Set `cacheBy` to `function` and point `cacheByFunction` at a function in your
27
+ project. The policy calls the function on each request. The function returns the
28
+ cache key and, optionally, settings for that request only:
29
+
30
+ | Property | Required | What it does |
31
+ | ---------------------- | -------- | --------------------------------------------------------------------------- |
32
+ | `cacheKey` | Yes | The text the policy compares by meaning, such as the user's question. |
33
+ | `namespace` | No | The partition to look up and store this request in. |
34
+ | `semanticTolerance` | No | How far apart two keys can be and still match. Smaller values match closer. |
35
+ | `expirationSecondsTtl` | No | How many seconds to keep a response that this request stores. |
36
+
37
+ A value the function returns overrides the policy option of the same name for
38
+ that request. A value it leaves out falls back to the policy option. With no
39
+ `namespace` from either, the policy uses the `default` namespace.
40
+
41
+ This function uses the question in the request body as the key and the
42
+ authenticated caller as the namespace:
43
+
44
+ ```ts title="modules/semantic-cache-key.ts"
45
+ import { ZuploContext, ZuploRequest } from "@zuplo/runtime";
46
+
47
+ export async function tenantCacheKey(
48
+ request: ZuploRequest,
49
+ context: ZuploContext,
50
+ policyName: string,
51
+ ) {
52
+ // Clone so the body is still available for the backend
53
+ const body = await request.clone().json();
54
+
55
+ return {
56
+ cacheKey: body.question,
57
+ namespace: `tenant:${request.user?.sub ?? "anonymous"}`,
58
+ };
59
+ }
60
+ ```
61
+
62
+ Read the body from `request.clone()`, as in the example. Reading the original
63
+ request consumes the body before it reaches your backend.
64
+
65
+ If the function throws, or returns no string `cacheKey`, the policy logs an
66
+ error and the request continues to the backend without caching.
67
+
68
+ ## Configure the policy
69
+
70
+ Reference the function in the policy options:
71
+
72
+ ```json title="config/policies.json"
73
+ {
74
+ "name": "semantic-cache",
75
+ "policyType": "semantic-cache-inbound",
76
+ "handler": {
77
+ "export": "SemanticCacheInboundPolicy",
78
+ "module": "$import(@zuplo/runtime)",
79
+ "options": {
80
+ "cacheBy": "function",
81
+ "cacheByFunction": {
82
+ "module": "$import(./modules/semantic-cache-key)",
83
+ "export": "tenantCacheKey"
84
+ },
85
+ "expirationSecondsTtl": 3600,
86
+ "returnCacheStatusHeader": true
87
+ }
88
+ }
89
+ }
90
+ ```
91
+
92
+ Add the policy to the route after your authentication policy, so that the
93
+ function can read `request.user`:
94
+
95
+ ```json title="config/routes.oas.json"
96
+ "policies": {
97
+ "inbound": ["api-key-inbound", "semantic-cache"]
98
+ }
99
+ ```
100
+
101
+ With `returnCacheStatusHeader` set to `true`, every response carries a
102
+ `zp-semantic-cache` header with `HIT` or `MISS`. Set `cacheStatusHeaderName` to
103
+ use a different header name.
104
+
105
+ ## Check the results
106
+
107
+ Send a question twice with one API key, then once with a key for a different
108
+ consumer:
109
+
110
+ | Request | `zp-semantic-cache` |
111
+ | --------------------------------- | ------------------- |
112
+ | Consumer A asks a question | `MISS` |
113
+ | Consumer A asks it again | `HIT` |
114
+ | Consumer B asks the same question | `MISS` |
115
+
116
+ To watch hit rates over time, open
117
+ [**Observability → Analytics**](https://portal.zuplo.com/+/account/project/analytics)
118
+ in your project and select the [Cache](../analytics/tabs/cache.md) section. The
119
+ **Policies** table shows hits, misses, and hit rate for each caching policy.
120
+
121
+ ## AI Gateway apps
122
+
123
+ For traffic through the AI Gateway, use the
124
+ [AI Gateway Semantic Cache](../policies/ai-gateway-semantic-cache-inbound.mdx)
125
+ policy in the app's [policy chain](../ai-gateway/policy-chains.mdx). It keys on
126
+ the prompt for you and keeps each app's cached responses apart, and the tokens
127
+ its hits save appear as **Saved Tokens** in the Cache analytics.
128
+
129
+ ## Related
130
+
131
+ - [Semantic Cache policy reference](../policies/semantic-cache-inbound.mdx)
132
+ - [Cache at the gateway](./gateway-caching.mdx)
133
+ - [Caching overview](./overview.mdx)
package/docs/cli/lint.mdx CHANGED
@@ -73,6 +73,15 @@ applies_to:
73
73
  "required": false,
74
74
  "deprecated": false,
75
75
  "hidden": false
76
+ },
77
+ {
78
+ "name": "list-rules",
79
+ "type": "boolean",
80
+ "description": "List every rule a config can use, with its default severity and the rulesets that include it. Use --format json for machine-readable output.",
81
+ "default": false,
82
+ "required": false,
83
+ "deprecated": false,
84
+ "hidden": false
76
85
  }
77
86
  ]}
78
87
  examples={[
@@ -91,6 +100,10 @@ applies_to:
91
100
  [
92
101
  "$0 lint --format sarif > results.sarif",
93
102
  "Emit SARIF for GitHub Code Scanning"
103
+ ],
104
+ [
105
+ "$0 lint --list-rules",
106
+ "List the rules you can configure"
94
107
  ]
95
108
  ]}
96
109
  usage="$0 lint [options]"
@@ -0,0 +1,66 @@
1
+ ---
2
+ title: "Zuplo CLI: Variable Delete"
3
+ sidebar_label: variable delete
4
+ applies_to:
5
+ product: gateway
6
+ hosting: all
7
+ ---
8
+
9
+ <CliCommand
10
+ command="variable delete"
11
+ description="Deletes a variable from a branch"
12
+ options={[
13
+ {
14
+ "name": "name",
15
+ "type": "string",
16
+ "description": "The name of the variable to delete",
17
+ "required": false,
18
+ "deprecated": false,
19
+ "hidden": false
20
+ },
21
+ {
22
+ "name": "branch",
23
+ "type": "string",
24
+ "description": "The branch where the variable exists",
25
+ "required": false,
26
+ "deprecated": false,
27
+ "hidden": false
28
+ },
29
+ {
30
+ "name": "project",
31
+ "type": "string",
32
+ "description": "The project name",
33
+ "required": false,
34
+ "deprecated": false,
35
+ "hidden": false
36
+ },
37
+ {
38
+ "name": "account",
39
+ "type": "string",
40
+ "description": "The account name",
41
+ "required": false,
42
+ "deprecated": false,
43
+ "hidden": false
44
+ }
45
+ ]}
46
+ examples={[
47
+ [
48
+ "$0 variable delete --name API_KEY --branch main",
49
+ "Delete a variable from the main branch"
50
+ ],
51
+ [
52
+ "$0 variable delete \\\n --name BASE_URL \\\n --branch production \\\n --account my-account \\\n --project my-project",
53
+ "Explicitly specify the account and project"
54
+ ]
55
+ ]}
56
+ usage="$0 variable delete --name <name> --branch <branch> [options]"
57
+ >
58
+
59
+ </CliCommand>
60
+
61
+ ## Global options
62
+
63
+ The following global options are available for all commands:
64
+
65
+ - [`--help`](./global-options.mdx#help)
66
+ - [`--api-key`](./global-options.mdx#api-key)
@@ -234,6 +234,10 @@ The typical workflow from development to production looks like this:
234
234
  4. **Merge** to the default branch. The Production environment updates
235
235
  automatically (GitHub) or via your CI/CD pipeline (other providers).
236
236
 
237
+ Each deployment rolls out without downtime, and a deployment that fails leaves
238
+ the current version serving. To undo a change, redeploy an earlier build. See
239
+ [Deployments and Rollbacks](../articles/deployments-and-rollbacks.mdx).
240
+
237
241
  ## Next steps
238
242
 
239
243
  - [Environments](../articles/environments.mdx) -- Environment types and
@@ -242,4 +246,6 @@ The typical workflow from development to production looks like this:
242
246
  setup guides
243
247
  - [Custom CI/CD](../articles/custom-ci-cd.mdx) -- Build your own deployment
244
248
  pipeline
249
+ - [Deployments and Rollbacks](../articles/deployments-and-rollbacks.mdx) -- How
250
+ deployments roll out and how to roll back
245
251
  - [CLI: deploy](../cli/deploy.mdx) -- Full CLI deploy reference
@@ -68,7 +68,8 @@ suffix — including the ones whose entire purpose is the outbound call, like
68
68
  the direction of the credential. It is not a typo.
69
69
 
70
70
  The `-outbound` policies work on responses. That is where
71
- [Secret Masking](../policies/secret-masking-outbound.mdx) belongs: it redacts
71
+ [Data Loss Prevention - Outbound](../policies/data-loss-prevention-outbound.mdx)
72
+ belongs: with its `secret` recognizers and the `mask` action, it redacts
72
73
  credentials that leaked into a response body before the caller — or an LLM
73
74
  reading the response — ever sees them.
74
75
 
@@ -0,0 +1,117 @@
1
+ ---
2
+ title: Fail Over Between Backends and Regions
3
+ sidebar_label: Backend Failover
4
+ description:
5
+ Keep your API available when a backend or region goes down by putting a
6
+ health-checked load balancer in front of your backends and pointing Zuplo at
7
+ one hostname.
8
+ tags:
9
+ - backends
10
+ - deployment
11
+ applies_to:
12
+ product: gateway
13
+ hosting: all
14
+ ---
15
+
16
+ When your backend runs in more than one region, or you keep a standby copy for
17
+ disaster recovery, requests need to reach a healthy copy when another one fails.
18
+ Handle failover with a load balancer in front of your backends: it checks the
19
+ health of each region and sends traffic only to healthy ones, while Zuplo
20
+ forwards every request to one hostname.
21
+
22
+ :::note
23
+
24
+ The built-in [URL Forward](../handlers/url-forward.mdx) and
25
+ [URL Rewrite](../handlers/url-rewrite.mdx) handlers send each request to the one
26
+ URL you configure. They don't run health checks or fail over between backends,
27
+ so failover belongs in a load balancer in front of your backends.
28
+
29
+ :::
30
+
31
+ ## Put a load balancer in front of your backends
32
+
33
+ Put a service that does health-checked failover in front of your regional
34
+ backends and point Zuplo at its hostname. Examples include AWS Global
35
+ Accelerator, DNS failover routing, and global load balancers from your cloud or
36
+ CDN provider.
37
+
38
+ <Diagram height="h-64">
39
+ <DiagramNode id="gateway" variant="zuplo">
40
+ Zuplo Gateway
41
+ </DiagramNode>
42
+ <DiagramNode id="lb" variant="orange">
43
+ Global load balancer or DNS
44
+ </DiagramNode>
45
+ <DiagramNode id="primary" variant="green">
46
+ Primary region
47
+ </DiagramNode>
48
+ <DiagramNode id="secondary" variant="blue">
49
+ Secondary region
50
+ </DiagramNode>
51
+ <DiagramEdge from="gateway" to="lb" label="api-origin.example.com" />
52
+ <DiagramEdge from="lb" to="primary" label="healthy" />
53
+ <DiagramEdge from="lb" to="secondary" label="on failover" />
54
+ </Diagram>
55
+
56
+ This keeps failover out of the gateway:
57
+
58
+ - **Zuplo configuration stays the same.** Your routes, policies, and backend URL
59
+ don't change when a region fails or recovers.
60
+ - **Failover doesn't wait for a deployment.** The load balancer or DNS service
61
+ moves traffic based on its own health checks, and you can switch regions by
62
+ hand, for testing or planned maintenance, without redeploying the gateway.
63
+ - **Unhealthy regions don't slow requests down.** The service stops sending
64
+ traffic to a failed region, so requests don't wait for a failed attempt first.
65
+
66
+ ### Use a hostname your certificates cover
67
+
68
+ Zuplo verifies the TLS certificate of every backend it calls, so the backend URL
69
+ must use a hostname that the server certificate covers. Create a hostname you
70
+ own, such as `api-origin.example.com`, that points at the load balancer or DNS
71
+ service. Install a server certificate for that hostname on the endpoint in every
72
+ region. Don't use the provider's generated hostname or a static IP address as
73
+ the backend URL, because your regional certificates don't cover them.
74
+
75
+ Store the hostname in an
76
+ [environment variable](../articles/environment-variables.mdx) and read it in
77
+ your route handlers:
78
+
79
+ ```json title="config/routes.oas.json"
80
+ {
81
+ "handler": {
82
+ "export": "urlForwardHandler",
83
+ "module": "$import(@zuplo/runtime)",
84
+ "options": {
85
+ "baseUrl": "${env.BACKEND_URL}"
86
+ }
87
+ }
88
+ }
89
+ ```
90
+
91
+ ### Use the same client certificate in every region
92
+
93
+ If your backends require mutual TLS, Zuplo presents the same
94
+ [client certificate](../articles/securing-backend-mtls.mdx) to whichever region
95
+ receives the request. Configure every region to trust the CA that issued that
96
+ certificate. For AWS load balancers, see
97
+ [Connect to an AWS ALB with mTLS](../articles/connect-to-aws-alb-with-mtls.mdx#use-the-certificate-with-more-than-one-alb).
98
+
99
+ ### Test the secondary region
100
+
101
+ Before you rely on the secondary region, send test traffic to it through a
102
+ [preview environment](../articles/environments.mdx) whose `BACKEND_URL` points
103
+ directly at that region. Production traffic is unaffected. See
104
+ [Testing Preview Environments](../articles/testing-preview-environments.mdx).
105
+
106
+ ## Monitor backend health
107
+
108
+ Add a health check route to your gateway that calls each backend, and point your
109
+ monitoring service at it. You find out about a failed region even when failover
110
+ hides it from your users. See
111
+ [Health Check Handler](../articles/health-checks.mdx).
112
+
113
+ ## Next steps
114
+
115
+ - [Blue-Green Deployments for Your Backend](./blue-green-deployments.mdx)
116
+ - [Route to Different Backends Based on Geolocation](./geolocation-backend-routing.mdx)
117
+ - [Securing your backend](../articles/securing-your-backend.mdx)