<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: nRouter</title>
    <description>The latest articles on DEV Community by nRouter (@nrouterai).</description>
    <link>https://dev.to/nrouterai</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4152209%2F1795ed9b-eedb-4cad-989b-5d20855b81f8.png</url>
      <title>DEV Community: nRouter</title>
      <link>https://dev.to/nrouterai</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nrouterai"/>
    <language>en</language>
    <item>
      <title>One Patched Client: Putting an Instructor Workload Behind a Gateway</title>
      <dc:creator>nRouter</dc:creator>
      <pubDate>Fri, 04 Dec 2026 12:23:54 +0000</pubDate>
      <link>https://dev.to/nrouterai/one-patched-client-putting-an-instructor-workload-behind-a-gateway-40o</link>
      <guid>https://dev.to/nrouterai/one-patched-client-putting-an-instructor-workload-behind-a-gateway-40o</guid>
      <description>&lt;p&gt;Every Instructor extraction in a codebase flows through one object: the patched client you build once with &lt;code&gt;instructor.from_openai&lt;/code&gt;. That makes it the natural seam for a gateway. Change the one definition, and every extraction downstream inherits the new behaviour — fallbacks, caching, telemetry — without a single call site being edited.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;openai&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;instructor&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pydantic&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;BaseModel&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Field&lt;/span&gt;

&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;instructor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_openai&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nc"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://api.nrouter.ai/v1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"NROUTER_API_KEY"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;30.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;max_retries&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserProfile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BaseModel&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Full name of the person"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Age in years"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;profile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;completions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"gpt-5.4-mini"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;response_model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;UserProfile&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;max_retries&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Extract: Ada Lovelace, 36"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install line, for completeness: &lt;code&gt;pip install instructor openai pydantic nrouter-sdk&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two retry systems that do not overlap
&lt;/h2&gt;

&lt;p&gt;This is the part people get wrong, so it is worth stating plainly.&lt;/p&gt;

&lt;p&gt;Instructor's &lt;code&gt;max_retries&lt;/code&gt; re-asks the model when the &lt;strong&gt;output&lt;/strong&gt; fails validation. The call worked; the answer had the wrong shape. Retrying with the validation error in view fixes the answer.&lt;/p&gt;

&lt;p&gt;A gateway fallback handles the opposite failure: the &lt;strong&gt;call&lt;/strong&gt; itself failed — provider error, timeout, nothing came back. Re-asking a model that is down does not help, so the gateway swaps models. Fallbacks are named per request in &lt;code&gt;extra_body&lt;/code&gt;, or you hand routing to &lt;code&gt;nrouter/auto&lt;/code&gt; with &lt;code&gt;nrouter_optimize&lt;/code&gt; set to &lt;code&gt;quality&lt;/code&gt;, &lt;code&gt;balanced&lt;/code&gt; or &lt;code&gt;cost&lt;/code&gt; (plus a &lt;code&gt;nrouter_cost_band&lt;/code&gt; under cost).&lt;/p&gt;

&lt;p&gt;Validation retries fix answers. Fallbacks fix calls. Keeping them separate is what makes the pairing clean.&lt;/p&gt;

&lt;h2&gt;
  
  
  Caching the repeats
&lt;/h2&gt;

&lt;p&gt;Document pipelines generate near-identical extractions all day. Pass &lt;code&gt;"nrouter_cache": True&lt;/code&gt; in &lt;code&gt;extra_body&lt;/code&gt; and an exact repeat of an earlier request is answered from cache instead of being generated again.&lt;/p&gt;

&lt;h2&gt;
  
  
  The record on every response
&lt;/h2&gt;

&lt;p&gt;Responses carry &lt;code&gt;x-nr-request-id&lt;/code&gt;, &lt;code&gt;x-nr-model&lt;/code&gt;, &lt;code&gt;x-nr-cost-status&lt;/code&gt; and &lt;code&gt;x-nr-request-cost&lt;/code&gt; — which model answered and what the call settled at, without a separate logging layer. Guardrails run server-side before generation, so a blocked prompt or invalid parameters surface as &lt;code&gt;openai.BadRequestError&lt;/code&gt;; rate limits surface as &lt;code&gt;openai.RateLimitError&lt;/code&gt;, the cue to back off.&lt;/p&gt;

&lt;p&gt;Full walkthrough: the &lt;a href="https://nrouter.ai/docs/frameworks/instructor" rel="noopener noreferrer"&gt;Instructor guide&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>python</category>
      <category>llm</category>
      <category>structuredoutput</category>
      <category>api</category>
    </item>
    <item>
      <title>Traces Describe the Call. They Don't Decide It.</title>
      <dc:creator>nRouter</dc:creator>
      <pubDate>Fri, 04 Dec 2026 10:45:27 +0000</pubDate>
      <link>https://dev.to/nrouterai/traces-describe-the-call-they-dont-decide-it-1jjm</link>
      <guid>https://dev.to/nrouterai/traces-describe-the-call-they-dont-decide-it-1jjm</guid>
      <description>&lt;p&gt;Every LLM stack eventually grows the same accidental architecture: a tracing tool watching the calls, and a layer of hand-written code making them. The tracing tool gets the budget and the polish. The hand-written layer gets the pager.&lt;/p&gt;

&lt;p&gt;A tracing specialist — Langfuse is the clean example — records the calls your code already made. It versions prompts, scores outputs, draws session views. It deliberately does not decide which model made the call, what happens when the provider fails, or who may spend what. Those decisions live in whatever sits in front of it. In most stacks, what sits in front of it is us: routing code, a fallback branch, a table of provider keys, a guardrail regex, a budget check that runs after the invoice.&lt;/p&gt;

&lt;p&gt;Four surfaces, then, beyond the observability bill:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Routing and fallbacks&lt;/strong&gt; — model and provider selection, plus the failure sequence.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Provider auth&lt;/strong&gt; — one key per provider, each with a rotation schedule.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Guardrails&lt;/strong&gt; — screening on the request path, before egress.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Budget enforcement&lt;/strong&gt; — ceilings that bite before the call, at team level.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The gateway shape is what you get when you stop maintaining the four as a side project. The request already flows through the gateway, so the log is written on the path: model, tokens, latency, exact cost per call, prompt and response text out of the log by default. Routing and operator-defined fallback chains are the native function. Guardrails run inline. Budgets are enforced at key, team and organisation level before spend exists. On the gateway this post draws on, all of it — including A/B tests, prompt management and evals — is on every plan, because the vendor's position is that the control surface is the product, not the upsell.&lt;/p&gt;

&lt;p&gt;The migration ledger is the part nobody puts in the brochure, so here it is. Prompt templates export and re-create; their version history stays behind. Prompt variants become A/B arms — a live traffic split across named models, a different mechanism from template variants plus scoring. Eval rubrics re-author; they do not port field-for-field. The historical trace archive does not move: the old instance stays read-only until retention expires. Annotation queues have no equivalent. And if your posture needs an open-source self-host, or tracing that stays vendor-neutral on OpenTelemetry conventions, the specialist is not the layer being replaced — it is the right tool, and this consolidation is the wrong trade.&lt;/p&gt;

&lt;p&gt;The test that settles it is boring and decisive: one non-production route, a week in parallel, the gateway's log and ledger held against the traces and invoices you already trust.&lt;/p&gt;

&lt;p&gt;Full post: &lt;a href="https://nrouter.ai/blog/product/langfuse-alternative" rel="noopener noreferrer"&gt;https://nrouter.ai/blog/product/langfuse-alternative&lt;/a&gt;&lt;/p&gt;

</description>
      <category>llm</category>
      <category>api</category>
      <category>observability</category>
      <category>architecture</category>
    </item>
    <item>
      <title>The Base URL Moves the Traffic. Nothing Moves the Policy.</title>
      <dc:creator>nRouter</dc:creator>
      <pubDate>Thu, 03 Dec 2026 13:28:07 +0000</pubDate>
      <link>https://dev.to/nrouterai/the-base-url-moves-the-traffic-nothing-moves-the-policy-1b0o</link>
      <guid>https://dev.to/nrouterai/the-base-url-moves-the-traffic-nothing-moves-the-policy-1b0o</guid>
      <description>&lt;p&gt;Every gateway migration guide leads with the same two lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;baseURL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'https://api.nrouter.ai/v1'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;// was: your old gateway&lt;/span&gt;
  &lt;span class="n"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;NROUTER_API_KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;    &lt;span class="c1"&gt;// was: the old key&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;True, and incomplete. The base URL moves your traffic. Your policy is not traffic.&lt;/p&gt;

&lt;p&gt;On a proxy-style gateway, policy lives in the request. A &lt;code&gt;models&lt;/code&gt; fallback array in the body. &lt;code&gt;provider&lt;/code&gt; ordering in the body. Spend caps and rate limits pinned to keys. Attribution in headers. Prompt transforms in a middleware chain. That design is coherent — the request carries its own instructions — but it means a migration is not done when the calls succeed. It is done when every instruction has a new home.&lt;/p&gt;

&lt;p&gt;The homes, on a managed gateway, are server-side:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fallback array → fallback chain.&lt;/strong&gt; Defined once in the dashboard instead of repeated in every request body. Changeable without a deploy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Provider ordering → routing policy.&lt;/strong&gt; Versioned, so "what order were we in last Tuesday" has an answer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Per-key caps → budgets.&lt;/strong&gt; Key, team and organisation ceilings. A cap on one key says nothing about the forty keys a team holds.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Attribution headers → cost tags.&lt;/strong&gt; Queryable, not decorative.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Transforms → prompt compression.&lt;/strong&gt; On by default where it qualifies, opt-outs at org/key/request/message level — and a caveat: compression rewrites the prompt the model reads, so token counts move. Budget for it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Two things do not map, and an honest migration plan names them. Bring-your-own-key coverage differs by gateway: a named set of providers is supported with your own keys, everything else is managed on credits, so negotiated provider arrangements do not all survive a move. And the long tail does not map at all — a community model that is not in the live catalogue has no equivalent, and a call that cannot be priced should be reported as unpriced, never silently as zero.&lt;/p&gt;

&lt;p&gt;Why move at all? Usually one of three walls: a percentage fee charged on every credit purchase, a governance surface (guardrails, evals, A/B tests, budgets) the proxy does not ship — which is how a second vendor ends up wedged beside the gateway — or per-provider wiring. And the stay cases are real: broader BYOK needs, a load-bearing long-tail model, an in-VPC requirement.&lt;/p&gt;

&lt;p&gt;The order that works: non-production route first, a week in parallel, the ledger against the old invoice line by line, then production. Two lines move the traffic. The week moves the policy.&lt;/p&gt;

&lt;p&gt;Full post: &lt;a href="https://nrouter.ai/blog/product/openrouter-alternative" rel="noopener noreferrer"&gt;https://nrouter.ai/blog/product/openrouter-alternative&lt;/a&gt;&lt;/p&gt;

</description>
      <category>llm</category>
      <category>api</category>
      <category>infrastructure</category>
      <category>architecture</category>
    </item>
    <item>
      <title>One Model Client: putting an AutoGen team behind a gateway</title>
      <dc:creator>nRouter</dc:creator>
      <pubDate>Thu, 03 Dec 2026 11:05:34 +0000</pubDate>
      <link>https://dev.to/nrouterai/one-model-client-putting-an-autogen-team-behind-a-gateway-oip</link>
      <guid>https://dev.to/nrouterai/one-model-client-putting-an-autogen-team-behind-a-gateway-oip</guid>
      <description>&lt;p&gt;An AutoGen team is a conversation, and every turn of it is a model call. Researcher speaks, critic answers, researcher revises. The calls are small; the run is not. And when each agent file wires up its own client, the operational questions — what did that run cost, what happens when the model errors mid-conversation, what stops a loop — end up answered in five places, or none.&lt;/p&gt;

&lt;p&gt;AutoGen's design gives them one place to live. Agents don't construct their own clients. An &lt;code&gt;AssistantAgent&lt;/code&gt; receives a &lt;code&gt;model_client&lt;/code&gt;, and a whole team can share one. That object is the seam.&lt;/p&gt;

&lt;h2&gt;
  
  
  The one definition
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip install autogen-agentchat autogen-ext&lt;span class="o"&gt;[&lt;/span&gt;openai&lt;span class="o"&gt;]&lt;/span&gt; nrouter-sdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;autogen_ext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;openai&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;OpenAIChatCompletionClient&lt;/span&gt;

&lt;span class="n"&gt;model_client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OpenAIChatCompletionClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"claude-sonnet-4-5-20250929"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"NROUTER_API_KEY"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://api.nrouter.ai/v1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;60.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;max_retries&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;extra_create_args&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"extra_body"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"nrouter_cache"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The model string stays bare — no provider prefix — because the client speaks the OpenAI wire format to the gateway endpoint. Hand this client to every agent and the team's traffic shares one configuration.&lt;/p&gt;

&lt;h2&gt;
  
  
  What doesn't change
&lt;/h2&gt;

&lt;p&gt;The team. &lt;code&gt;AssistantAgent&lt;/code&gt; still takes a name, a system message and the model_client. &lt;code&gt;RoundRobinGroupChat&lt;/code&gt; still takes its turns in order. &lt;code&gt;MaxMessageTermination(max_messages=4)&lt;/code&gt; still ends the conversation, and the run still ends with &lt;code&gt;await team.run(task=...)&lt;/code&gt;. Team design is AutoGen's job and it stays AutoGen's.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the gateway carries
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fallbacks as configuration.&lt;/strong&gt; Per-call overrides ride inside &lt;code&gt;extra_create_args&lt;/code&gt;, in the &lt;code&gt;extra_body&lt;/code&gt;: &lt;code&gt;nrouter_fallbacks&lt;/code&gt; names the chain, or &lt;code&gt;nrouter/auto&lt;/code&gt; with &lt;code&gt;nrouter_optimize&lt;/code&gt; set to &lt;code&gt;quality&lt;/code&gt;, &lt;code&gt;balanced&lt;/code&gt; or &lt;code&gt;cost&lt;/code&gt; (plus &lt;code&gt;nrouter_cost_band&lt;/code&gt; under cost) lets routing decide per call.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A ceiling for the spend, beside the cap on turns.&lt;/strong&gt; &lt;code&gt;MaxMessageTermination&lt;/code&gt; bounds the conversation; it doesn't bound the money. Hard budget ceilings on the virtual key are checked before a call runs, so a team that reaches its ceiling stops with a legible refusal instead of iterating through the weekend.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A record per call.&lt;/strong&gt; Responses carry &lt;code&gt;x-nr-request-id&lt;/code&gt;, &lt;code&gt;x-nr-model&lt;/code&gt;, &lt;code&gt;x-nr-cost-status&lt;/code&gt; and &lt;code&gt;x-nr-request-cost&lt;/code&gt;. Across a run, that's attribution: which model served which turn, at what settled cost.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Typed errors.&lt;/strong&gt; A guardrail block surfaces as &lt;code&gt;openai.BadRequestError&lt;/code&gt;; a rate limit arrives as &lt;code&gt;openai.RateLimitError&lt;/code&gt;, asking for a backoff. The code around the run can tell them apart and react differently.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A team is a workload with a shape — turn-based, bursty, occasionally circular. Governing it at the one client every agent shares is simply meeting the workload where it already gathers.&lt;/p&gt;

&lt;p&gt;Full walkthrough: &lt;a href="https://nrouter.ai/docs/frameworks/autogen" rel="noopener noreferrer"&gt;AutoGen guide&lt;/a&gt;&lt;/p&gt;

</description>
      <category>agents</category>
      <category>python</category>
      <category>ai</category>
      <category>llm</category>
    </item>
    <item>
      <title>Check-then-call is a race condition</title>
      <dc:creator>nRouter</dc:creator>
      <pubDate>Wed, 02 Dec 2026 11:46:51 +0000</pubDate>
      <link>https://dev.to/nrouterai/check-then-call-is-a-race-condition-177g</link>
      <guid>https://dev.to/nrouterai/check-then-call-is-a-race-condition-177g</guid>
      <description>&lt;p&gt;Every credit system starts with the same three lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;estimated_cost&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;        &lt;span class="c1"&gt;# 1. check&lt;/span&gt;
    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 2. act (a round trip)&lt;/span&gt;
    &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="n"&gt;actual_cost&lt;/span&gt;           &lt;span class="c1"&gt;# 3. debit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It passes every test written by a human sending requests one at a time. Under concurrency it overspends — not from a typo or an off-by-one, but because every simultaneous request reaches step 1 before any of them reaches step 3. Each reads the same balance, each concludes there is room, each proceeds, each gets billed. The balance lands below zero.&lt;/p&gt;

&lt;p&gt;Concurrency is the default traffic shape for an LLM gateway — agent swarms, batch pipelines, parallel tool calls. A spend control exercised only serially is unvalidated, not correct.&lt;/p&gt;

&lt;h2&gt;
  
  
  The repairs that still lose
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Debit first, refund after&lt;/strong&gt; — a crash between the two keeps the money.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Serialise everything&lt;/strong&gt; — correct, and no longer a gateway.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reconcile afterwards&lt;/strong&gt; — detects the overspend; the provider has already billed you.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shrink the window&lt;/strong&gt; — a rarer race is a harder-to-reproduce race. Rarity is not safety.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  One indivisible act
&lt;/h2&gt;

&lt;p&gt;Reserve-and-settle makes the check and the commitment the same act. The maximum plausible cost is held against the balance &lt;strong&gt;before&lt;/strong&gt; the provider is contacted. If the hold does not fit, the request is refused immediately (a 402, no provider called, nothing owed). After the call, the hold is replaced by the real cost and the difference returns. On any failure path, the whole hold returns.&lt;/p&gt;

&lt;p&gt;Every hold settles or releases — no third outcome — and both ends are ledger rows, so the balance is the sum of its rows.&lt;/p&gt;

&lt;p&gt;The operative figure becomes &lt;strong&gt;available balance&lt;/strong&gt;: balance minus in-flight holds. It dips during a burst and recovers as calls settle, like a card authorisation hold. The estimate errs high on purpose: over-reserving costs an early, free refusal; under-reserving reopens the race.&lt;/p&gt;

&lt;p&gt;The judgment calls are decided too: an unpriceable completed call settles at its hold rather than becoming free; a guardrail-blocked completion settles because the provider did the work; a fallback takes one hold for the whole attempt; a mid-stream disconnect settles what was generated.&lt;/p&gt;

&lt;p&gt;And the property is testable the only way concurrency properties are: fire many simultaneous requests at a deliberately tiny balance, assert it never went negative, and assert the ledger rows sum to the final balance exactly.&lt;/p&gt;

&lt;p&gt;Full post: &lt;a href="https://nrouter.ai/blog/engineering/reserve-and-settle-credit-safety" rel="noopener noreferrer"&gt;https://nrouter.ai/blog/engineering/reserve-and-settle-credit-safety&lt;/a&gt;&lt;/p&gt;

</description>
      <category>llm</category>
      <category>api</category>
      <category>infrastructure</category>
      <category>cost</category>
    </item>
    <item>
      <title>One LLM Object: putting a CrewAI crew behind a gateway</title>
      <dc:creator>nRouter</dc:creator>
      <pubDate>Wed, 02 Dec 2026 11:31:55 +0000</pubDate>
      <link>https://dev.to/nrouterai/one-llm-object-putting-a-crewai-crew-behind-a-gateway-36an</link>
      <guid>https://dev.to/nrouterai/one-llm-object-putting-a-crewai-crew-behind-a-gateway-36an</guid>
      <description>&lt;p&gt;CrewAI crews have a property that cuts both ways: a single run makes a lot of model calls. Researcher thinks, writer drafts, the writer revises, someone summarises. Each call is small. The run is not. And because the calls fan out from agent definitions scattered through the codebase, the operational questions — what did that run cost, what happens when a model errors mid-task, what stops a loop — tend to have no single place to live.&lt;/p&gt;

&lt;p&gt;Except they do. Agents in CrewAI don't construct their own clients; they receive an &lt;code&gt;LLM&lt;/code&gt; object. That object is the seam.&lt;/p&gt;

&lt;h2&gt;
  
  
  The one definition
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip install crewai nrouter-sdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;crewai&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="no"&gt;LLM&lt;/span&gt;

&lt;span class="n"&gt;llm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;LLM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"openai/claude-sonnet-4-5-20250929"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://api.nrouter.ai/v1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"NROUTER_API_KEY"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;temperature&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;60.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;extra_body&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"nrouter_cache"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"nrouter_fallbacks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"claude-haiku-4-5-20251001"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The model string carries the &lt;code&gt;openai/&lt;/code&gt; prefix because the gateway is reached through CrewAI's OpenAI-compatible path. Hand this &lt;code&gt;llm&lt;/code&gt; to every agent and the crew's traffic shares one configuration.&lt;/p&gt;

&lt;h2&gt;
  
  
  What doesn't change
&lt;/h2&gt;

&lt;p&gt;The crew itself. &lt;code&gt;Agent&lt;/code&gt; still takes a role, a goal, a backstory and the llm. &lt;code&gt;Task&lt;/code&gt; still chains through &lt;code&gt;context&lt;/code&gt;. &lt;code&gt;Crew(agents=[...], tasks=[...], process=Process.sequential)&lt;/code&gt; still ends in &lt;code&gt;crew.kickoff()&lt;/code&gt;. Crew design is CrewAI's job and it stays CrewAI's.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the gateway carries
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fallbacks in &lt;code&gt;extra_body&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;nrouter_fallbacks&lt;/code&gt; names the chain on the object — fallbacks work through that field, not through anything written into the model string. Or use &lt;code&gt;nrouter/auto&lt;/code&gt; with &lt;code&gt;nrouter_optimize&lt;/code&gt; set to &lt;code&gt;quality&lt;/code&gt;, &lt;code&gt;balanced&lt;/code&gt; or &lt;code&gt;cost&lt;/code&gt; (plus &lt;code&gt;nrouter_cost_band&lt;/code&gt; under cost) and let routing decide per call.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A ceiling a loop can hit.&lt;/strong&gt; Spend limits sit on the virtual key, checked before a call runs. A crew that reaches its ceiling gets HTTP 402 with &lt;code&gt;insufficient_credits&lt;/code&gt; — a failure you can catch, log and act on, instead of a quiet weekend of iterating.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A record per call.&lt;/strong&gt; Responses carry &lt;code&gt;x-nr-request-id&lt;/code&gt;, &lt;code&gt;x-nr-model&lt;/code&gt;, &lt;code&gt;x-nr-cost-status&lt;/code&gt; and &lt;code&gt;x-nr-request-cost&lt;/code&gt;. Across a run, that's attribution: which model served which task, at what settled cost.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Errors that say what happened.&lt;/strong&gt; Gateway errors map to HTTP status codes. A guardrail block names itself in the error; the ceiling arrives as 402. The &lt;code&gt;try/except&lt;/code&gt; around &lt;code&gt;kickoff()&lt;/code&gt; can tell them apart.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A crew is a workload with a shape — bursty, multi-step, occasionally loopy. Governing it at the one object every agent shares is simply meeting the workload where it already gathers.&lt;/p&gt;

&lt;p&gt;Full walkthrough: &lt;a href="https://nrouter.ai/docs/frameworks/crewai" rel="noopener noreferrer"&gt;CrewAI guide&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>ai</category>
      <category>llm</category>
      <category>agents</category>
    </item>
    <item>
      <title>Your balance is derived, not stored: reading a credit ledger</title>
      <dc:creator>nRouter</dc:creator>
      <pubDate>Tue, 01 Dec 2026 12:56:18 +0000</pubDate>
      <link>https://dev.to/nrouterai/your-balance-is-derived-not-stored-reading-a-credit-ledger-4oin</link>
      <guid>https://dev.to/nrouterai/your-balance-is-derived-not-stored-reading-a-credit-ledger-4oin</guid>
      <description>&lt;p&gt;Most billing surfaces show you a number and ask you to trust it. A ledger does the opposite: the number is the arithmetic of things that happened, and every one of those things is a row you can point at.&lt;/p&gt;

&lt;p&gt;On a gateway that keeps a credit ledger, the balance is &lt;strong&gt;derived, not stored&lt;/strong&gt; — the running total of a ledger where every movement of value is a row. The practical payoff arrives the first time somebody asks where a small amount went: the answer is a lookup, not a reconstruction.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quote available, not balance
&lt;/h2&gt;

&lt;p&gt;The balance card carries four figures:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Available&lt;/strong&gt; — balance minus in-flight reservations. What you can actually spend right now. Quote this one, always.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lifetime purchased&lt;/strong&gt; — everything ever bought. For reconciling against invoices.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Credits used&lt;/strong&gt; — cumulative draw-down. For explaining the period.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reserved&lt;/strong&gt; — held against requests in flight. For investigating the gap between the other figures.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A dashboard that displays the raw balance overstates spending power by exactly the amount currently in flight — which under load is not a rounding error.&lt;/p&gt;

&lt;h2&gt;
  
  
  Five rows, one mechanism
&lt;/h2&gt;

&lt;p&gt;Every row is one of five: a &lt;strong&gt;top-up&lt;/strong&gt;, a &lt;strong&gt;reservation&lt;/strong&gt; (a hold placed &lt;em&gt;before&lt;/em&gt; the call is forwarded), a &lt;strong&gt;settlement&lt;/strong&gt; (the true-up from the hold to the provider's real cost), a &lt;strong&gt;release&lt;/strong&gt; (the hold handed back because the call never completed), and the platform-fee row — no fee on credit purchases here, and usage settles at the served model's exact list price, which is what makes the per-call figure literally true.&lt;/p&gt;

&lt;p&gt;The ordering is the mechanism. Because the hold precedes the call, two concurrent requests cannot both fit under the same last unit of credit: the first takes it, the second is refused before any provider is contacted. That is why a spend ceiling built on reservations is exact rather than approximate.&lt;/p&gt;

&lt;p&gt;Two consequences surprise people. &lt;strong&gt;One call is often two rows&lt;/strong&gt; — hold plus settlement, netting to the real cost; sum only the negative rows and you overstate spend. &lt;strong&gt;A failed call leaves rows but no cost&lt;/strong&gt; — reservation and release, cancelling — while a request refused at pre-flight (budget, rate limit, guardrail) never reaches a provider and leaves no spend row at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reconcile against the ledger
&lt;/h2&gt;

&lt;p&gt;Two identities: lifetime purchased − credits used = balance, and balance − reserved = available. If both hold, every unit is accounted for.&lt;/p&gt;

&lt;p&gt;When the cost report disagrees slightly, the cause is structural: enforcement runs off the ledger, the charts are drawn from observability logs, and in-flight reservations explain most gaps. Trust the ledger for invoices and budget arguments. And the reporting trap that corrupts more dashboards than any other: when a call cannot be priced, its cost is &lt;strong&gt;absent&lt;/strong&gt;, status unpriced — never a zero. Default absent to zero in your own code and your reports will quietly under-report what the ledger knows.&lt;/p&gt;

&lt;p&gt;The ledger tells you the money moved; the request log — searchable by the request ID on every response — tells you what moved it, with the provider's own token counts. Content is never in the log; metadata is, deliberately.&lt;/p&gt;

&lt;p&gt;Full guide: &lt;a href="https://nrouter.ai/blog/guides/reading-a-spend-ledger" rel="noopener noreferrer"&gt;https://nrouter.ai/blog/guides/reading-a-spend-ledger&lt;/a&gt;&lt;/p&gt;

</description>
      <category>llm</category>
      <category>api</category>
      <category>infrastructure</category>
      <category>cost</category>
    </item>
    <item>
      <title>Two Settings: putting LlamaIndex behind a gateway</title>
      <dc:creator>nRouter</dc:creator>
      <pubDate>Tue, 01 Dec 2026 12:18:50 +0000</pubDate>
      <link>https://dev.to/nrouterai/two-settings-putting-llamaindex-behind-a-gateway-4o5i</link>
      <guid>https://dev.to/nrouterai/two-settings-putting-llamaindex-behind-a-gateway-4o5i</guid>
      <description>&lt;p&gt;LlamaIndex keeps every model it uses in one place: the global &lt;code&gt;Settings&lt;/code&gt; object. &lt;code&gt;Settings.llm&lt;/code&gt; generates, &lt;code&gt;Settings.embed_model&lt;/code&gt; embeds. That single design choice decides how a gateway integrates — not through a plugin or a subclass, but through the two assignments the framework already asks you to make.&lt;/p&gt;

&lt;h2&gt;
  
  
  The two assignments
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip install llama-index-core llama-index-llms-openai llama-index-embeddings-openai nrouter-sdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;llama_index&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;core&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Settings&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;llama_index&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;llms&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;openai&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;llama_index&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;embeddings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;openai&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;OpenAIEmbedding&lt;/span&gt;

&lt;span class="nc"&gt;Settings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;llm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"claude-sonnet-4-5-20250929"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"NROUTER_API_KEY"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;api_base&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://api.nrouter.ai/v1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;60.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;max_retries&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;additional_kwargs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"nrouter_cache"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nc"&gt;Settings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;embed_model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OpenAIEmbedding&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"text-embedding-3-small"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"NROUTER_API_KEY"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;api_base&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://api.nrouter.ai/v1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Generation and embeddings now share one key and one base URL.&lt;/p&gt;

&lt;h2&gt;
  
  
  What doesn't change
&lt;/h2&gt;

&lt;p&gt;Everything downstream. &lt;code&gt;VectorStoreIndex.from_documents(...)&lt;/code&gt; builds the index the usual way, &lt;code&gt;index.as_query_engine(streaming=True)&lt;/code&gt; answers the usual way, and &lt;code&gt;response.response_gen&lt;/code&gt; streams the usual way. The gateway speaks through the OpenAI client classes LlamaIndex already uses, so retrieval code, node parsers and response handling are untouched.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the gateway carries
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fallbacks in &lt;code&gt;additional_kwargs&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;nrouter_fallbacks&lt;/code&gt; names the chain for a call; or use &lt;code&gt;nrouter/auto&lt;/code&gt; with &lt;code&gt;nrouter_optimize&lt;/code&gt; set to &lt;code&gt;quality&lt;/code&gt;, &lt;code&gt;balanced&lt;/code&gt; or &lt;code&gt;cost&lt;/code&gt; (plus &lt;code&gt;nrouter_cost_band&lt;/code&gt; under cost). Retry logic leaves the query path.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Exact-match caching.&lt;/strong&gt; &lt;code&gt;"nrouter_cache": True&lt;/code&gt; lets repeat queries be answered from edge cache. RAG systems get asked the same questions constantly — this is the workload caching was invented for.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;One record per response.&lt;/strong&gt; Generation and embedding calls return &lt;code&gt;x-nr-request-id&lt;/code&gt;, &lt;code&gt;x-nr-model&lt;/code&gt;, &lt;code&gt;x-nr-cost-status&lt;/code&gt; and &lt;code&gt;x-nr-request-cost&lt;/code&gt;. Two bills become one header set.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Errors you already catch.&lt;/strong&gt; A guardrail block is &lt;code&gt;openai.BadRequestError&lt;/code&gt;; a rate limit is &lt;code&gt;openai.RateLimitError&lt;/code&gt;. Guardrails run server-side in the request path, so a blocked call stops before generation, and it arrives as an exception type your handlers already know.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The framework keeps its shape. The two settings carry the operations.&lt;/p&gt;

&lt;p&gt;Full walkthrough: &lt;a href="https://nrouter.ai/docs/frameworks/llamaindex" rel="noopener noreferrer"&gt;LlamaIndex guide&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>llm</category>
      <category>rag</category>
      <category>ai</category>
    </item>
    <item>
      <title>Splitting the AI bill: when the LLM half outgrows the marketplace</title>
      <dc:creator>nRouter</dc:creator>
      <pubDate>Mon, 30 Nov 2026 10:06:55 +0000</pubDate>
      <link>https://dev.to/nrouterai/splitting-the-ai-bill-when-the-llm-half-outgrows-the-marketplace-207</link>
      <guid>https://dev.to/nrouterai/splitting-the-ai-bill-when-the-llm-half-outgrows-the-marketplace-207</guid>
      <description>&lt;p&gt;A multi-service AI platform earns its keep early. One account, one SDK, one invoice, and your product gets text generation, OCR, speech and translation without four vendor evaluations. The trouble starts quietly, when one line on that invoice stops behaving like the others.&lt;/p&gt;

&lt;p&gt;For most teams the line is language. Chat completions grow from a feature into the product's centre of gravity — most of the spend, most of the incidents, and every compliance question — while the controls around them are still the controls a marketplace builds evenly for every task type. Three walls show up, usually in this order.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wall one: governance designed per-task, not per-token
&lt;/h2&gt;

&lt;p&gt;An OCR call and a chat completion do not need the same controls. OCR needs throughput and accuracy. A completion needs a prompt version, an injection check on the input, a PII check on the output, and an eval that tells you whether last week's prompt edit quietly broke four cases while fixing the one you were looking at. Platforms that treat both as "an AI task" build the controls that generalise. The LLM-specific ones arrive last, if they arrive.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wall two: attribution stops at the task type
&lt;/h2&gt;

&lt;p&gt;When language is a small share of the bill, nobody asks which team spent it. When it is most of the bill, somebody does — and the answer they need is per team, per customer, per prompt template. A category total ("text generation was the big line last month") is not attribution. It is a sum wearing a label.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wall three: breadth is a roadmap decision
&lt;/h2&gt;

&lt;p&gt;Keeping many task types normalised across many providers is real, unglamorous engineering work, and it consumes the budget that would otherwise go to routing depth, evals and governance. A focused gateway spends the same budget on one task type. Neither allocation is wrong. They just produce different products two years out, and you are choosing which one to be a customer of.&lt;/p&gt;

&lt;h2&gt;
  
  
  The boundary is the honest part
&lt;/h2&gt;

&lt;p&gt;Splitting does not mean consolidating. What a specialised gateway serves is the generative half:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Served:&lt;/strong&gt; chat and text generation, text-to-speech, speech-to-text.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Not served, permanently:&lt;/strong&gt; OCR and document parsing, image analysis, translation endpoints, sentiment and entity-extraction endpoints.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your OCR client keeps pointing where it points today. Both SDKs living in one codebase is not a transition state; it is the end state, and any comparison that hides that is selling you a rewrite.&lt;/p&gt;

&lt;h2&gt;
  
  
  The switch itself is two lines
&lt;/h2&gt;

&lt;p&gt;Because both sides speak the OpenAI wire format, moving a language call site is a base URL and a key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;baseURL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://api.nrouter.ai/v1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;NROUTER_API_KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Model strings, message arrays, tool calls and streaming consumers do not change. What changes is what sits behind the call: a fallback chain in the router config instead of client-side retry, budget ceilings scoped to an organisation, a team, a user or a single key, virtual keys per downstream customer, and a per-request cost written on the response itself — &lt;code&gt;x-nr-request-id&lt;/code&gt;, &lt;code&gt;x-nr-request-cost&lt;/code&gt;, &lt;code&gt;x-nr-cost-status&lt;/code&gt;. When the cost cannot be computed, the header is absent and the status says &lt;code&gt;unpriced&lt;/code&gt;. It is never reported as zero, because dashboards happily sum zeros into a confident, wrong total.&lt;/p&gt;

&lt;p&gt;One use case deserves a mention because it only exists in the split world: text that came out of a document is the highest-risk input a model in your stack will ever read — unstructured, customer-supplied, and the classic indirect-injection route. An output guardrail on the completion that summarises that text is worth more than one on a chat box, and it is the kind of control a per-token platform builds and a per-task one defers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Do the invoice test before anything else
&lt;/h2&gt;

&lt;p&gt;Pull last month's invoice. Isolate the language line — text generation, plus speech-to-text and text-to-speech if you use them — and set everything else aside entirely. Divide language spend by total AI spend. Under about half, the two-vendor overhead probably is not worth it yet. Well over half, and it is worth pricing properly, including any plan tier you would have to buy to unlock the LLM-side controls you actually need.&lt;/p&gt;

&lt;p&gt;And the stay cases are real: three or more task types in production, a team too small to reconcile two vendors, a model you depend on that the gateway does not serve, or a completed SOC 2 Type II report needed this quarter. A comparison with no losses is an advertisement.&lt;/p&gt;

&lt;p&gt;The full comparison, including the served/not-served table and the move/stay checklists: &lt;a href="https://nrouter.ai/blog/product/eden-ai-alternative" rel="noopener noreferrer"&gt;Eden AI alternative&lt;/a&gt;&lt;/p&gt;

</description>
      <category>llm</category>
      <category>api</category>
      <category>ai</category>
      <category>architecture</category>
    </item>
    <item>
      <title>One provider object: putting the Vercel AI SDK behind a gateway</title>
      <dc:creator>nRouter</dc:creator>
      <pubDate>Mon, 30 Nov 2026 08:20:31 +0000</pubDate>
      <link>https://dev.to/nrouterai/one-provider-object-putting-the-vercel-ai-sdk-behind-a-gateway-3k27</link>
      <guid>https://dev.to/nrouterai/one-provider-object-putting-the-vercel-ai-sdk-behind-a-gateway-3k27</guid>
      <description>&lt;p&gt;The Vercel AI SDK's best design decision is easy to overlook: a model is a provider object you pass in, not a client you construct inside your handlers. That seam is exactly where a gateway fits — and fitting one in takes one file.&lt;/p&gt;

&lt;h2&gt;
  
  
  The file
&lt;/h2&gt;

&lt;p&gt;Install the packages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm install ai @ai-sdk/openai zod
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep a virtual key in &lt;code&gt;.env.local&lt;/code&gt;, then define the provider once:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// lib/ai.ts&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;createOpenAI&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"@ai-sdk/openai"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;nrouter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createOpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;NROUTER_API_KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;baseURL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://api.nrouter.ai/v1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The OpenAI provider accepts a base URL, and the gateway answers at that address in the OpenAI wire format. The SDK's view of the world doesn't move.&lt;/p&gt;

&lt;h2&gt;
  
  
  What doesn't change
&lt;/h2&gt;

&lt;p&gt;The route handler is the standard one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;streamText&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"ai"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;nrouter&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"@/lib/ai"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;POST&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;messages&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;streamText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;nrouter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"gpt-5.4-mini"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messages&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toDataStreamResponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Streaming, the client hooks and the data protocol are untouched, on the Edge Runtime or Node.js.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the gateway carries
&lt;/h2&gt;

&lt;p&gt;Three things that otherwise become application code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fallbacks as data.&lt;/strong&gt; &lt;code&gt;nrouter_fallbacks&lt;/code&gt; in the request body names the chain to try when a model errors. Or call &lt;code&gt;nrouter/auto&lt;/code&gt; and set &lt;code&gt;nrouter_optimize&lt;/code&gt; to &lt;code&gt;quality&lt;/code&gt;, &lt;code&gt;balanced&lt;/code&gt; or &lt;code&gt;cost&lt;/code&gt;, with a cost band when cost wins.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Telemetry without plumbing.&lt;/strong&gt; Every response carries &lt;code&gt;x-nr-request-id&lt;/code&gt;, &lt;code&gt;x-nr-model&lt;/code&gt;, &lt;code&gt;x-nr-cost-status&lt;/code&gt; and &lt;code&gt;x-nr-request-cost&lt;/code&gt;. The per-call record exists because the gateway wrote it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Checks before generation.&lt;/strong&gt; Guardrails run server-side in the request path, so a blocked call stops before tokens are spent on it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Error handling stays idiomatic: an &lt;code&gt;onError&lt;/code&gt; callback on &lt;code&gt;streamText&lt;/code&gt; sees gateway stream errors, and HTTP errors follow the gateway's documented shape.&lt;/p&gt;

&lt;p&gt;Nothing in the app becomes gateway-shaped. You keep the SDK you chose; the routing, fallback and accounting concerns move to the layer whose job they are.&lt;/p&gt;

&lt;p&gt;Full walkthrough: &lt;a href="https://nrouter.ai/docs/frameworks/vercel-ai" rel="noopener noreferrer"&gt;Vercel AI SDK guide&lt;/a&gt;&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>ai</category>
      <category>webdev</category>
      <category>typescript</category>
    </item>
    <item>
      <title>The checks run before the call: an enterprise LLM gateway request path, in order</title>
      <dc:creator>nRouter</dc:creator>
      <pubDate>Fri, 27 Nov 2026 07:53:41 +0000</pubDate>
      <link>https://dev.to/nrouterai/the-checks-run-before-the-call-an-enterprise-llm-gateway-request-path-in-order-kc0</link>
      <guid>https://dev.to/nrouterai/the-checks-run-before-the-call-an-enterprise-llm-gateway-request-path-in-order-kc0</guid>
      <description>&lt;p&gt;Most gateway diagrams start at the router. The part that decides cost and safety sits earlier in the path.&lt;/p&gt;

&lt;p&gt;Here is the request path nRouter's Enterprise LLM Gateway page specifies, in the order it actually runs.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. One key, scoped
&lt;/h2&gt;

&lt;p&gt;Every application authenticates with a single virtual key (&lt;code&gt;sk-nrouter-*&lt;/code&gt;) scoped by organisation, team and key permissions, pointed at one OpenAI-compatible endpoint. Provider credentials live with the gateway. Access becomes a property of the credential, not of whichever codebase holds a secret — which is what makes revocation a one-line operation instead of a scavenger hunt.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Access, before anything
&lt;/h2&gt;

&lt;p&gt;Key permissions and model access rules are verified first. If the key may not use the model, the refusal is a 401 or 403 and no model call ever runs.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Rate limits, before reservation
&lt;/h2&gt;

&lt;p&gt;Key and organisation rate limits are enforced before credits are reserved. A runaway retry loop meets a wall before it meets a balance.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Input guardrails, on the request
&lt;/h2&gt;

&lt;p&gt;Configured input policies are evaluated on the request itself. A block returns HTTP 400 with $0 held and $0 spent, and &lt;code&gt;x-nr-guardrails&lt;/code&gt; reports the outcome: pass, redacted, blocked, monitor, partial, none or unavailable.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. One reservation across fallbacks
&lt;/h2&gt;

&lt;p&gt;A single credit reservation covers the request and its configured fallbacks. An upstream 429, 503 or 529, a connection fault or a first-byte timeout advances to the next fallback under the same reservation. The request settles once, at the served model's list price, and the unused hold is released.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. A log of metadata, not content
&lt;/h2&gt;

&lt;p&gt;Buffered responses return &lt;code&gt;x-nr-request-cost&lt;/code&gt; with &lt;code&gt;x-nr-cost-status: exact&lt;/code&gt;. Streamed responses settle in the request log. The log itself stores request ID, timestamps, served model, token counts, settled charge, latency, routing outcome and guardrail status. Prompt and completion text are not written to it — the prompt goes to the selected provider, after any configured redaction, and the organisation keeps the operational record.&lt;/p&gt;

&lt;p&gt;One honest edge: an output guardrail that blocks after generation still settles for the generated tokens. Pre-call blocks are the free ones; that asymmetry is exactly why the order above matters.&lt;/p&gt;

&lt;p&gt;Full specification: &lt;a href="https://nrouter.ai/product/enterprise-llm-gateway" rel="noopener noreferrer"&gt;https://nrouter.ai/product/enterprise-llm-gateway&lt;/a&gt;&lt;/p&gt;

</description>
      <category>llm</category>
      <category>api</category>
      <category>enterprise</category>
      <category>security</category>
    </item>
    <item>
      <title>The occupancy test: are you buying a gateway, or a platform?</title>
      <dc:creator>nRouter</dc:creator>
      <pubDate>Thu, 26 Nov 2026 10:33:45 +0000</pubDate>
      <link>https://dev.to/nrouterai/the-occupancy-test-are-you-buying-a-gateway-or-a-platform-4k01</link>
      <guid>https://dev.to/nrouterai/the-occupancy-test-are-you-buying-a-gateway-or-a-platform-4k01</guid>
      <description>&lt;p&gt;TrueFoundry's own docs describe its AI Gateway as a proxy layer in front of the model providers — listed alongside model deployment, GPU serving, batch processing, semantic caching, guardrails, observability, prompt management, and agent, MCP and skills registries. That's not a gateway with extras. That's a platform, and the gateway is a room in it.&lt;/p&gt;

&lt;p&gt;The comparison this post draws on starts there, because teams searching for an alternative usually aren't unhappy with the product. They're working out what they bought.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two meters, and a third nobody controls
&lt;/h2&gt;

&lt;p&gt;The platform's published plans meter two things at once: &lt;strong&gt;requests and seats&lt;/strong&gt;. nRouter meters one thing: model spend, settled at the served model's exact list price, no platform fee, no seat count, no request allowance, no key allowance.&lt;/p&gt;

&lt;p&gt;The catch is the third meter. The provider's per-token rate dominates the actual bill, and no gateway plan controls it. Which means a request allowance is &lt;strong&gt;not a spend control&lt;/strong&gt;: a million cheap classification calls and a million long-context reasoning calls consume the same allowance and produce wildly different invoices.&lt;/p&gt;

&lt;p&gt;Converting one meter into the other is only a fair comparison if the gateway is all you want. If you're also deploying models, running GPU workloads and using the agent registry, the platform fee is buying four or five things — and comparing it to a standalone gateway is not honest. Decide what you're buying before you compare prices.&lt;/p&gt;

&lt;p&gt;Two consequences that surprise people late:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Seats are a hard number.&lt;/strong&gt; Governance tools acquire viewers — finance wants the spend view, security wants the audit log, a second team lead wants their own budget page. On a metered plan, every viewer is a plan conversation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keys can be a billing event.&lt;/strong&gt; Where keys are counted in an overage line, a deliberate per-service/per-customer key strategy multiplies a metered quantity. Check your key hygiene isn't a billing event before you design it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The occupancy test
&lt;/h2&gt;

&lt;p&gt;Five yes/no questions, before any feature comparison:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Are you deploying and serving your own models — fine-tuned, open-weights, or classical ML — on infrastructure this vendor manages?&lt;/li&gt;
&lt;li&gt;Do you need GPU orchestration or autoscaling from the same vendor?&lt;/li&gt;
&lt;li&gt;Will you use the agent, MCP or skills registries as your team's &lt;em&gt;actual&lt;/em&gt; registry, not as a demo?&lt;/li&gt;
&lt;li&gt;Do you want experiment tracking and model deployment in the same pane as your LLM calls?&lt;/li&gt;
&lt;li&gt;Is the number of humans who need a login going to stay inside the seat count you're paying for?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Three or more yes:&lt;/strong&gt; you're buying a platform. The gateway is a bundled convenience, and a standalone gateway would be a second bill for a room you already own. Stay.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One or zero:&lt;/strong&gt; you're buying a gateway and paying platform pricing for it. That's the case the comparison is written for.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Two:&lt;/strong&gt; price both explicitly, including the seat line — and check what question 1's answer will be in twelve months. That answer moves more than the others.&lt;/p&gt;

&lt;h2&gt;
  
  
  Budgets: reports, or stops?
&lt;/h2&gt;

&lt;p&gt;One more distinction worth checking in any gateway: does the budget &lt;em&gt;report&lt;/em&gt; or &lt;em&gt;stop&lt;/em&gt;, and what does your caller see when it stops? On the standalone side, ceilings are enforced pre-flight at org, team, user and key scope. A spent org/team/user ceiling answers &lt;strong&gt;402 &lt;code&gt;budget_exceeded&lt;/code&gt;&lt;/strong&gt; — retrying is pointless until someone raises it. A single key's ceiling answers &lt;strong&gt;429 &lt;code&gt;key_budget_exceeded&lt;/code&gt;&lt;/strong&gt; — that key is done for the window while the org is fine, so the caller can fail over instead of storming. And a cost that can't be determined comes back &lt;em&gt;unpriced&lt;/em&gt; — header absent, never zero.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the platform genuinely does better
&lt;/h2&gt;

&lt;p&gt;The comparison prints these itself. &lt;strong&gt;It serves your own models&lt;/strong&gt; — fine-tunes, open-weights on your GPUs, classical ML. That's the whole ballgame; a hosted-catalogue gateway has no story for a checkpoint you trained last week. &lt;strong&gt;A free entry tier&lt;/strong&gt; with a real request allowance. &lt;strong&gt;The registries are ahead&lt;/strong&gt; — shipped surfaces, if your team is standardising how agents discover tools. &lt;strong&gt;Data residency&lt;/strong&gt;: the hybrid mode keeps your prompts and completions in your own object storage while the vendor runs the control plane — if request bodies must never transit a third party's storage, that requirement is dispositive and you should stay.&lt;/p&gt;

&lt;p&gt;And the renewal test it ends on: &lt;em&gt;if you removed the gateway from this contract, would the rest still be worth the price?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Full comparison: &lt;a href="https://nrouter.ai/blog/product/truefoundry-ai-gateway-alternative" rel="noopener noreferrer"&gt;https://nrouter.ai/blog/product/truefoundry-ai-gateway-alternative&lt;/a&gt;&lt;/p&gt;

</description>
      <category>llm</category>
      <category>platform</category>
      <category>infrastructure</category>
      <category>cost</category>
    </item>
  </channel>
</rss>
