An agent, or you, can follow this page by calling the API routes directly with an API key that has the Management scope. The MCP server is optional: it exposes each route below as a tool with the same name.
summarize_profile calls with the results of my last benchmark”. It starts from a completed benchmark: if there is none yet, follow Start a benchmark first.
Before you start: the API key
Every step needs an API key with the Management scope, sent in theAuthorization header, or set in the MCP server’s configuration if the agent uses it. If the agent has none, it asks you to create one at https://app.weflayr.com/api-keys/. It then calls Get API key info (get_api_key_info, which works with a key of any scope) and, if scopes lacks management or the key has expired, asks you for one that has it before going on.
What changes live routing
Set routing strategy, Archive routing strategy and Restore routing strategy change how live calls are routed at once, so the agent asks you before each of them. Every other step only reads.Who it is for
An API key belongs to a project, not to a person. What an agent creates is recorded for the person who created the API key, unless the request names another member of your organization withuser_email. The response says which email was recorded (recorded_for_email): if it is not yours, the agent asks you for the email of a member of your organization and never guesses it.
Technical questions
When the person asks how something works (how models are judged, how the router picks a model, the baseline, prompt caching, fallbacks), answer from the How it works pages rather than guessing: Benchmark-driven routing, Benchmarking, Routing, Prompt caching, Self-heal and Fallback and model health. Give the link of the page you answered from. The agent asks the person twice only: once to confirm the benchmark and the objective (step 1), once to accept the strategy before it changes live routing (step 3). Going through the report is optional.1. Confirm the benchmark and the objective
Use the benchmark the person names. Otherwise Get benchmarks withstatus completed lists them, newest first, without their calls: read each one’s call_names with Get benchmark and propose the latest for their call. Only a completed or archived benchmark has a report. A draft, running or stopped one has none yet: tell the person, point to Start a benchmark to follow it, and stop.
Read its report and its suggested_routing_strategies with Get benchmark. When its blockers say that no optimization objective recommends a model, or that the benchmark offers no model a strategy can route to, tell the person: a strategy made from it would keep their calls on the baseline and save nothing. Then stop. Otherwise ask the person, in one message:
- Which benchmark: the one proposed, with its report’s
url. - Which objective to route for: the objectives the routing strategy page offers, in one line each with its recommended mix, its quality against the baseline and its savings per month. An objective of
suggested_routing_strategieswhoseoffered_objectiveis another one is not offered (Best quality, when it would route as Same cost, best quality). An objective whosedocumentis null cannot be routed for either: none of the benchmark’s deployments can be routed to for it (no longer served, too expensive at today’s prices, or lacking a capability the calls use). Propose the benchmark’s first objective, as the page does, or the one it is offered as. - Whether to go through the results first, or straight to the strategy.
2. Walk through the report (optional)
Only when the person asked for it. The report gives, for each optimization objective, the recommended mix of models with each one’s share, the quality against the baseline, the cost and the savings per month. Get benchmark examples shows the calls behind the figures. Present the report as it measures it: the baseline is production (the model or models that served the calls) or the model picked as baseline, and the judges are the evaluators picked. Do not guess why a result looks good or bad, and show the examples if the person wants to read the answers. A model that matches or beats the baseline at a lower cost is what a benchmark is meant to find.3. Show the strategy and ask the person to accept it
Get benchmark withsuggested_routing_strategies returns, for the objective picked, a strategy document made from the benchmark and ready to push: keep it as it is, named after the call. Its slug is empty, so it is the name made into a slug (lowercase, spaces turned into -) once saved. A slug stays taken by an archived strategy too, and saving a new strategy with a taken slug is refused (409 slug_taken), so first list the strategies with Get routing strategies and status all. When one already has that slug (usually an earlier strategy for the same call), ask the person whether to save the next version of it (its slug in the document, and its live version as expected_version) or to give the new one another name. Saving a version of an archived strategy makes it live again: say so when asking.
In one message, give the person:
- its name and the slug the calls will send as their model (
strategy/<slug>), - the models it routes to,
- what it costs per month and how good its answers are against the baseline, worked out as below. The suggested document leaves out the mix’s models that the gateway no longer serves, that cost too much at today’s prices or that lack a capability the calls use, so work it out from its actual picks rather than assuming it is the objective’s recommendation,
- that saving it changes live routing at once for the calls that send
strategy/<slug>. - what to do with the cache breakpoints their code sends (
cache_controlorprompt_cache_breakpoint), when the document applies the benchmark’s caching (apply_auto_caching_from_benchmark, on in the suggested document). Readuser_cache_breakpointsinsuggested_routing_strategies.routable_modelsfor each model the strategy routes to, overrides included:- any
kept: tell them to keep their breakpoints, naming those models. The cheapest caching the benchmark found on them uses those breakpoints as they are, so removing them makes those models’ calls cost more. - every non-null one
replaced: tell them the gateway replaces their breakpoints with its own on every model, so they can remove them from their code. They must add them back if they later turn the caching off or route to a model whose value iskept. - all null (none of the benchmark’s calls carried breakpoints): say nothing about them.
- any
- when the project’s customers carry tags (Get tags,
customer_tags), a proposal of override rules for the segments they define, for example the customers taggedplan:enterpriserouted for Best quality while the others route for the cheapest. Such a rule is acustomer_selectionoverride rule whoseincluded_customersare the customers Get customers returns for thattag. Say that the list is the one of today: a customer tagged later is not in it until a new version is saved, and the predicted cost covers the global rule only. Route each override rule for an objective that is offered (itsoffered_objectiveis itself, so often not Best quality), give it the global rule’sswitch_from_cached_model_or_cheaper_better_model_condition, and take its allowed deployments from that objective’sdocument.
- Another objective: start from that objective’s own
document, since each objective can route to different deployments. - Other models: a rule routing for an objective cannot allow a deployment listed in that objective’s
not_selectable, which gives thereason(it costs too much against the baseline, or lacks a capability the calls use). Tell the person why instead of adding it. - Fixed order: a
fixed_orderrule takesnullas itsswitch_from_cached_model_or_cheaper_better_model_condition, and a rule routing for an objective needs one (same_or_better_quality_is_unlikelyin the suggested document).
not_selectable), remove them or switch that rule to fixed_order, and tell the person why with the reason. Never save it without their acceptance. Once accepted, Set routing strategy saves it: give the person its url.
Predict what a strategy costs
The agent works the prediction out from thereport of Get benchmark, with no other call. It reads the picks from the strategy’s global_rule and its allowed deployments, counting the deployments of one model once. The benchmark’s figures are per model: objectives[].models[] gives each model’s cost_per_run (mean USD per call) and quality (against the baseline, null for the baseline, which counts as 0% better, 100% same, 0% worse and 100% same or better). A month is calls_per_month calls. The report names a production baseline after the model its calls logged (gpt-4.1-2025-04-14), while the strategy names it after the gateway’s catalog (gpt-4.1): match the strategy’s model whose suggested_routing_strategies entry has baseline true to the report’s model with baseline true. A model’s own figures are read from an objective whose entry for it has full_run true (or baseline true), since the other objectives explored it on a few calls only.
- Baseline: its monthly cost is the
cost_per_runof the model withbaselinetrue, timescalls_per_month. fixed_order: every call goes to the first model, so the prediction is that model’s owncost_per_runtimescalls_per_month, and its ownquality. The calls that fall back to the next models are left out. A first model the report does not list cannot be predicted.- An optimization objective: read the objective of
objectives[]with thatoptimization_objective. Every picked model must be listed in itsmodels, since a strategy routing dynamically only routes to the benchmark’s models. Nothing can be predicted when the objective is not in the report, when itsrecommendationis null, or when a picked model has a nullmix(it is outside the recommended mix, and the gateway never sends it a call under that rule). A nullrecommendationhas two causes: no model held the baseline’s quality (no model has amix), where the gateway keeps every call on the production model, so the strategy saves nothing and the agent suggests not creating it; or the mix was not validated (models have amixbut no call was held back to check it), where the gateway still routes with the mix.- The picks are exactly the models with a
mix: the prediction is therecommendation, itsmonthly_costand itsquality. - The picks are part of the mix: keep the picked models whose
mix.num_callsis above 0 (none left: nothing can be predicted). The cost per call is the mean of theirmix.cost_per_runweighted by theirmix.num_calls, and the quality is the mean of each model’s ownquality(notmix.quality) weighted the same way, each percentage rounded to one decimal. The monthly cost is that cost per call timescalls_per_month. Usemix.cost_per_run, not the model’scost_per_run: the baseline’s holds its model at other reasoning efforts at their own cost. The prediction assumes the router sends each kept model the calls it sent it in the benchmark, which is an approximation.
- The picks are exactly the models with a
4. Send the calls to the strategy
A strategy routes only the calls sent through the Weflayr gateway withstrategy/<slug> as their model. Offer to make that change in the code making the call, keeping or removing its cache breakpoints as step 3 told the person. When the call sends a reasoning effort (reasoning_effort or reasoning.effort), check it is in the routed_reasoning_efforts of a model the rule routes to, in the objective’s models of suggested_routing_strategies: otherwise the gateway refuses every such call (400 reasoning_effort_not_benchmarked). Offer to remove the effort from the call then, so the router picks the effort with the model. If the call does not go through the gateway yet (it is logged with the telemetry SDK, or imported), say so and point to Integrate Weflayr to move it there first.
End with the strategy’s url, which Set routing strategy returns: it opens the strategy on the routing strategies page, so the person can check it there.
5. Read it back and save a new version
Get routing strategy returns the live version’s document and itsversion, and Get routing strategy results the calls it routed by rule and by route. To change it, save the next version with Set routing strategy, passing the version you read as expected_version. Saving a version of an archived strategy makes it live again, so ask the person first.