Set a request timeout per API route without redeploying
Give API routes different Gregale edge budgets, verify request_budget_exceeded, and update a timeout without deploying again.
Use a per-route execution budget when one API endpoint needs more time than another. Set a short budget for search and leave a longer one for a bounded report, without increasing the timeout for the rest of the app. On Gregale, you can change that budget at the edge without a new deployment.
Download the runnable drill. It gives two endpoints the same two seconds of synthetic work before sending response headers. With different budgets, one fails and the other completes.
1. Set a time budget for each route
gregale edge rule create --app my-api --kind budget --match-host @app \
--match-path /search --match-method GET --budget-ms 1000
gregale edge rule create --app my-api --kind budget --match-host @app \
--match-path /report --match-method GET --budget-ms 4000
These are test thresholds, not recommended production settings. Choose production limits from your own latency and capacity goals. Gregale still enforces your plan's maximum, and an upstream proxy or client can give up sooner. See edge budgets for the difference between the execution budget and a total deadline that includes more of the request path. A curl timer is not the gateway's execution budget.
2. Tell a budget failure from another timeout
Request each endpoint and inspect the response body as well as the status.
On the tested path, the expired Gregale budget returns HTTP 503 with
request_budget_exceeded. A generic 504 does not establish that this rule
fired; check your proxy, the app, and Gregale's error reference.
The drill proves the distinction with a baseline: both endpoints return the app's own JSON before the rules are set. With a one-second search budget, search returns the platform error while report still returns its JSON. Then the drill changes just the search rule:
gregale edge rule update SEARCH_RULE_ID --app my-api --kind budget --budget-ms 4000
Search and report must both return app-owned 200 responses at that point. The script checks that the original deployment remains at 100% traffic. It doesn't call a rollback or deploy a replacement.
3. Keep background work out of the request
A bigger budget can make sense for a bounded, synchronous response. It does not prove that the server stops its work when the request times out. Don't blindly retry a timed-out request that could already have written data. If the work should finish after a client disconnects, schedule it as a background job and expose a separate status endpoint.
To run the drill, install the Gregale CLI, Bash, curl, jq
and OpenSSL. Export a test workspace key as GREGALE_TOKEN, extract the ZIP
and run bash run-demo.sh. It creates one disposable public test app, uses
synthetic data only, and verifies app removal on exit.
Questions
- Can API routes have different request timeouts?
Yes. Set a Gregale budget edge rule for a matching path and method. The rule sets its execution budget up to the plan limit without a new deployment.
- Does a generic 504 mean the edge budget fired?
No. Check the response code and body. The Gregale execution-budget error shown here is HTTP 503 with request_budget_exceeded.
- Does a request timeout guarantee the job stopped?
No. A failed HTTP request is not proof the application canceled its work. Use a job and a durable receipt when work needs to outlive the client.