<!DOCTYPE html><html lang="en" class="inter_1d81deff-module__CYM0aG__variable papermono_89c757f2-module__6aS5zq__variable dark" data-banner-state="visible" data-assistant-state="closed" data-page-mode="none" data-current-path="/"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"/><link rel="preload" href="/docs/_next/static/media/83afe278b6a6bb3c.p.3a6ba036.woff2" as="font" crossorigin="" type="font/woff2"/><link rel="preload" href="/docs/_next/static/media/PaperMono_Variable.p.aa32f7a0.woff2" as="font" crossorigin="" type="font/woff2"/><link rel="preload" href="/docs/_next/static/media/f67ad414ed34149c.p.84166d94.woff2" as="font" crossorigin="" type="font/woff2"/><link rel="preload" as="image" href="https://mintcdn.com/openrouter-d02e98a0/ksNSeB_K7gD-BUDh/assets/logo-v2-light.svg?fit=max&amp;auto=format&amp;n=ksNSeB_K7gD-BUDh&amp;q=85&amp;s=690e45873843519efe02bcbe45795dac"/><link rel="preload" as="image" href="https://mintcdn.com/openrouter-d02e98a0/ksNSeB_K7gD-BUDh/assets/logo-v2-dark.svg?fit=max&amp;auto=format&amp;n=ksNSeB_K7gD-BUDh&amp;q=85&amp;s=8ba2f49b11cd9839c37dd03c62537ebd"/><link rel="stylesheet" href="/docs/_next/static/chunks/462bacc63bed9960.css?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" data-precedence="next"/><link rel="stylesheet" href="/docs/_next/static/chunks/bf5dec8f24f39796.css?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" data-precedence="next"/><style data-precedence="base-ui:low" data-href="base-ui-disable-scrollbar">.base-ui-disable-scrollbar{scrollbar-width:none}.base-ui-disable-scrollbar::-webkit-scrollbar{display:none}</style><link rel="preload" as="script" fetchPriority="low" href="/docs/_next/static/chunks/6d55b684068fd47e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx"/><script src="/docs/_next/static/chunks/44795504c795ca32.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/b5f04601e14032c6.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/f486afc314643ce1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/5b69ece0e92f795e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/turbopack-0141dac0c725f3bf.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/6b1d878389ce54e6.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/ecfd3e69d0bcca28.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/fab73139199c3663.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/cee6f6b26d68395d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/0eb894a8519f24ea.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/fb156bebf42da1e9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/2dd53f5a4cfe6dd5.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/e95beff806b7ab98.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/8a30b6291cd9465f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/893b80a74cde24cd.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/c0e7a98cd764702e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><script src="/docs/_next/static/chunks/ef83d4b60122b4a4.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" async=""></script><link rel="preload" href="https://www.googletagmanager.com/gtag/js?id=G-R8YZRJS2XN" as="script"/><title>API Streaming - Real-time Model Response Integration</title><meta name="application-name" content="OpenRouter | Documentation"/><meta name="generator" content="Mintlify"/><meta name="msapplication-config" content="/docs/_mintlify/favicons/openrouter-d02e98a0/EmhfYwFO2tvnkuV-/_generated/favicon/browserconfig.xml"/><meta name="apple-mobile-web-app-title" content="OpenRouter | Documentation"/><meta name="msapplication-TileColor" content="#7624F4"/><link rel="canonical" href="https://openrouter.ai/docs/api_reference/streaming"/><link rel="alternate" type="application/xml" href="/docs/sitemap.xml"/><link rel="alternate" type="text/markdown" href="/docs/api_reference/streaming.md"/><meta property="og:title" content="API Streaming - Real-time Model Response Integration"/><meta property="og:description" content="Learn how to implement streaming responses with OpenRouter&#x27;s API. Complete guide to Server-Sent Events (SSE) and real-time model outputs."/><meta property="og:url" content="https://openrouter.ai/docs/api_reference/streaming"/><meta property="og:site_name" content="OpenRouter Documentation"/><meta property="og:image" content="https://openrouter.ai/dynamic-og?title=API%20Streaming&amp;description=Real-time%20model%20response%20streaming"/><meta property="og:image:width" content="1200"/><meta property="og:image:height" content="630"/><meta property="og:type" content="website"/><meta name="twitter:card" content="summary_large_image"/><meta name="twitter:title" content="API Streaming - Real-time Model Response Integration"/><meta name="twitter:description" content="Learn how to implement streaming responses with OpenRouter&#x27;s API. Complete guide to Server-Sent Events (SSE) and real-time model outputs."/><meta name="twitter:image" content="https://openrouter.ai/dynamic-og?title=API%20Streaming&amp;description=Real-time%20model%20response%20streaming"/><meta name="twitter:image:width" content="1200"/><meta name="twitter:image:height" content="630"/><link rel="icon" href="/docs/_mintlify/favicons/openrouter-d02e98a0/EmhfYwFO2tvnkuV-/_generated/favicon/android-chrome-192x192.png" type="image/png" sizes="192x192" media="(prefers-color-scheme: light)"/><link rel="apple-touch-icon" href="/docs/_mintlify/favicons/openrouter-d02e98a0/EmhfYwFO2tvnkuV-/_generated/favicon/apple-touch-icon.png" type="image/png" sizes="180x180"/><link rel="icon" href="/docs/_mintlify/favicons/openrouter-d02e98a0/EmhfYwFO2tvnkuV-/_generated/favicon/favicon-16x16.png" type="image/png" sizes="16x16" media="(prefers-color-scheme: light)"/><link rel="icon" href="/docs/_mintlify/favicons/openrouter-d02e98a0/EmhfYwFO2tvnkuV-/_generated/favicon/favicon-32x32.png" type="image/png" sizes="32x32" media="(prefers-color-scheme: light)"/><link rel="shortcut icon" href="/docs/_mintlify/favicons/openrouter-d02e98a0/EmhfYwFO2tvnkuV-/_generated/favicon/favicon.ico" type="image/x-icon" media="(prefers-color-scheme: light)"/><link rel="icon" href="/docs/_mintlify/favicons/openrouter-d02e98a0/EmhfYwFO2tvnkuV-/_generated/favicon-dark/android-chrome-192x192.png" type="image/png" sizes="192x192" media="(prefers-color-scheme: dark)"/><link rel="icon" href="/docs/_mintlify/favicons/openrouter-d02e98a0/EmhfYwFO2tvnkuV-/_generated/favicon-dark/favicon-16x16.png" type="image/png" sizes="16x16" media="(prefers-color-scheme: dark)"/><link rel="icon" href="/docs/_mintlify/favicons/openrouter-d02e98a0/EmhfYwFO2tvnkuV-/_generated/favicon-dark/favicon-32x32.png" type="image/png" sizes="32x32" media="(prefers-color-scheme: dark)"/><link rel="shortcut icon" href="/docs/_mintlify/favicons/openrouter-d02e98a0/EmhfYwFO2tvnkuV-/_generated/favicon-dark/favicon.ico" type="image/x-icon" media="(prefers-color-scheme: dark)"/><link rel="preconnect" href="https://fonts.googleapis.com"/><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="anonymous"/><link rel="preconnect" href="https://fonts.googleapis.com"/><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="anonymous"/><link rel="preload" href="https://d4tuoctqmanu0.cloudfront.net/katex.min.css" as="style"/><script type="text/javascript">!function(){var b="/docs";
function a(p){if(p==null)return"/";p=""+p;if(""===p)return"/";return"/"===p.charAt(0)?p:"/"+p}
function u(p){if(p==null)return p;p=""+p;if(!p||p.charAt(p.length-1)==="/")return p.slice(0,-1);return p}
function i(p){if(p==null)return p;p=""+p;if(6<=p.length&&p.substring(p.length-6)==="/index")return p.substring(0,p.length-6);if("index"===p)return"";return p}
var p=(location.pathname||"").split("?")[0].split("#")[0]||"";
if(b)if(p===b)p="";else if(0===p.indexOf(b+"/"))p=p.substring(b.length);
p=a(p);p=u(p);p=i(p);p=""===p||"index"===p?"/":a(p);
document.documentElement.setAttribute("data-current-path",p);
}();</script><script type="text/javascript">(() => {
  const isIOS =
    /iP(hone|ad|od)/.test(navigator.userAgent) ||
    (/Macintosh/.test(navigator.userAgent) && navigator.maxTouchPoints > 1);
  if (!isIOS) return;
  const apply = () => {
    for (const meta of document.querySelectorAll('meta[name="viewport"]')) {
      const content = meta.getAttribute('content') || '';
      if (!content.includes('maximum-scale')) {
        meta.setAttribute('content', content + ', maximum-scale=1');
      }
    }
  };
  apply();
  new MutationObserver(apply).observe(document.head, {
    childList: true,
    subtree: true,
    attributes: true,
    attributeFilter: ['content'],
  });
})();</script><script type="text/javascript">!function(){
function read(){try{
var e=performance.getEntriesByType?performance.getEntriesByType("navigation"):[];
var st=(e[0]&&e[0].serverTiming)||[];
var g={};
for(var i=0;i<st.length;i++){var n=st[i].name,d=st[i].description;if(!d)continue;try{d=decodeURIComponent(d)}catch(x){}
if(n==="country")g.country=d;else if(n==="region")g.region=d;else if(n==="continent")g.continent=d;}
var w=window;w.mintlify=w.mintlify||{};w.mintlify.geo=g;
}catch(x){}}
read();document.addEventListener("DOMContentLoaded",read);
}();</script><script type="text/javascript">!function(){try{
var w=window;w.mintlify=w.mintlify||{};
var q=w.mintlify.__apiPlaygroundInputsQueue;
if(!Array.isArray(q)){q=[];w.mintlify.__apiPlaygroundInputsQueue=q;}
w.mintlify.api=w.mintlify.api||{};
w.mintlify.api.playground=w.mintlify.api.playground||{};
if(typeof w.mintlify.api.playground.setServerVariables!=="function"){
w.mintlify.api.playground.setServerVariables=function(v){q.push({type:"set",variables:v});};
}
if(typeof w.mintlify.api.playground.clearServerVariables!=="function"){
w.mintlify.api.playground.clearServerVariables=function(){q.push({type:"clear"});};
}
}catch(e){}}();</script><script type="text/javascript">(function(a,b){try{let c=document.getElementById("banner")?.innerText;if(c){for(let d=0;d<localStorage.length;d++){let e=localStorage.key(d);if(e?.endsWith(a)&&localStorage.getItem(e)===c)return void document.documentElement.setAttribute(b,"hidden")}document.documentElement.setAttribute(b,"visible");return}for(let c=0;c<localStorage.length;c++){let d=localStorage.key(c);if(d?.endsWith(a)&&localStorage.getItem(d))return void document.documentElement.setAttribute(b,"hidden")}document.documentElement.setAttribute(b,"visible")}catch(a){document.documentElement.setAttribute(b,"hidden")}})(
  "bannerDismissed",
  "data-banner-state",
)</script><script src="/docs/_next/static/chunks/a6dad97d9634a72d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" noModule=""></script></head><body class="antialiased"><div hidden=""><!--$--><!--/$--></div><script>((a,b,c,d,e,f,g,h)=>{let i=document.documentElement,j=["light","dark"];function k(b){var c;(Array.isArray(a)?a:[a]).forEach(a=>{let c="class"===a,d=c&&f?e.map(a=>f[a]||a):e;c?(i.classList.remove(...d),i.classList.add(f&&f[b]?f[b]:b)):i.setAttribute(a,b)}),c=b,h&&j.includes(c)&&(i.style.colorScheme=c)}if(d)k(d);else try{let a=localStorage.getItem(b)||c,d=g&&"system"===a?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":a;k(d)}catch(a){}})("class","isDarkMode","dark",null,["dark","light","true","false","system"],{"true":"dark","false":"light","dark":"dark","light":"light"},true,false)</script><script>(function(){try{var f=null;var v=f||localStorage.getItem("isDarkMode");if(v==='true')v='dark';else if(v==='false')v='light';if(v!=='light'&&v!=='dark'&&v!=='system')v="dark";document.documentElement.setAttribute("data-theme-preference",v)}catch(e){}})();</script><blockquote class="sr-only" data-agent-docs-index="true" aria-hidden="true"><h2>Documentation Index</h2><p>Fetch the complete documentation index at:<!-- --> <a href="/docs/llms.txt" tabindex="-1">/docs/llms.txt</a></p><p>Use this file to discover all available pages before exploring further.</p></blockquote><style>:root{--banner-height:0px!important}</style><script id="_mintlify-banner-script">(function i(a,b,c,d,e){try{let f,g,h=[];try{h=window.location.pathname.split("/").filter(a=>""!==a&&"global"!==a).slice(0,2)}catch{h=[]}let i=h.find(a=>c.includes(a)),j=[];for(let c of(i?j.push(i):j.push(b),j.push("global"),j)){if(!c)continue;let b=a[c];if(b?.content){f=b.content,g=c;break}}if(!f)return void document.documentElement.setAttribute(d,"hidden");let k=!0,l=0;for(;l<localStorage.length;){let a=localStorage.key(l);if(l++,!a?.endsWith(e))continue;let b=localStorage.getItem(a);if(b&&b===f){k=!1;break}g&&(a.startsWith(`lang:${g}_`)||!a.startsWith("lang:"))&&(localStorage.removeItem(a),l--)}document.documentElement.setAttribute(d,k?"visible":"hidden")}catch(a){console.error(a),document.documentElement.setAttribute(d,"hidden")}})(
  {},
  "en",
  [],
  "data-banner-state",
  "bannerDismissed",
)</script><link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:ital,wght@0,400;1,400&amp;display=swap" rel="stylesheet"/><link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:ital,wght@0,400;1,400&amp;display=swap" rel="stylesheet"/><style>:root {
  --font-family-headings-custom: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-weight-headings-custom: 400;
  --font-family-body-custom: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-weight-body-custom: 400;
  
}
</style><style>:root {
    --primary: 118 36 244;
    --primary-light: 118 36 244;
    --primary-dark: 200 255 0;
    --tooltip-foreground: 0 0 0;
    --background-light: 252 252 254;
    --background-dark: 3 8 10;
    --gray-50: 246 243 250;
    --gray-100: 241 239 245;
    --gray-200: 226 223 229;
    --gray-300: 209 207 213;
    --gray-400: 162 159 165;
    --gray-500: 115 113 119;
    --gray-600: 83 81 87;
    --gray-700: 66 63 70;
    --gray-800: 40 38 44;
    --gray-900: 26 23 30;
    --gray-950: 13 11 17;
  }</style><script type="text/javascript">
          (function() {
            function loadKatex() {
              const link = document.querySelector('link[href="https://d4tuoctqmanu0.cloudfront.net/katex.min.css"]');
              if (link) link.rel = 'stylesheet';
            }
            if (document.readyState === 'loading') {
              document.addEventListener('DOMContentLoaded', loadKatex);
            } else {
              loadKatex();
            }
          })();
        </script><div class="relative antialiased text-gray-500 dark:text-gray-400 [[&amp;_:is(h1,h2,h3,h4,h5,h6)]:font-headingsWeight [&amp;_*:not(h1,h2,h3,h4,h5,h6,strong,b,h1_*,h2_*,h3_*,h4_*,h5_*,h6_*,strong_*,b_*)]:font-bodyWeight"><script id="_mintlify-navbar-transition-script">(function(a){let b,c=(b="navbar-transition","maple"===a&&(b+="-maple"),b);function d(){let a=!1;a=window.scrollY>50;let b=document.getElementById(c);b&&b.hasAttribute("data-is-opaque")&&b.setAttribute("data-is-opaque",`${!!a}`)}let e=function(){let a=document.createElement("style"),b=`#${c}`;return a.appendChild(document.createTextNode(`${b},${b} *,${b} *::before,${b} *::after{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}`)),document.head.appendChild(a),function(){window.getComputedStyle(document.body),setTimeout(()=>{document.head.removeChild(a)},1)}}();function f(){window.removeEventListener("scroll",d),document.removeEventListener("DOMContentLoaded",d),d(),e()}window.addEventListener("scroll",d,{passive:!0}),document.addEventListener("DOMContentLoaded",d),("requestAnimationFrame"in globalThis?requestAnimationFrame:setTimeout)(d),"complete"===document.readyState?f():window.addEventListener("load",f,{once:!0})})("mint")</script><script id="_mintlify-scroll-margin-script">(function () {
  var measure = function(){let a=document.querySelectorAll("[id='navbar'], [data-top-chrome]"),b=0;a.forEach(a=>{let c=a.getBoundingClientRect();c.height>0&&(b=Math.max(b,c.bottom))});let c=0,d=document.getElementById("content-container");if(d){let{overflowY:a}=getComputedStyle(d);("auto"===a||"scroll"===a)&&(c=Math.max(0,d.getBoundingClientRect().top))}let e=`${Math.round(Math.max(0,b-c))+40}px`,f=document.documentElement.style;f.getPropertyValue("--scroll-mt")!==e&&f.setProperty("--scroll-mt",e)};
  (function(a){let b=[],c=0,d="undefined"==typeof ResizeObserver?null:new ResizeObserver(f);function e(){let c=Array.from(document.querySelectorAll("[id='navbar'], [data-top-chrome]"));(c.length!==b.length||c.some((a,c)=>a!==b[c]))&&d&&(d.disconnect(),c.forEach(a=>d.observe(a))),b=c,a()}function f(){c||(c=requestAnimationFrame(()=>{c=0,e()}))}let g="[id='navbar'], [data-top-chrome]";function h(a){let b=a.target;if(b instanceof Element&&b.closest(g))return!0;for(let b of a.addedNodes)if(b instanceof Element&&(b.matches(g)||b.querySelector(g)))return!0;for(let b of a.removedNodes)if(b instanceof Element&&(b.matches(g)||b.querySelector(g)))return!0;return!1}new MutationObserver(a=>{a.some(h)&&f()}).observe(document.documentElement,{childList:!0,subtree:!0}),window.addEventListener("resize",f),"loading"===document.readyState&&document.addEventListener("DOMContentLoaded",e),e()})(measure);
  (function(a){let b=window.location.hash.slice(1);if(!b)return;function c(){return"smooth"===getComputedStyle(document.documentElement).scrollBehavior}function d(c){let d=document.getElementById(b);return!!d&&(a(),d.scrollIntoView(c?{behavior:c}:void 0),!0)}if("complete"===document.readyState)return void d();let e=new MutationObserver(()=>{!c()&&d("instant")&&f()});function f(){e.disconnect(),window.removeEventListener("load",g)}function g(){let a=c();f(),a&&requestAnimationFrame(()=>{d(),function(){let a=["wheel","touchstart","keydown","pointerdown"],c=0,e=window.scrollY,f=setInterval(()=>{c+=1;let a=document.getElementById(b);if(!a||c>=6)return g();let f=Math.abs(window.scrollY-e)>1;if(e=window.scrollY,f)return;let h=parseFloat(getComputedStyle(a).scrollMarginTop)||0;Math.abs(a.getBoundingClientRect().top-h)>4&&d()},350);function g(){clearInterval(f),a.forEach(a=>window.removeEventListener(a,g))}a.forEach(a=>window.addEventListener(a,g,{passive:!0}))}()})}window.addEventListener("load",g),e.observe(document.documentElement,{childList:!0,subtree:!0}),!c()&&d("instant")&&f()})(measure);
})();</script><a href="#content-area" class="sr-only focus:not-sr-only focus:fixed focus:top-2 focus:left-2 focus:z-50 focus:p-2 focus:text-sm focus:bg-background-light dark:focus:bg-background-dark focus:rounded-md focus:outline-primary dark:focus:outline-primary-light">Skip to main content</a><script>(function i(a,b,c,d){try{if(window.matchMedia("(max-width: 1024px)").matches||!d){document.documentElement.style.setProperty(c,"0px"),document.documentElement.setAttribute("data-assistant-state","closed"),d||localStorage.setItem(a,"false");return}let e=localStorage.getItem(a);if(null===e){document.documentElement.style.setProperty(c,"0px"),document.documentElement.setAttribute("data-assistant-state","closed");return}let f=JSON.parse(e),g=localStorage.getItem(b),h=null!==g?JSON.parse(g):368;document.documentElement.style.setProperty(c,f?h+"px":"0px"),document.documentElement.setAttribute("data-assistant-state",f?"open":"closed")}catch(a){document.documentElement.style.setProperty(c,"0px"),document.documentElement.setAttribute("data-assistant-state","closed")}})(
    "chat-assistant-sheet-open",
    "chat-assistant-sheet-width",
    "--assistant-sheet-width",
    true
  )</script><div class="max-lg:contents lg:flex lg:w-full" data-docs-theme="mint"><div class="max-lg:contents lg:flex-1 lg:min-w-0 lg:overflow-x-clip"><header id="navbar" class="z-30 fixed lg:sticky top-0 w-full peer is-not-custom peer is-not-center peer is-not-wide peer is-not-frame"><div id="navbar-transition" class="absolute w-full h-full flex-none transition-colors duration-500 border-b border-gray-500/5 dark:border-gray-300/[0.06] bg-background-light dark:bg-background-dark" data-is-opaque="false"></div><div class="max-w-8xl mx-auto relative"><div><div class="relative"><div class="flex items-center lg:px-12 h-16 min-w-0 mx-4 lg:mx-0"><div class="h-full relative flex-1 flex items-center gap-x-4 min-w-0 border-b border-gray-500/5 dark:border-gray-300/[0.06]"><div class="flex-1 flex items-center gap-x-4"><a class="select-none" style="-webkit-touch-callout:none" href="https://openrouter.ai"><span class="sr-only">OpenRouter | Documentation<!-- --> home page</span><img class="nav-logo w-auto h-7 relative object-contain shrink-0 block dark:hidden" src="https://mintcdn.com/openrouter-d02e98a0/ksNSeB_K7gD-BUDh/assets/logo-v2-light.svg?fit=max&amp;auto=format&amp;n=ksNSeB_K7gD-BUDh&amp;q=85&amp;s=690e45873843519efe02bcbe45795dac" alt="light logo"/><img class="nav-logo w-auto h-7 relative object-contain shrink-0 hidden dark:block" src="https://mintcdn.com/openrouter-d02e98a0/ksNSeB_K7gD-BUDh/assets/logo-v2-dark.svg?fit=max&amp;auto=format&amp;n=ksNSeB_K7gD-BUDh&amp;q=85&amp;s=8ba2f49b11cd9839c37dd03c62537ebd" alt="dark logo"/></a><div class="hidden lg:flex items-center gap-x-2"></div></div><div class="relative hidden lg:flex items-center flex-1 z-20 gap-2.5"><button type="button" class="group/search flex pointer-events-auto rounded-xl w-full items-center text-sm leading-6 h-9 pl-3.5 pr-3 text-gray-500 dark:text-white/50 bg-background-light dark:bg-background-dark dark:brightness-[1.1] dark:ring-1 dark:hover:brightness-[1.25] ring-1 ring-gray-400/30 hover:ring-gray-600/30 dark:ring-gray-600/30 dark:hover:ring-gray-500/30 justify-between truncate gap-2" id="search-bar-entry" aria-label="Open search"><div class="flex items-center gap-2"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-4 min-w-4 flex-none text-gray-700 group-hover/search:text-gray-800 dark:text-gray-400 dark:group-hover/search:text-gray-200"><path d="M15.25 15.25L11.285 11.285" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M7.75 12.75C10.5114 12.75 12.75 10.5114 12.75 7.75C12.75 4.98858 10.5114 2.75 7.75 2.75C4.98858 2.75 2.75 4.98858 2.75 7.75C2.75 10.5114 4.98858 12.75 7.75 12.75Z" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg><div class="truncate min-w-0">Search...</div></div><span class="flex-none text-xs font-semibold">⌘<!-- -->K</span></button><button type="button" class="group/ai flex-none hidden lg:flex items-center justify-center gap-1.5 pl-3 pr-3.5 h-9 rounded-xl bg-background-light dark:bg-background-dark dark:brightness-[1.1] dark:ring-1 dark:hover:brightness-[1.25] ring-1 ring-gray-400/30 hover:ring-gray-600/30 dark:ring-gray-600/30 dark:hover:ring-gray-500/30" id="assistant-entry" aria-label="Toggle assistant panel"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-4 shrink-0 text-gray-700 group-hover/ai:text-gray-800 dark:text-gray-400 dark:group-hover/ai:text-gray-200"><path d="M5.65799 2.99L4.39499 2.569L3.97399 1.306C3.83699 0.898 3.16199 0.898 3.02499 1.306L2.60399 2.569L1.34099 2.99C1.13699 3.058 0.998993 3.249 0.998993 3.464C0.998993 3.679 1.13699 3.87 1.34099 3.938L2.60399 4.359L3.02499 5.622C3.09299 5.826 3.28499 5.964 3.49999 5.964C3.71499 5.964 3.90599 5.826 3.97499 5.622L4.39599 4.359L5.65899 3.938C5.86299 3.87 6.00099 3.679 6.00099 3.464C6.00099 3.249 5.86199 3.058 5.65799 2.99Z" fill="currentColor" stroke="none"></path><path d="M9.5 2.75L11.412 7.587L16.25 9.5L11.412 11.413L9.5 16.25L7.587 11.413L2.75 9.5L7.587 7.587L9.5 2.75Z" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg><span class="text-sm text-gray-500 dark:text-white/50 whitespace-nowrap">Ask Assistant</span><span class="flex-none text-xs font-semibold">⌘<!-- -->I</span></button></div><div class="flex-1 relative hidden lg:flex items-center ml-auto justify-end space-x-4"><nav aria-label="Main" class="text-sm"><ul class="flex space-x-6 items-center"><li class="navbar-link"><a href="https://openrouter.ai/models" class="flex items-center gap-1.5 whitespace-nowrap font-medium text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" target="_blank" rel="noopener noreferrer"><span class="min-w-0 truncate">Models</span></a></li><li class="navbar-link"><a href="https://openrouter.ai/benchmarks" class="flex items-center gap-1.5 whitespace-nowrap font-medium text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" target="_blank" rel="noopener noreferrer"><span class="min-w-0 truncate">Benchmarks</span></a></li><li class="navbar-link"><a href="https://openrouter.ai/chat" class="flex items-center gap-1.5 whitespace-nowrap font-medium text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" target="_blank" rel="noopener noreferrer"><span class="min-w-0 truncate">Chat</span></a></li><li class="navbar-link"><a href="https://openrouter.ai/rankings" class="flex items-center gap-1.5 whitespace-nowrap font-medium text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" target="_blank" rel="noopener noreferrer"><span class="min-w-0 truncate">Rankings</span></a></li><li class="navbar-link"><a href="https://openrouter.ai/apps" class="flex items-center gap-1.5 whitespace-nowrap font-medium text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" target="_blank" rel="noopener noreferrer"><span class="min-w-0 truncate">Apps</span></a></li><li class="block lg:hidden"><a class="flex items-center gap-1.5 whitespace-nowrap font-medium text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" href="https://openrouter.ai/sign-in"><span class="min-w-0 truncate">Sign In</span></a></li><li class="whitespace-nowrap hidden lg:flex" id="topbar-cta-button"><a target="_blank" rel="noopener noreferrer" class="group pl-3 pr-2 py-2 relative inline-flex items-center text-sm font-medium" href="https://openrouter.ai/sign-in"><span class="absolute inset-0 bg-primary-dark rounded-xl group-hover:opacity-[0.9]"></span><div class="z-10 gap-1 flex items-center"><span class="text-white">Sign In</span><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-3 shrink-0 text-white/90"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></a></li></ul></nav><div class="flex items-center"><button type="button" tabindex="0" aria-haspopup="menu" id="theme-preference-menu-trigger" aria-label="Change theme preference" data-component-name="theme-preference-menu" data-component-part="theme-preference-menu-trigger" data-testid="theme-preference-menu-trigger" class="group disabled:pointer-events-none rounded-lg overflow-hidden gap-1 text-sm text-gray-950/50 dark:text-white/50 group-hover:text-gray-950/70 dark:group-hover:text-white/70 theme-preference-menu-trigger group p-2 flex items-center justify-center"><span data-theme-preference-icon="system"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="size-4 text-gray-500 dark:text-gray-400 group-hover:text-gray-700 dark:group-hover:text-gray-200"><path d="M4.5 15.5L9 14.5L13.5 15.5" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M9 11.75V14.5" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M14.25 2.75H3.75C2.64543 2.75 1.75 3.64543 1.75 4.75V9.75C1.75 10.8546 2.64543 11.75 3.75 11.75H14.25C15.3546 11.75 16.25 10.8546 16.25 9.75V4.75C16.25 3.64543 15.3546 2.75 14.25 2.75Z" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></span><span data-theme-preference-icon="light"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="size-4 text-gray-500 dark:text-gray-400 group-hover:text-gray-700 dark:group-hover:text-gray-200"><path d="M9 1.25V2.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M14.48 3.52002L13.773 4.22702" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M16.75 9H15.75" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M14.48 14.4799L13.773 13.7729" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M9 16.75V15.75" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M3.52 14.4799L4.227 13.7729" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M1.25 9H2.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M3.52 3.52002L4.227 4.22702" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M9 13.25C11.3472 13.25 13.25 11.3472 13.25 9C13.25 6.65279 11.3472 4.75 9 4.75C6.65279 4.75 4.75 6.65279 4.75 9C4.75 11.3472 6.65279 13.25 9 13.25Z" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></span><span data-theme-preference-icon="dark"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="size-4 text-gray-500 dark:text-gray-400 group-hover:text-gray-700 dark:group-hover:text-gray-200"><path d="M13 11.75C9.548 11.75 6.75 8.95201 6.75 5.50001C6.75 4.14801 7.183 2.90101 7.912 1.87801C4.548 2.50601 2 5.45301 2 9.00001C2 13.004 5.246 16.25 9.25 16.25C12.622 16.25 15.448 13.944 16.259 10.826C15.309 11.409 14.196 11.75 13 11.75Z" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></span></button></div></div><div class="flex lg:hidden items-center gap-3"><button type="button" class="text-gray-500 w-8 h-8 flex items-center justify-center hover:text-gray-600 dark:text-gray-400 dark:hover:text-gray-300" id="search-bar-entry-mobile" aria-label="Open search"><span class="sr-only">Search...</span><svg class="forced-colors:forced-color-adjust-none forced-colors:bg-[color:CanvasText]! h-4 w-4 bg-gray-500 dark:bg-gray-400 hover:bg-gray-600 dark:hover:bg-gray-300" aria-hidden="true" focusable="false" style="-webkit-mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/solid/magnifying-glass.svg&quot;);-webkit-mask-repeat:no-repeat;-webkit-mask-position:center;mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/solid/magnifying-glass.svg&quot;);mask-repeat:no-repeat;mask-position:center"></svg></button><button id="assistant-entry-mobile" aria-label="Toggle assistant panel"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-4.5 text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300"><path d="M5.65799 2.99L4.39499 2.569L3.97399 1.306C3.83699 0.898 3.16199 0.898 3.02499 1.306L2.60399 2.569L1.34099 2.99C1.13699 3.058 0.998993 3.249 0.998993 3.464C0.998993 3.679 1.13699 3.87 1.34099 3.938L2.60399 4.359L3.02499 5.622C3.09299 5.826 3.28499 5.964 3.49999 5.964C3.71499 5.964 3.90599 5.826 3.97499 5.622L4.39599 4.359L5.65899 3.938C5.86299 3.87 6.00099 3.679 6.00099 3.464C6.00099 3.249 5.86199 3.058 5.65799 2.99Z" fill="currentColor" stroke="none"></path><path d="M9.5 2.75L11.412 7.587L16.25 9.5L11.412 11.413L9.5 16.25L7.587 11.413L2.75 9.5L7.587 7.587L9.5 2.75Z" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></button><button type="button" aria-label="More actions" class="h-7 w-5 flex items-center justify-center relative after:content-[&#x27;&#x27;] after:absolute after:-inset-y-2 after:-left-1 after:-right-4"><svg class="forced-colors:forced-color-adjust-none forced-colors:bg-[color:CanvasText]! size-4 shrink-0 bg-gray-500 dark:bg-gray-400 hover:bg-gray-600 dark:hover:bg-gray-300" aria-hidden="true" focusable="false" style="-webkit-mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/solid/ellipsis-vertical.svg&quot;);-webkit-mask-repeat:no-repeat;-webkit-mask-position:center;mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/solid/ellipsis-vertical.svg&quot;);mask-repeat:no-repeat;mask-position:center"></svg></button></div></div></div><button type="button" class="flex items-center h-14 py-4 px-5 lg:hidden focus:outline-0 w-full text-left"><div class="text-gray-500 hover:text-gray-600 dark:text-gray-400 dark:hover:text-gray-300"><span class="sr-only">Navigation</span><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-4 shrink-0"><path d="M2.25 9H15.75" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M2.25 3.75H15.75" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M2.25 14.25H15.75" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div><div class="ml-4 flex text-sm leading-6 whitespace-nowrap min-w-0 space-x-3 overflow-hidden"><div class="flex items-center space-x-3 shrink-0"><span>API Guides</span><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-3 text-gray-400 shrink-0"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div><div class="font-semibold text-gray-900 truncate dark:text-gray-200 min-w-0 flex-1">Streaming</div></div></button></div><div class="hidden lg:flex px-12 h-12"><div class="nav-tabs h-full flex text-sm gap-x-6"><a class="link nav-tabs-item group relative h-full gap-2 flex items-center font-medium text-gray-600 dark:text-gray-400 hover:text-gray-800 dark:hover:text-gray-300" href="/docs/quickstart"><svg class="forced-colors:forced-color-adjust-none forced-colors:bg-[color:CanvasText]! h-4 w-4 bg-current" aria-hidden="true" focusable="false" style="-webkit-mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/book.svg&quot;);-webkit-mask-repeat:no-repeat;-webkit-mask-position:center;mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/book.svg&quot;);mask-repeat:no-repeat;mask-position:center"></svg>Docs<div class="absolute bottom-0 h-[1.5px] w-full left-0 group-hover:bg-gray-200 dark:group-hover:bg-gray-700"></div></a><a class="link nav-tabs-item group relative h-full gap-2 flex items-center font-medium hover:text-gray-800 dark:hover:text-gray-300 text-gray-800 dark:text-gray-200 [text-shadow:-0.2px_0_0_currentColor,0.2px_0_0_currentColor]" data-active="true" aria-current="location" href="/docs/api_reference/overview"><svg class="forced-colors:forced-color-adjust-none forced-colors:bg-[color:CanvasText]! h-4 w-4 bg-current" aria-hidden="true" focusable="false" style="-webkit-mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/code.svg&quot;);-webkit-mask-repeat:no-repeat;-webkit-mask-position:center;mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/code.svg&quot;);mask-repeat:no-repeat;mask-position:center"></svg>API Reference<div class="absolute bottom-0 h-[1.5px] w-full left-0 bg-primary dark:bg-primary-light"></div></a><a class="link nav-tabs-item group relative h-full gap-2 flex items-center font-medium text-gray-600 dark:text-gray-400 hover:text-gray-800 dark:hover:text-gray-300" href="/docs/client-sdks/overview"><svg class="forced-colors:forced-color-adjust-none forced-colors:bg-[color:CanvasText]! h-4 w-4 bg-current" aria-hidden="true" focusable="false" style="-webkit-mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/cube.svg&quot;);-webkit-mask-repeat:no-repeat;-webkit-mask-position:center;mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/cube.svg&quot;);mask-repeat:no-repeat;mask-position:center"></svg>Client SDKs<div class="absolute bottom-0 h-[1.5px] w-full left-0 group-hover:bg-gray-200 dark:group-hover:bg-gray-700"></div></a><a class="link nav-tabs-item group relative h-full gap-2 flex items-center font-medium text-gray-600 dark:text-gray-400 hover:text-gray-800 dark:hover:text-gray-300" href="/docs/agent-sdk/overview"><svg class="forced-colors:forced-color-adjust-none forced-colors:bg-[color:CanvasText]! h-4 w-4 bg-current" aria-hidden="true" focusable="false" style="-webkit-mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/cube.svg&quot;);-webkit-mask-repeat:no-repeat;-webkit-mask-position:center;mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/cube.svg&quot;);mask-repeat:no-repeat;mask-position:center"></svg>Agent SDK<div class="absolute bottom-0 h-[1.5px] w-full left-0 group-hover:bg-gray-200 dark:group-hover:bg-gray-700"></div></a><a class="link nav-tabs-item group relative h-full gap-2 flex items-center font-medium text-gray-600 dark:text-gray-400 hover:text-gray-800 dark:hover:text-gray-300" href="/docs/cookbook/get-started/quickstart"><svg class="forced-colors:forced-color-adjust-none forced-colors:bg-[color:CanvasText]! h-4 w-4 bg-current" aria-hidden="true" focusable="false" style="-webkit-mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/book-open.svg&quot;);-webkit-mask-repeat:no-repeat;-webkit-mask-position:center;mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/book-open.svg&quot;);mask-repeat:no-repeat;mask-position:center"></svg>Cookbook<div class="absolute bottom-0 h-[1.5px] w-full left-0 group-hover:bg-gray-200 dark:group-hover:bg-gray-700"></div></a></div></div><style>:root{--topbar-tabs-height:3rem}</style></div></div></header><div class="scroll-mt-(--scroll-mt) peer-[.is-custom]:max-w-none peer-[.is-center]:max-w-3xl peer-[.is-not-custom]:peer-[.is-not-center]:max-w-8xl peer-[.is-not-custom]:px-4 peer-[.is-not-custom]:mx-auto peer-[.is-not-custom]:lg:px-8 peer-[.is-wide]:lg:*:last:max-w-216 peer-[.is-not-custom]:peer-[.is-not-center]:lg:flex peer-[.is-custom]:[&amp;&gt;:first-child]:hidden! peer-[.is-custom]:[&amp;&gt;:first-child]:sm:hidden! peer-[.is-custom]:[&amp;&gt;:first-child]:md:hidden! peer-[.is-custom]:[&amp;&gt;:first-child]:lg:hidden! peer-[.is-custom]:[&amp;&gt;:first-child]:xl:hidden! peer-[.is-center]:[&amp;&gt;:first-child]:hidden! peer-[.is-center]:[&amp;&gt;:first-child]:sm:hidden! peer-[.is-center]:[&amp;&gt;:first-child]:md:hidden! peer-[.is-center]:[&amp;&gt;:first-child]:lg:hidden! peer-[.is-center]:[&amp;&gt;:first-child]:xl:hidden!"><nav aria-label="Pages" class="z-20 hidden lg:block sticky self-start shrink-0 w-[18rem] top-[calc(var(--mintlify-slot-header-height,calc(4rem+var(--topbar-tabs-height,0rem)))+var(--banner-height,0px))] h-[calc(100dvh-var(--mintlify-slot-header-height,calc(4rem+var(--topbar-tabs-height,0rem)))-var(--banner-height,0px))]" id="sidebar"><div role="presentation" style="position:relative;--scroll-area-corner-height:0px;--scroll-area-corner-width:0px" data-component-part="scroll-area" id="sidebar-content" class="min-w-0 absolute! inset-0 z-10"><div role="presentation" data-id="base-ui-_R_2tbsnlhjiuqsnpfiutb_-viewport" tabindex="-1" class="size-full rounded-[inherit] [--scroll-area-fade-size:32px] pr-8 pb-10 base-ui-disable-scrollbar" style="overflow:scroll" data-component-part="scroll-area-viewport"><div role="presentation" style="min-width:fit-content" data-component-part="scroll-area-content" class="min-w-0! w-full"><div class="relative lg:text-sm lg:leading-6"><div class="sticky top-0 h-8 pointer-events-none z-10 bg-linear-to-b from-background-light dark:from-background-dark"></div><div id="navigation-items"><div><div class="sidebar-group-header flex items-center gap-2.5 pl-4 mb-3.5 lg:mb-2.5 font-semibold text-gray-900 dark:text-gray-200"><svg class="forced-colors:forced-color-adjust-none forced-colors:bg-[color:CanvasText]! sidebar-group-icon h-3.5 w-3.5 bg-current" aria-hidden="true" focusable="false" style="-webkit-mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/code.svg&quot;);-webkit-mask-repeat:no-repeat;-webkit-mask-position:center;mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/code.svg&quot;);mask-repeat:no-repeat;mask-position:center"></svg><h3 class="sidebar-title text-[length:inherit] font-[inherit] leading-[inherit]"><span>API Guides</span></h3></div><ul class="sidebar-group space-y-px"><li id="/api_reference/overview" class="relative scroll-m-4 first:scroll-m-20" data-title="Overview"><a class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" href="/docs/api_reference/overview"><div class="h-[1lh] flex items-center shrink-0"><svg class="forced-colors:forced-color-adjust-none forced-colors:bg-[color:CanvasText]! size-4 bg-gray-400 dark:bg-gray-500" aria-hidden="true" focusable="false" style="-webkit-mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/book-open.svg&quot;);-webkit-mask-repeat:no-repeat;-webkit-mask-position:center;mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/book-open.svg&quot;);mask-repeat:no-repeat;mask-position:center"></svg></div><div class="flex-1 flex min-w-0 items-start gap-x-2.5"><div class="flex min-w-0 flex-1 flex-wrap items-center gap-1.5 [word-break:break-word]"><span class="min-w-0 max-w-full break-words hyphens-auto">Overview</span></div></div></a></li><li id="/api_reference/streaming" class="relative scroll-m-4 first:scroll-m-20" data-title="Streaming" data-active="true" data-active-nav-item="true"><a class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] bg-primary/10 text-primary [text-shadow:-0.2px_0_0_currentColor,0.2px_0_0_currentColor] dark:text-primary-light dark:bg-primary-light/10" style="padding-left:1rem" aria-current="page" href="/docs/api_reference/streaming"><div class="h-[1lh] flex items-center shrink-0"><svg class="forced-colors:forced-color-adjust-none forced-colors:bg-[color:CanvasText]! size-4 bg-primary dark:bg-primary-light" aria-hidden="true" focusable="false" style="-webkit-mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/bars-staggered.svg&quot;);-webkit-mask-repeat:no-repeat;-webkit-mask-position:center;mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/bars-staggered.svg&quot;);mask-repeat:no-repeat;mask-position:center"></svg></div><div class="flex-1 flex min-w-0 items-start gap-x-2.5"><div class="flex min-w-0 flex-1 flex-wrap items-center gap-1.5 [word-break:break-word]"><span class="min-w-0 max-w-full break-words hyphens-auto">Streaming</span></div></div></a></li><li id="/api_reference/embeddings" class="relative scroll-m-4 first:scroll-m-20" data-title="Embeddings"><a class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" href="/docs/api_reference/embeddings"><div class="h-[1lh] flex items-center shrink-0"><svg class="forced-colors:forced-color-adjust-none forced-colors:bg-[color:CanvasText]! size-4 bg-gray-400 dark:bg-gray-500" aria-hidden="true" focusable="false" style="-webkit-mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/draw-square.svg&quot;);-webkit-mask-repeat:no-repeat;-webkit-mask-position:center;mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/draw-square.svg&quot;);mask-repeat:no-repeat;mask-position:center"></svg></div><div class="flex-1 flex min-w-0 items-start gap-x-2.5"><div class="flex min-w-0 flex-1 flex-wrap items-center gap-1.5 [word-break:break-word]"><span class="min-w-0 max-w-full break-words hyphens-auto">Embeddings</span></div></div></a></li><li id="/api_reference/limits" class="relative scroll-m-4 first:scroll-m-20" data-title="Limits"><a class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" href="/docs/api_reference/limits"><div class="h-[1lh] flex items-center shrink-0"><svg class="forced-colors:forced-color-adjust-none forced-colors:bg-[color:CanvasText]! size-4 bg-gray-400 dark:bg-gray-500" aria-hidden="true" focusable="false" style="-webkit-mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/gauge-high.svg&quot;);-webkit-mask-repeat:no-repeat;-webkit-mask-position:center;mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/gauge-high.svg&quot;);mask-repeat:no-repeat;mask-position:center"></svg></div><div class="flex-1 flex min-w-0 items-start gap-x-2.5"><div class="flex min-w-0 flex-1 flex-wrap items-center gap-1.5 [word-break:break-word]"><span class="min-w-0 max-w-full break-words hyphens-auto">Limits</span></div></div></a></li><li id="/api_reference/authentication" class="relative scroll-m-4 first:scroll-m-20" data-title="Authentication"><a class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" href="/docs/api_reference/authentication"><div class="h-[1lh] flex items-center shrink-0"><svg class="forced-colors:forced-color-adjust-none forced-colors:bg-[color:CanvasText]! size-4 bg-gray-400 dark:bg-gray-500" aria-hidden="true" focusable="false" style="-webkit-mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/lock.svg&quot;);-webkit-mask-repeat:no-repeat;-webkit-mask-position:center;mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/lock.svg&quot;);mask-repeat:no-repeat;mask-position:center"></svg></div><div class="flex-1 flex min-w-0 items-start gap-x-2.5"><div class="flex min-w-0 flex-1 flex-wrap items-center gap-1.5 [word-break:break-word]"><span class="min-w-0 max-w-full break-words hyphens-auto">Authentication</span></div></div></a></li><li id="/api_reference/parameters" class="relative scroll-m-4 first:scroll-m-20" data-title="Parameters"><a class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" href="/docs/api_reference/parameters"><div class="h-[1lh] flex items-center shrink-0"><svg class="forced-colors:forced-color-adjust-none forced-colors:bg-[color:CanvasText]! size-4 bg-gray-400 dark:bg-gray-500" aria-hidden="true" focusable="false" style="-webkit-mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/gear.svg&quot;);-webkit-mask-repeat:no-repeat;-webkit-mask-position:center;mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/gear.svg&quot;);mask-repeat:no-repeat;mask-position:center"></svg></div><div class="flex-1 flex min-w-0 items-start gap-x-2.5"><div class="flex min-w-0 flex-1 flex-wrap items-center gap-1.5 [word-break:break-word]"><span class="min-w-0 max-w-full break-words hyphens-auto">Parameters</span></div></div></a></li><li id="/api_reference/errors-and-debugging" class="relative scroll-m-4 first:scroll-m-20" data-title="Errors and Debugging"><a class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" href="/docs/api_reference/errors-and-debugging"><div class="h-[1lh] flex items-center shrink-0"><svg class="forced-colors:forced-color-adjust-none forced-colors:bg-[color:CanvasText]! size-4 bg-gray-400 dark:bg-gray-500" aria-hidden="true" focusable="false" style="-webkit-mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/triangle-exclamation.svg&quot;);-webkit-mask-repeat:no-repeat;-webkit-mask-position:center;mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/triangle-exclamation.svg&quot;);mask-repeat:no-repeat;mask-position:center"></svg></div><div class="flex-1 flex min-w-0 items-start gap-x-2.5"><div class="flex min-w-0 flex-1 flex-wrap items-center gap-1.5 [word-break:break-word]"><span class="min-w-0 max-w-full break-words hyphens-auto">Errors and Debugging</span></div></div></a></li><li data-title="Responses API" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class="h-[1lh] flex items-center shrink-0"><svg class="forced-colors:forced-color-adjust-none forced-colors:bg-[color:CanvasText]! size-4 bg-gray-400 dark:bg-gray-500" aria-hidden="true" focusable="false" style="-webkit-mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/reply.svg&quot;);-webkit-mask-repeat:no-repeat;-webkit-mask-position:center;mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/reply.svg&quot;);mask-repeat:no-repeat;mask-position:center"></svg></div><div class=""><span>Responses API</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li></ul></div><div class="mt-6 lg:mt-8"><div class="sidebar-group-header flex items-center gap-2.5 pl-4 mb-3.5 lg:mb-2.5 font-semibold text-gray-900 dark:text-gray-200"><svg class="forced-colors:forced-color-adjust-none forced-colors:bg-[color:CanvasText]! sidebar-group-icon h-3.5 w-3.5 bg-current" aria-hidden="true" focusable="false" style="-webkit-mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/code-branch.svg&quot;);-webkit-mask-repeat:no-repeat;-webkit-mask-position:center;mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/code-branch.svg&quot;);mask-repeat:no-repeat;mask-position:center"></svg><h3 class="sidebar-title text-[length:inherit] font-[inherit] leading-[inherit]"><span>Versioning</span></h3></div><ul class="sidebar-group space-y-px"><li id="/api_reference/versioning" class="relative scroll-m-4 first:scroll-m-20" data-title="API Versioning"><a class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" href="/docs/api_reference/versioning"><div class="h-[1lh] flex items-center shrink-0"><svg class="forced-colors:forced-color-adjust-none forced-colors:bg-[color:CanvasText]! size-4 bg-gray-400 dark:bg-gray-500" aria-hidden="true" focusable="false" style="-webkit-mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/code-branch.svg&quot;);-webkit-mask-repeat:no-repeat;-webkit-mask-position:center;mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/code-branch.svg&quot;);mask-repeat:no-repeat;mask-position:center"></svg></div><div class="flex-1 flex min-w-0 items-start gap-x-2.5"><div class="flex min-w-0 flex-1 flex-wrap items-center gap-1.5 [word-break:break-word]"><span class="min-w-0 max-w-full break-words hyphens-auto">API Versioning</span></div></div></a></li><li id="/changelog" class="relative scroll-m-4 first:scroll-m-20" data-title="API Changelog"><a class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" href="/docs/changelog"><div class="h-[1lh] flex items-center shrink-0"><svg class="forced-colors:forced-color-adjust-none forced-colors:bg-[color:CanvasText]! size-4 bg-gray-400 dark:bg-gray-500" aria-hidden="true" focusable="false" style="-webkit-mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/clock-rotate-left.svg&quot;);-webkit-mask-repeat:no-repeat;-webkit-mask-position:center;mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/clock-rotate-left.svg&quot;);mask-repeat:no-repeat;mask-position:center"></svg></div><div class="flex-1 flex min-w-0 items-start gap-x-2.5"><div class="flex min-w-0 flex-1 flex-wrap items-center gap-1.5 [word-break:break-word]"><span class="min-w-0 max-w-full break-words hyphens-auto">API Changelog</span></div></div></a></li></ul></div><div class="mt-6 lg:mt-8"><div class="sidebar-group-header flex items-center gap-2.5 pl-4 mb-3.5 lg:mb-2.5 font-semibold text-gray-900 dark:text-gray-200"><svg class="forced-colors:forced-color-adjust-none forced-colors:bg-[color:CanvasText]! sidebar-group-icon h-3.5 w-3.5 bg-current" aria-hidden="true" focusable="false" style="-webkit-mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/code.svg&quot;);-webkit-mask-repeat:no-repeat;-webkit-mask-position:center;mask-image:url(&quot;https://d3gk2c5xim1je2.cloudfront.net/fontawesome/v7.2.0/regular/code.svg&quot;);mask-repeat:no-repeat;mask-position:center"></svg><h3 class="sidebar-title text-[length:inherit] font-[inherit] leading-[inherit]"><span>API Reference</span></h3></div><ul class="sidebar-group space-y-px"><li data-title="Analytics" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>Analytics</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="TTS" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>TTS</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="STT" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>STT</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="OAuth" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>OAuth</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="Benchmarks" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>Benchmarks</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="BYOK" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>BYOK</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="Chat" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>Chat</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="Classifications" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>Classifications</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="Containers" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>Containers</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="Credits" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>Credits</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="Datasets" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>Datasets</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="Embeddings" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>Embeddings</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="Endpoints" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>Endpoints</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="Files" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>Files</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="Generations" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>Generations</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="Guardrails" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>Guardrails</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="Images" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>Images</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="API Keys" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>API Keys</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="Anthropic Messages" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>Anthropic Messages</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="Models" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>Models</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="Observability" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>Observability</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="Organization" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>Organization</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="Presets" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>Presets</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="Providers" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>Providers</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="Rerank" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>Rerank</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="Responses" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>Responses</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="SCIM" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>SCIM</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="Video Generation" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>Video Generation</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li><li data-title="Workspaces" data-group-tag="" class="space-y-px"><button class="group flex items-start pr-3 py-1.5 cursor-pointer gap-x-3 text-left focus-visible:-outline-offset-2 break-words hyphens-auto rounded-xl w-full outline-offset-[-1px] hover:bg-gray-600/5 dark:hover:bg-gray-200/5 text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-300" style="padding-left:1rem" aria-expanded="false"><div class=""><span>Workspaces</span></div><div class="h-[1lh] flex items-center shrink-0"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 w-2 h-[1lh] -mr-0.5"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></button></li></ul></div><script>(function () {
  try {
    if (window.__mintlifyInitialSidebarScrollDone) return;
    window.__mintlifyInitialSidebarScrollDone = true;

    var path = (window.location.pathname || '/').split('#')[0].split('?')[0];
    if (path.endsWith('/index')) path = path.slice(0, -6);
    else if (path === 'index') path = '';

    var candidates = [];
    if (path) candidates.push(path);
    if (path.startsWith('/')) candidates.push(path.slice(1));
    else candidates.push('/' + path);

    var item = null;
    for (var i = 0; i < candidates.length && !item; i++) {
      var matches = document.querySelectorAll('[id="' + candidates[i].replace(/"/g, '\\"') + '"]');
      for (var j = 0; j < matches.length; j++) {
        if (matches[j].closest('#sidebar, #sidebar-content')) {
          item = matches[j];
          break;
        }
      }
    }
    if (!item) return;

    var parent = item.closest('[data-component-part="scroll-area-viewport"]');
    if (!parent) {
      parent = item.parentElement;
      while (parent) {
        var style = getComputedStyle(parent);
        if (style.overflowY === 'auto' || style.overflowY === 'scroll') break;
        parent = parent.parentElement;
      }
    }
    if (!parent) return;

    var parentRect = parent.getBoundingClientRect();
    var itemRect = item.getBoundingClientRect();
    if (itemRect.top >= parentRect.top && itemRect.bottom <= parentRect.bottom) return;

    var itemTopRelative = itemRect.top - parentRect.top + parent.scrollTop;
    parent.scrollTop = itemTopRelative - parentRect.height / 2 + itemRect.height / 2;
  } catch (e) {}
})();</script></div></div></div></div></div></nav><main id="content-container" class="lg:flex-1 lg:min-w-0"><script type="application/ld+json">{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://openrouter.ai/#organization","name":"OpenRouter | Documentation","url":"https://openrouter.ai","logo":{"@type":"ImageObject","url":"https://mintcdn.com/openrouter-d02e98a0/ksNSeB_K7gD-BUDh/assets/logo-v2-light.svg?fit=max&auto=format&n=ksNSeB_K7gD-BUDh&q=85&s=690e45873843519efe02bcbe45795dac"}},{"@type":"WebSite","@id":"https://openrouter.ai/docs#website","name":"OpenRouter | Documentation","url":"https://openrouter.ai/docs","publisher":{"@id":"https://openrouter.ai/#organization"}},{"@type":"WebPage","@id":"https://openrouter.ai/docs/api_reference/streaming#webpage","url":"https://openrouter.ai/docs/api_reference/streaming","name":"Streaming","dateModified":"2026-09-05T06:13:49.881Z","isPartOf":{"@id":"https://openrouter.ai/docs#website"},"breadcrumb":{"@id":"https://openrouter.ai/docs/api_reference/streaming#breadcrumb"}},{"@type":"BreadcrumbList","@id":"https://openrouter.ai/docs/api_reference/streaming#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"API Guides","item":"https://openrouter.ai/docs/api_reference/overview"},{"@type":"ListItem","position":2,"name":"Streaming","item":"https://openrouter.ai/docs/api_reference/streaming"}]},{"@type":["Article","TechArticle"],"@id":"https://openrouter.ai/docs/api_reference/streaming#article","headline":"Streaming","name":"Streaming","url":"https://openrouter.ai/docs/api_reference/streaming","mainEntityOfPage":{"@id":"https://openrouter.ai/docs/api_reference/streaming#webpage"},"image":"https://openrouter.ai/dynamic-og?title=API%20Streaming&description=Real-time%20model%20response%20streaming","dateModified":"2026-09-05T06:13:49.881Z","publisher":{"@id":"https://openrouter.ai/#organization"},"isPartOf":{"@id":"https://openrouter.ai/docs#website"}}]}</script><script>document.documentElement.setAttribute('data-page-mode', "none");</script><span class="fixed inset-0 bg-background-light dark:bg-background-dark -z-10 pointer-events-none" id="background-color"></span><span class="block absolute dark:hidden inset-0 overflow-hidden pointer-events-none"></span><span class="hidden absolute dark:block inset-0 overflow-hidden pointer-events-none"></span><style data-custom-css-index="0" data-custom-css-path="style.css">/*
 * OpenRouter Docs — Bauhaus theme overrides
 *
 * Custom CSS for Mintlify to align with the bauhaus design system.
 * Uses Mintlify's exposed ID/element selectors for targeted styling.
 *
 * Brand palette:
 *   Ink #03080A   Cloud #FCFCFE   Grape #7624F4
 *   Volt #C8FF00  Coral #FF6849   Royal #035ADE
 */

/* ── Code font: Geist Mono ── */
@import url('https://fonts.googleapis.com/css2?family=Geist+Mono:wght@400;500;600&display=swap');

/*
 * Inverse semantic pair mirrors packages/frontend/components/ui/theme.css.
 * Mintlify is a separate app, so its generated tooltip DOM uses the same
 * light Ink/Cloud and dark Cloud/Ink values through RGB channel variables.
 */
:root {
  --inverse: 3 8 10;
  --inverse-foreground: 252 252 254;
  --tooltip-background: var(--inverse);
  --tooltip-foreground: var(--inverse-foreground);
}

code,
pre,
pre code,
.code-block code,
[class*="code"] code {
  font-family: 'Geist Mono', ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
}

/* ── Text selection: accent tint per DESIGN.md ── */
::selection {
  background: rgb(118 36 244 / 0.14);
}

.dark ::selection,
html.dark ::selection {
  background: rgb(200 255 0 / 0.14);
  color: inherit;
}

/* ── Dark-mode accent swap: Volt (#C8FF00 = rgb(200 255 0)) per DESIGN.md ──
 * Mintlify + Tailwind use space-separated RGB: rgb(var(--primary-light) / alpha).
 * Override accent in dark mode from Grape to Volt. */
.dark,
[data-theme="dark"],
html.dark {
  --primary: 200 255 0;
  --primary-light: 200 255 0;
  --primary-dark: 200 255 0;
  --light-primary: 200 255 0;
  --primary-foreground: 3 8 10;
  --inverse: 252 252 254;
  --inverse-foreground: 3 8 10;

  /* ── Dark-mode border: Cloud at 14% per DESIGN.md ── */
  --default-border-color: rgb(252 252 254 / 0.14);
}

/* ── Border radius: bauhaus 4/6/8px scale ── */
#navbar {
  border-radius: 0;
}

/* Sidebar active item */
#sidebar a[aria-current="page"],
nav[aria-label="Pages"] a[aria-current="page"] {
  border-radius: 8px;
}

/* Cards and code blocks */
[data-component-part="code-block-root"] {
  border-radius: 8px;
}

/* ── Link styling per DESIGN.md ──
 * underline at 40% opacity of current color, full on hover, offset 2px */
a:not([class]) {
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  text-decoration-color: rgb(0 0 0 / 0.4);
}

a:not([class]):hover {
  text-decoration-color: currentColor;
}

.dark a:not([class]),
html.dark a:not([class]) {
  text-decoration-color: rgb(255 255 255 / 0.4);
}

.dark a:not([class]):hover,
html.dark a:not([class]):hover {
  text-decoration-color: currentColor;
}

/* ── Sidebar badges: outline style ── */
.nav-tag-pill-text {
  background: transparent !important;
  color: rgb(0 0 0 / 0.5) !important;
  border: 1px solid rgb(0 0 0 / 0.2) !important;
}

.dark .nav-tag-pill-text,
html.dark .nav-tag-pill-text {
  background: transparent !important;
  color: rgb(252 252 254 / 0.5) !important;
  border: 1px solid rgb(252 252 254 / 0.2) !important;
}

/* Match the home navbar logo height (h-6 / 1.5rem). */
.nav-logo {
  height: 1.5rem;
}

/* ── Sidebar expand chevrons: raise dark-mode contrast ──
 * Collapsible group toggles render a caret whose default dark tone
 * (gray-600 on Ink) is nearly invisible, so it isn't clear which items
 * have subsections. Derive the caret from Cloud via the DESIGN.md opacity
 * scale: muted-foreground (Cloud `a0`) at rest, full Cloud (foreground) on
 * hover — no custom hex outside the brand palette. */
.dark nav[aria-label="Pages"] button[aria-expanded] svg.transition-transform,
html.dark nav[aria-label="Pages"] button[aria-expanded] svg.transition-transform {
  color: rgb(252 252 254 / 0.627);
}

.dark nav[aria-label="Pages"] button[aria-expanded]:hover svg.transition-transform,
html.dark nav[aria-label="Pages"] button[aria-expanded]:hover svg.transition-transform {
  color: rgb(252 252 254);
}

/* ── Sidebar expand chevrons: enlarge for legibility ──
 * The default caret (w-2 ≈ 8px) is easy to miss; bump its footprint so it
 * reads clearly as an expandable affordance. */
nav[aria-label="Pages"] button[aria-expanded] svg.transition-transform {
  width: 0.625rem;
  height: 0.625rem;
}

/* ── Tooltips: inverse surface pairing ──
 * Mintlify has a foreground variable for Radix tooltips but no matching
 * background variable, so both values are mirrored here from the inverse pair.
 * Radix opens tooltips as "delayed-open" on a normal hover but "instant-open"
 * when moving between triggers within its skip-delay window; cover both. */
[data-radix-popper-content-wrapper]
  > div[data-state="delayed-open"],
[data-radix-popper-content-wrapper]
  > div[data-state="instant-open"] {
  background-color: rgb(var(--tooltip-background)) !important;
  color: rgb(var(--tooltip-foreground)) !important;
}

/* ── Callout + code block alignment ──
 * A code block that is the only child of a callout body carries Mintlify's default
 * prose margins (mt-5 mb-8), which push the snippet down so it no longer lines
 * up with the top-aligned callout icon. Drop those margins so the snippet's
 * top edge aligns with the icon. */
.callout [data-component-part="callout-content"] > .code-block:first-child {
  margin-top: 0;
}

.callout [data-component-part="callout-content"] > .code-block:last-child {
  margin-bottom: 0;
}

/* ── Floating code-block buttons: opaque background ──
 * Mintlify only backs the floating buttons (report / copy / ask) with
 * gray-100/gray-800 when the code block has no fade overlay
 * (group-[:not(:has([data-fade-overlay]))]). Collapsible/expandable blocks
 * always carry a fade overlay, so the buttons stay transparent and the code
 * text bleeds through behind them. Apply the same background unconditionally
 * so the buttons are legible on every code block. */
[data-floating-buttons] button {
  background-color: rgb(241 239 245);
}

.dark [data-floating-buttons] button,
html.dark [data-floating-buttons] button {
  background-color: rgb(40 38 44);
}

/* ── Changelog: Update tags as outline pills (matches sidebar badges) ── */
[data-component-part="update-tag"] {
  border: 1px solid rgb(0 0 0 / 0.2);
  border-radius: 9999px;
  padding: 0.125rem 0.625rem;
  font-size: 0.75rem;
  line-height: 1.25rem;
  color: rgb(0 0 0 / 0.6);
}

.dark [data-component-part="update-tag"],
html.dark [data-component-part="update-tag"] {
  border-color: rgb(252 252 254 / 0.2);
  color: rgb(252 252 254 / 0.6);
}

/* ── Navbar CTA: drop the chevron, pair label and background per theme ──
 * Mintlify renders the primary CTA with a trailing chevron, a text-white
 * label, and a bg-primary-dark fill in both themes (primary-dark maps to
 * docs.json colors.dark = Volt). Per DESIGN.md the pairings are white on
 * Grape in light mode and Ink on Volt in dark mode, which is exactly what
 * --primary already resolves to (Grape from docs.json, Volt via the
 * dark-mode swap above). */
#topbar-cta-button svg {
  display: none;
}

/* Mintlify pads the CTA pl-3/pr-2 to hug the chevron; even it out. */
#topbar-cta-button a {
  padding-right: 0.75rem;
}

#topbar-cta-button .bg-primary-dark {
  background-color: rgb(var(--primary));
}

.dark #topbar-cta-button .text-white,
html.dark #topbar-cta-button .text-white {
  color: rgb(3 8 10);
}

/* ── Changelog: selected filter pill readability ──
 * Mintlify renders the active filter as bg-primary + text-white/90. In dark
 * mode our primary is Volt (#C8FF00), so switch the text to Ink per DESIGN.md. */
.dark #changelog-filters-content button.bg-primary,
html.dark #changelog-filters-content button.bg-primary {
  color: rgb(3 8 10 / 0.9) !important;
}

/* ── Changelog: separate inline status badges from bullet text ── */
.changelog-status-badge {
  margin-left: 0.5rem;
}

.changelog-status-badge[data-color="gray"] {
  border: 1px solid rgb(3 8 10 / 0.3) !important;
}

.dark .changelog-status-badge[data-color="gray"],
html.dark .changelog-status-badge[data-color="gray"] {
  border-color: rgb(252 252 254 / 0.4) !important;
}

/* ── Mermaid: center diagrams in the content column ── */
.mermaid > svg {
  margin-inline: auto;
}
</style><!--$--><!--/$--><div class="flex flex-row-reverse gap-12 box-border w-full pt-[calc(10rem+var(--banner-height,2.5rem))] lg:pt-10"><div class="hidden xl:flex self-start sticky xl:flex-col max-w-[28rem] z-21 h-[calc(100vh-9.5rem)] top-[9.5rem] [[data-banner-state=visible]_&amp;]:h-[calc(100vh-12rem)] [[data-banner-state=visible]_&amp;]:top-[12rem]" id="content-side-layout"><div class="z-10 hidden xl:flex box-border max-h-full pl-10 w-[19rem]" id="table-of-contents-layout"><div role="presentation" style="position:relative;--scroll-area-corner-height:0px;--scroll-area-corner-width:0px" data-component-part="scroll-area" id="table-of-contents" class="min-w-0 text-gray-600 text-sm leading-6 w-[16.5rem] -mt-10"><div role="presentation" data-id="base-ui-_R_1dktbsnlhjiuqsnpfiutb_-viewport" tabindex="-1" class="size-full rounded-[inherit] [--scroll-area-fade-size:32px] pt-10 pb-4 base-ui-disable-scrollbar" style="overflow:scroll" data-component-part="scroll-area-viewport"><div role="presentation" style="min-width:fit-content" data-component-part="scroll-area-content" class="min-w-0! w-full space-y-2"><nav aria-labelledby="_R_dktbsnlhjiuqsnpfiutb_"><h2 id="_R_dktbsnlhjiuqsnpfiutb_" class="m-0 font-normal"><button type="button" class="text-gray-700 dark:text-gray-300 font-medium flex items-center space-x-2 hover:text-gray-900 dark:hover:text-gray-100 transition-colors cursor-pointer"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-3 shrink-0"><path d="M2.75 14.25H15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M2.75 3.75H15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M2.75 9H8.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg><span>On this page</span></button></h2><div><ul id="table-of-contents-content" class="toc"><li class="toc-item relative" data-depth="0"><a style="--toc-padding-left:0rem" href="#additional-information" class="break-words py-1 block pl-[calc(var(--toc-padding-left)+var(--toc-focus-padding,0rem))] focus-visible:[--toc-focus-padding:0.25rem] focus-visible:-ml-1 focus-visible:-outline-offset-2 dark:text-gray-400 [li:not([data-active])&gt;&amp;:hover]:text-gray-900 dark:[li:not([data-active])&gt;&amp;:hover]:text-gray-300 [[data-active]&gt;&amp;]:text-primary dark:[[data-active]&gt;&amp;]:text-primary-light [[data-active]&gt;&amp;]:[text-shadow:-0.15px_0_0_currentColor,0.15px_0_0_currentColor]">Additional information</a></li><li class="toc-item relative" data-depth="0"><a style="--toc-padding-left:0rem" href="#the-final-usage-chunk-chat-completions" class="break-words py-1 block pl-[calc(var(--toc-padding-left)+var(--toc-focus-padding,0rem))] focus-visible:[--toc-focus-padding:0.25rem] focus-visible:-ml-1 focus-visible:-outline-offset-2 dark:text-gray-400 [li:not([data-active])&gt;&amp;:hover]:text-gray-900 dark:[li:not([data-active])&gt;&amp;:hover]:text-gray-300 [[data-active]&gt;&amp;]:text-primary dark:[[data-active]&gt;&amp;]:text-primary-light [[data-active]&gt;&amp;]:[text-shadow:-0.15px_0_0_currentColor,0.15px_0_0_currentColor]">The final usage chunk (Chat Completions)</a></li><li class="toc-item relative" data-depth="0"><a style="--toc-padding-left:0rem" href="#stream-cancellation" class="break-words py-1 block pl-[calc(var(--toc-padding-left)+var(--toc-focus-padding,0rem))] focus-visible:[--toc-focus-padding:0.25rem] focus-visible:-ml-1 focus-visible:-outline-offset-2 dark:text-gray-400 [li:not([data-active])&gt;&amp;:hover]:text-gray-900 dark:[li:not([data-active])&gt;&amp;:hover]:text-gray-300 [[data-active]&gt;&amp;]:text-primary dark:[[data-active]&gt;&amp;]:text-primary-light [[data-active]&gt;&amp;]:[text-shadow:-0.15px_0_0_currentColor,0.15px_0_0_currentColor]">Stream cancellation</a></li><li class="toc-item relative" data-depth="0"><a style="--toc-padding-left:0rem" href="#handling-errors-during-streaming" class="break-words py-1 block pl-[calc(var(--toc-padding-left)+var(--toc-focus-padding,0rem))] focus-visible:[--toc-focus-padding:0.25rem] focus-visible:-ml-1 focus-visible:-outline-offset-2 dark:text-gray-400 [li:not([data-active])&gt;&amp;:hover]:text-gray-900 dark:[li:not([data-active])&gt;&amp;:hover]:text-gray-300 [[data-active]&gt;&amp;]:text-primary dark:[[data-active]&gt;&amp;]:text-primary-light [[data-active]&gt;&amp;]:[text-shadow:-0.15px_0_0_currentColor,0.15px_0_0_currentColor]">Handling errors during streaming</a></li><li class="toc-item relative" data-depth="0"><a style="--toc-padding-left:0rem" href="#errors-before-the-response-is-committed" class="break-words py-1 block pl-[calc(var(--toc-padding-left)+var(--toc-focus-padding,0rem))] focus-visible:[--toc-focus-padding:0.25rem] focus-visible:-ml-1 focus-visible:-outline-offset-2 dark:text-gray-400 [li:not([data-active])&gt;&amp;:hover]:text-gray-900 dark:[li:not([data-active])&gt;&amp;:hover]:text-gray-300 [[data-active]&gt;&amp;]:text-primary dark:[[data-active]&gt;&amp;]:text-primary-light [[data-active]&gt;&amp;]:[text-shadow:-0.15px_0_0_currentColor,0.15px_0_0_currentColor]">Errors before the response is committed</a></li><li class="toc-item relative" data-depth="0"><a style="--toc-padding-left:0rem" href="#errors-after-the-response-is-committed-mid-stream" class="break-words py-1 block pl-[calc(var(--toc-padding-left)+var(--toc-focus-padding,0rem))] focus-visible:[--toc-focus-padding:0.25rem] focus-visible:-ml-1 focus-visible:-outline-offset-2 dark:text-gray-400 [li:not([data-active])&gt;&amp;:hover]:text-gray-900 dark:[li:not([data-active])&gt;&amp;:hover]:text-gray-300 [[data-active]&gt;&amp;]:text-primary dark:[[data-active]&gt;&amp;]:text-primary-light [[data-active]&gt;&amp;]:[text-shadow:-0.15px_0_0_currentColor,0.15px_0_0_currentColor]">Errors after the response is committed (mid-stream)</a></li><li class="toc-item relative" data-depth="0"><a style="--toc-padding-left:0rem" href="#code-examples" class="break-words py-1 block pl-[calc(var(--toc-padding-left)+var(--toc-focus-padding,0rem))] focus-visible:[--toc-focus-padding:0.25rem] focus-visible:-ml-1 focus-visible:-outline-offset-2 dark:text-gray-400 [li:not([data-active])&gt;&amp;:hover]:text-gray-900 dark:[li:not([data-active])&gt;&amp;:hover]:text-gray-300 [[data-active]&gt;&amp;]:text-primary dark:[[data-active]&gt;&amp;]:text-primary-light [[data-active]&gt;&amp;]:[text-shadow:-0.15px_0_0_currentColor,0.15px_0_0_currentColor]">Code examples</a></li><li class="toc-item relative" data-depth="0"><a style="--toc-padding-left:0rem" href="#api-specific-behavior" class="break-words py-1 block pl-[calc(var(--toc-padding-left)+var(--toc-focus-padding,0rem))] focus-visible:[--toc-focus-padding:0.25rem] focus-visible:-ml-1 focus-visible:-outline-offset-2 dark:text-gray-400 [li:not([data-active])&gt;&amp;:hover]:text-gray-900 dark:[li:not([data-active])&gt;&amp;:hover]:text-gray-300 [[data-active]&gt;&amp;]:text-primary dark:[[data-active]&gt;&amp;]:text-primary-light [[data-active]&gt;&amp;]:[text-shadow:-0.15px_0_0_currentColor,0.15px_0_0_currentColor]">API-specific behavior</a></li></ul></div></nav></div></div></div></div></div><div class="relative grow box-border flex-col w-full mx-auto px-1 lg:pl-[5.7rem] lg:-ml-12 xl:w-[calc(100%-28rem)]" id="content-area"><header id="header" class="relative leading-none @container/page-header"><div class="mt-0.5 space-y-2.5"><div class="eyebrow h-5 text-primary dark:text-primary-light text-sm font-semibold">API Guides</div><div class="flex flex-col sm:flex-row items-start sm:items-center relative gap-2 min-w-0"><h1 id="page-title" class="text-3xl sm:text-4xl text-gray-900 tracking-tight dark:text-gray-200 [overflow-wrap:anywhere] break-all font-semibold">Streaming</h1><div id="page-context-menu" class="items-center shrink-0 min-w-[156px] justify-end ml-auto hidden @[520px]/page-header:flex"><button id="page-context-menu-button" class="rounded-l-xl px-3 text-gray-700 dark:text-gray-300 py-1.5 border border-gray-200 dark:border-white/[0.07] bg-background-light dark:bg-background-dark hover:bg-gray-600/5 dark:hover:bg-gray-200/5 border-r-0" aria-label="Copy page"><div class="flex items-center gap-2 text-sm text-center font-medium"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-4 shrink-0"><path d="M14.25 5.25H7.25C6.14543 5.25 5.25 6.14543 5.25 7.25V14.25C5.25 15.3546 6.14543 16.25 7.25 16.25H14.25C15.3546 16.25 16.25 15.3546 16.25 14.25V7.25C16.25 6.14543 15.3546 5.25 14.25 5.25Z" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M2.80103 11.998L1.77203 5.07397C1.61003 3.98097 2.36403 2.96397 3.45603 2.80197L10.38 1.77297C11.313 1.63397 12.19 2.16297 12.528 3.00097" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg><span class="grid"><span aria-hidden="true" class="invisible col-start-1 row-start-1">Copy page</span><span class="col-start-1 row-start-1">Copy page</span></span></div></button><button type="button" tabindex="0" aria-haspopup="menu" id="base-ui-_R_1mshlktbsnlhjiuqsnpfiutb_" aria-label="More actions" class="group disabled:pointer-events-none [&amp;&gt;span]:line-clamp-1 overflow-hidden group focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-primary dark:focus-visible:outline-primary-light py-0.5 gap-1 text-sm text-gray-950/50 dark:text-white/50 group-hover:text-gray-950/70 dark:group-hover:text-white/70 rounded-none rounded-r-xl border flex items-center justify-center h-[34px] border-gray-200 aspect-square dark:border-white/[0.07] bg-background-light dark:bg-background-dark hover:bg-gray-600/5 dark:hover:bg-gray-200/5"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 rotate-90"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></button></div></div></div><div id="page-context-menu" class="flex items-center shrink-0 min-w-[156px] mt-3 @[520px]/page-header:hidden"><button id="page-context-menu-button" class="rounded-l-xl px-3 text-gray-700 dark:text-gray-300 py-1.5 border border-gray-200 dark:border-white/[0.07] bg-background-light dark:bg-background-dark hover:bg-gray-600/5 dark:hover:bg-gray-200/5 border-r-0" aria-label="Copy page"><div class="flex items-center gap-2 text-sm text-center font-medium"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-4 shrink-0"><path d="M14.25 5.25H7.25C6.14543 5.25 5.25 6.14543 5.25 7.25V14.25C5.25 15.3546 6.14543 16.25 7.25 16.25H14.25C15.3546 16.25 16.25 15.3546 16.25 14.25V7.25C16.25 6.14543 15.3546 5.25 14.25 5.25Z" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M2.80103 11.998L1.77203 5.07397C1.61003 3.98097 2.36403 2.96397 3.45603 2.80197L10.38 1.77297C11.313 1.63397 12.19 2.16297 12.528 3.00097" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg><span class="grid"><span aria-hidden="true" class="invisible col-start-1 row-start-1">Copy page</span><span class="col-start-1 row-start-1">Copy page</span></span></div></button><button type="button" tabindex="0" aria-haspopup="menu" id="base-ui-_R_3dhlktbsnlhjiuqsnpfiutb_" aria-label="More actions" class="group disabled:pointer-events-none [&amp;&gt;span]:line-clamp-1 overflow-hidden group focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-primary dark:focus-visible:outline-primary-light py-0.5 gap-1 text-sm text-gray-950/50 dark:text-white/50 group-hover:text-gray-950/70 dark:group-hover:text-white/70 rounded-none rounded-r-xl border flex items-center justify-center h-[34px] border-gray-200 aspect-square dark:border-white/[0.07] bg-background-light dark:bg-background-dark hover:bg-gray-600/5 dark:hover:bg-gray-200/5"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3 transition-transform text-gray-400 group-hover:text-gray-600 dark:text-gray-600 dark:group-hover:text-gray-400 shrink-0 rotate-90"><path d="M6.5 2.75L12.75 9L6.5 15.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></button></div></header><div class="mdx-content @container/columns-container relative mt-8 prose prose-gray dark:prose-invert [contain:inline-size] isolate empty:hidden mb-14" data-page-title="Streaming" data-page-href="/api_reference/streaming" id="content"><span data-as="p">The OpenRouter API allows streaming responses from <em>any model</em>. This is useful for building chat interfaces or other applications where the UI should update as the model generates the response.</span>
<span data-as="p">To enable streaming, you can set the <code>stream</code> parameter to <code>true</code> in your request. The model will then stream the response to the client in chunks, rather than returning the entire response at once.</span>
<span data-as="p">Here is an example of how to stream a response, and process it:</span>
<!-- -->
<h3 class="flex whitespace-pre-wrap group font-semibold" id="additional-information"><div class="absolute" tabindex="-1"><a href="#additional-information" class="-ml-10 flex items-center opacity-0 border-0 group-hover:opacity-100 focus:opacity-100 focus:outline-0 group/link" aria-label="Navigate to header">​<div class="size-6 rounded-md flex items-center justify-center shadow-xs text-gray-400 dark:text-white/50 dark:bg-background-dark dark:brightness-[1.35] dark:ring-1 dark:hover:brightness-150 bg-white ring-1 ring-gray-400/30 dark:ring-gray-700/25 hover:ring-gray-400/60 dark:hover:ring-white/20 group-focus/link:border-2 group-focus/link:border-primary dark:group-focus/link:border-primary-light"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-3 shrink-0"><path d="M8.50001 6.827C8.14801 6.995 7.81801 7.225 7.52701 7.517L7.51701 7.527C6.13601 8.908 6.13601 11.146 7.51701 12.527L9.69201 14.702C11.073 16.083 13.311 16.083 14.692 14.702L14.702 14.692C16.083 13.311 16.083 11.073 14.702 9.692L13.771 8.761" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M9.50002 11.173C9.85202 11.005 10.182 10.775 10.473 10.483L10.483 10.473C11.864 9.092 11.864 6.854 10.483 5.473L8.30802 3.298C6.92702 1.917 4.68902 1.917 3.30802 3.298L3.29802 3.308C1.91702 4.689 1.91702 6.927 3.29802 8.308L4.22902 9.239" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></a></div><span class="cursor-pointer">Additional information</span></h3>
<span data-as="p">For SSE (Server-Sent Events) streams, OpenRouter occasionally sends comments to prevent connection timeouts. These comments look like:</span>
<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group min-w-0 print:print-color-exact text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" data-has-floating-buttons="" lines="true" numberOfLines="2" language="text"><div data-floating-buttons="true" class="absolute top-3 right-4 flex items-center gap-1.5 print:hidden"><div class="z-10 select-none" id="base-ui-_R_fahkllktbsnlhjiuqsnpfiutb_" data-base-ui-tooltip-trigger=""><button class="size-6.5 flex items-center justify-center rounded-md group/code-snippet-feedback-button [.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-100 dark:[.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-800" id="code-snippet-feedback-button" aria-label="Report incorrect code"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-4 shrink-0 text-gray-400 group-hover/code-snippet-feedback-button:text-gray-500 dark:text-white/40 dark:group-hover/code-snippet-feedback-button:text-white/60"><path d="M9 5.431V9.569" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M9 11.417C8.449 11.417 8 11.866 8 12.417C8 12.968 8.449 13.417 9 13.417C9.551 13.417 10 12.968 10 12.417C10 11.866 9.551 11.417 9 11.417Z" fill="currentColor" stroke="none"></path><path d="M10.968 2.25H7.03301C6.50301 2.25 5.99401 2.461 5.61901 2.836L2.83701 5.618C2.46201 5.993 2.25101 6.502 2.25101 7.032V10.967C2.25101 11.497 2.46201 12.006 2.83701 12.381L5.61901 15.163C5.99401 15.538 6.50301 15.749 7.03301 15.749H10.968C11.498 15.749 12.007 15.538 12.382 15.163L15.164 12.381C15.539 12.006 15.75 11.497 15.75 10.967V7.032C15.75 6.502 15.539 5.993 15.164 5.618L12.382 2.836C12.007 2.461 11.498 2.25 10.968 2.25Z" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></button></div><div class="code-block-copy-button z-10 select-none" id="base-ui-_R_fihkllktbsnlhjiuqsnpfiutb_" data-base-ui-tooltip-trigger=""><button class="size-6.5 flex items-center justify-center rounded-md group/copy-button [.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-100 dark:[.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-800" data-testid="copy-code-button" aria-label="Copy the contents from the code block"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-4 shrink-0 text-gray-400 group-hover/copy-button:text-gray-500 dark:text-white/40 dark:group-hover/copy-button:text-white/60"><path d="M14.25 5.25H7.25C6.14543 5.25 5.25 6.14543 5.25 7.25V14.25C5.25 15.3546 6.14543 16.25 7.25 16.25H14.25C15.3546 16.25 16.25 15.3546 16.25 14.25V7.25C16.25 6.14543 15.3546 5.25 14.25 5.25Z" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M2.80103 11.998L1.77203 5.07397C1.61003 3.98097 2.36403 2.96397 3.45603 2.80197L10.38 1.77297C11.313 1.63397 12.19 2.16297 12.528 3.00097" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></button><span role="status" class="sr-only"></span></div><div class="z-10 select-none" id="base-ui-_R_fqhkllktbsnlhjiuqsnpfiutb_" data-base-ui-tooltip-trigger=""><button class="size-6.5 flex items-center justify-center rounded-md group/ask-assistant-button [.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-100 dark:[.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-800" id="ask-assistant-code-block-button" aria-label="Ask Assistant" data-chat-payload-element-id="lang-text-code-__OPENROUTER_PROCESS"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-4 shrink-0 text-gray-400 group-hover/ask-assistant-button:text-gray-500 dark:text-white/40 dark:group-hover/ask-assistant-button:text-white/60"><path d="M5.65799 2.99L4.39499 2.569L3.97399 1.306C3.83699 0.898 3.16199 0.898 3.02499 1.306L2.60399 2.569L1.34099 2.99C1.13699 3.058 0.998993 3.249 0.998993 3.464C0.998993 3.679 1.13699 3.87 1.34099 3.938L2.60399 4.359L3.02499 5.622C3.09299 5.826 3.28499 5.964 3.49999 5.964C3.71499 5.964 3.90599 5.826 3.97499 5.622L4.39599 4.359L5.65899 3.938C5.86299 3.87 6.00099 3.679 6.00099 3.464C6.00099 3.249 5.86199 3.058 5.65799 2.99Z" fill="currentColor" stroke="none"></path><path d="M9.5 2.75L11.412 7.587L16.25 9.5L11.412 11.413L9.5 16.25L7.587 11.413L2.75 9.5L7.587 7.587L9.5 2.75Z" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></button></div></div><div role="presentation" style="position:relative;--scroll-area-corner-height:0px;--scroll-area-corner-width:0px;font-variant-ligatures:none;height:auto;background-color:#ffffff;--shiki-dark-bg:#0B0C0E" data-component-part="code-block-root" class="w-0 min-w-full max-w-full h-full dark:bg-codeblock text-sm leading-6 transition-[height] duration-300 ease-in-out code-block-background **:ring-0 **:outline-0 **:focus:ring-0 **:focus:outline-0 rounded-2xl bg-white has-line-numbers"><div role="presentation" data-id="base-ui-_R_chkllktbsnlhjiuqsnpfiutb_-viewport" tabindex="-1" class="size-full rounded-[inherit] [--scroll-area-fade-size:32px] py-3.5 px-4 overflow-y-hidden! base-ui-disable-scrollbar" style="overflow:scroll" data-component-part="scroll-area-viewport"><div role="presentation" style="min-width:fit-content" data-component-part="scroll-area-content" class="min-w-full! h-full children:my-0! children:shadow-none! children:bg-transparent!"><div class="font-mono whitespace-pre leading-6"><pre class="shiki shiki-themes github-light-default dark-plus" style="background-color:#ffffff;--shiki-dark-bg:#0B0C0E;color:#1f2328;--shiki-dark:#D4D4D4" language="text"><code language="text" numberOfLines="2"><span class="line"><span>: OPENROUTER PROCESSING</span></span>
<span class="line"><span></span></span></code></pre></div></div></div></div><div class="code-block-fade-overlay print:hidden" data-fade-overlay="true" aria-hidden="true" style="--fade-color-light:#ffffff;--fade-color-dark:#0B0C0E"></div></div>
<span data-as="p">Comment payload can be safely ignored per the <a href="https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation" target="_blank" rel="noreferrer" class="link">SSE specs</a>. However, you can use it to improve UX as needed, e.g. by showing a dynamic loading indicator.</span>
<div role="note" aria-label="Warning" class="callout my-4 px-5 py-4 overflow-hidden rounded-2xl flex gap-3 border border-yellow-200 bg-yellow-50 dark:border-yellow-900 dark:bg-yellow-600/20 [&amp;_[data-component-part=&#x27;callout-icon&#x27;]]:mt-px" data-callout-type="warning"><div class="mt-0.5 w-4" data-component-part="callout-icon"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="flex-none size-5 text-yellow-800 dark:text-yellow-300"><path d="M 9 6.75 v 1.5 m 0 3 h 0.0075 m -5.2035 3 h 10.392 c 1.155 0 1.8765 -1.2503 1.299 -2.25 L 10.299 3 c -0.5775 -0.9997 -2.0205 -0.9997 -2.598 0 L 2.505 12 c -0.5775 0.9997 0.144 2.25 1.299 2.25 z" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg></div><div class="text-sm prose dark:prose-invert min-w-0 w-full [&amp;_kbd]:bg-background-light dark:[&amp;_kbd]:bg-background-dark [&amp;_code]:text-current! [&amp;_kbd]:text-current! [&amp;_a]:text-current! [&amp;_a]:border-current [&amp;_strong]:text-current! text-yellow-800 dark:text-yellow-300" data-component-part="callout-content"><span data-as="p">If you parse the stream by hand, skip lines that start with <code>:</code> before
calling <code>JSON.parse</code>. Passing a comment line like <code>: OPENROUTER PROCESSING</code>
to <code>JSON.parse</code> throws, and unhandled it will crash your stream loop. The
snippets above handle this.</span></div></div>
<span data-as="p">A spec-compliant parser such as <a href="https://github.com/rexxars/eventsource-parser" target="_blank" rel="noreferrer" class="link">eventsource-parser</a> handles comments, multi-line <code>data:</code> fields, and buffering for you:</span>
<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group min-w-0 print:print-color-exact text-gray-950 bg-gray-50 dark:bg-white/5 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark p-0.5" data-has-header="" lines="true" numberOfLines="43" language="typescript"><div class="flex text-gray-400 text-xs rounded-t-[14px] leading-6 font-medium pl-4 pr-2.5 py-1" data-component-part="code-block-header"><div class="grow-0 flex items-center gap-1.5 text-gray-700 dark:text-gray-300 min-w-0" data-component-part="code-block-header-filename"><span class="truncate min-w-0" title="eventsource-parser">eventsource-parser</span></div><div class="flex-1 flex items-center justify-end gap-1.5 print:hidden"><div class="z-10 select-none" id="base-ui-_R_1tiikllktbsnlhjiuqsnpfiutb_" data-base-ui-tooltip-trigger=""><button class="size-6.5 flex items-center justify-center rounded-md group/code-snippet-feedback-button [.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-100 dark:[.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-800" id="code-snippet-feedback-button" aria-label="Report incorrect code"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-4 shrink-0 text-gray-400 group-hover/code-snippet-feedback-button:text-gray-500 dark:text-white/40 dark:group-hover/code-snippet-feedback-button:text-white/60"><path d="M9 5.431V9.569" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M9 11.417C8.449 11.417 8 11.866 8 12.417C8 12.968 8.449 13.417 9 13.417C9.551 13.417 10 12.968 10 12.417C10 11.866 9.551 11.417 9 11.417Z" fill="currentColor" stroke="none"></path><path d="M10.968 2.25H7.03301C6.50301 2.25 5.99401 2.461 5.61901 2.836L2.83701 5.618C2.46201 5.993 2.25101 6.502 2.25101 7.032V10.967C2.25101 11.497 2.46201 12.006 2.83701 12.381L5.61901 15.163C5.99401 15.538 6.50301 15.749 7.03301 15.749H10.968C11.498 15.749 12.007 15.538 12.382 15.163L15.164 12.381C15.539 12.006 15.75 11.497 15.75 10.967V7.032C15.75 6.502 15.539 5.993 15.164 5.618L12.382 2.836C12.007 2.461 11.498 2.25 10.968 2.25Z" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></button></div><div class="code-block-copy-button z-10 select-none" id="base-ui-_R_1uiikllktbsnlhjiuqsnpfiutb_" data-base-ui-tooltip-trigger=""><button class="size-6.5 flex items-center justify-center rounded-md group/copy-button [.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-100 dark:[.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-800" data-testid="copy-code-button" aria-label="Copy the contents from the code block"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-4 shrink-0 text-gray-400 group-hover/copy-button:text-gray-500 dark:text-white/40 dark:group-hover/copy-button:text-white/60"><path d="M14.25 5.25H7.25C6.14543 5.25 5.25 6.14543 5.25 7.25V14.25C5.25 15.3546 6.14543 16.25 7.25 16.25H14.25C15.3546 16.25 16.25 15.3546 16.25 14.25V7.25C16.25 6.14543 15.3546 5.25 14.25 5.25Z" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M2.80103 11.998L1.77203 5.07397C1.61003 3.98097 2.36403 2.96397 3.45603 2.80197L10.38 1.77297C11.313 1.63397 12.19 2.16297 12.528 3.00097" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></button><span role="status" class="sr-only"></span></div><div class="z-10 select-none" id="base-ui-_R_1viikllktbsnlhjiuqsnpfiutb_" data-base-ui-tooltip-trigger=""><button class="size-6.5 flex items-center justify-center rounded-md group/ask-assistant-button [.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-100 dark:[.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-800" id="ask-assistant-code-block-button" aria-label="Ask Assistant" data-chat-payload-element-id="lang-typescript-code-import___createParse"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-4 shrink-0 text-gray-400 group-hover/ask-assistant-button:text-gray-500 dark:text-white/40 dark:group-hover/ask-assistant-button:text-white/60"><path d="M5.65799 2.99L4.39499 2.569L3.97399 1.306C3.83699 0.898 3.16199 0.898 3.02499 1.306L2.60399 2.569L1.34099 2.99C1.13699 3.058 0.998993 3.249 0.998993 3.464C0.998993 3.679 1.13699 3.87 1.34099 3.938L2.60399 4.359L3.02499 5.622C3.09299 5.826 3.28499 5.964 3.49999 5.964C3.71499 5.964 3.90599 5.826 3.97499 5.622L4.39599 4.359L5.65899 3.938C5.86299 3.87 6.00099 3.679 6.00099 3.464C6.00099 3.249 5.86199 3.058 5.65799 2.99Z" fill="currentColor" stroke="none"></path><path d="M9.5 2.75L11.412 7.587L16.25 9.5L11.412 11.413L9.5 16.25L7.587 11.413L2.75 9.5L7.587 7.587L9.5 2.75Z" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></button></div></div></div><div role="presentation" style="position:relative;--scroll-area-corner-height:0px;--scroll-area-corner-width:0px;font-variant-ligatures:none;height:190px;background-color:#ffffff;--shiki-dark-bg:#0B0C0E" data-component-part="code-block-root" class="w-0 min-w-full max-w-full h-full dark:bg-codeblock text-sm leading-6 transition-[height] duration-300 ease-in-out code-block-background **:ring-0 **:outline-0 **:focus:ring-0 **:focus:outline-0 rounded-xt bg-white has-line-numbers"><div role="presentation" data-id="base-ui-_R_cikllktbsnlhjiuqsnpfiutb_-viewport" tabindex="-1" class="size-full rounded-[inherit] [--scroll-area-fade-size:32px] py-3.5 px-4 overflow-y-hidden! base-ui-disable-scrollbar" style="overflow:scroll" data-component-part="scroll-area-viewport"><div role="presentation" style="min-width:fit-content" data-component-part="scroll-area-content" class="min-w-full! h-full children:my-0! children:shadow-none! children:bg-transparent!"><div class="font-mono whitespace-pre leading-6"><pre class="shiki shiki-themes github-light-default dark-plus" style="background-color:#ffffff;--shiki-dark-bg:#0B0C0E;color:#1f2328;--shiki-dark:#D4D4D4" language="typescript"><code language="typescript" numberOfLines="43"><span class="line"><span style="color:#CF222E;--shiki-dark:#C586C0">import</span><span style="color:#1F2328;--shiki-dark:#D4D4D4"> { </span><span style="color:#1F2328;--shiki-dark:#9CDCFE">createParser</span><span style="color:#1F2328;--shiki-dark:#D4D4D4"> } </span><span style="color:#CF222E;--shiki-dark:#C586C0">from</span><span style="color:#0A3069;--shiki-dark:#CE9178"> &#x27;eventsource-parser&#x27;</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#CF222E;--shiki-dark:#569CD6">const</span><span style="color:#0550AE;--shiki-dark:#4FC1FF"> response</span><span style="color:#CF222E;--shiki-dark:#D4D4D4"> =</span><span style="color:#CF222E;--shiki-dark:#C586C0"> await</span><span style="color:#8250DF;--shiki-dark:#DCDCAA"> fetch</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">(</span><span style="color:#0A3069;--shiki-dark:#CE9178">&#x27;https://openrouter.ai/api/v1/chat/completions&#x27;</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">, {</span></span>
<span class="line"><span style="color:#1F2328;--shiki-dark:#9CDCFE">  method:</span><span style="color:#0A3069;--shiki-dark:#CE9178"> &#x27;POST&#x27;</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">,</span></span>
<span class="line"><span style="color:#1F2328;--shiki-dark:#9CDCFE">  headers:</span><span style="color:#1F2328;--shiki-dark:#D4D4D4"> {</span></span>
<span class="line"><span style="color:#1F2328;--shiki-dark:#9CDCFE">    Authorization:</span><span style="color:#0A3069;--shiki-dark:#CE9178"> `Bearer </span><span style="color:#0A3069;--shiki-dark:#569CD6">${</span><span style="color:#1F2328;--shiki-dark:#9CDCFE">process</span><span style="color:#0A3069;--shiki-dark:#D4D4D4">.</span><span style="color:#1F2328;--shiki-dark:#9CDCFE">env</span><span style="color:#0A3069;--shiki-dark:#D4D4D4">.</span><span style="color:#0550AE;--shiki-dark:#4FC1FF">OPENROUTER_API_KEY</span><span style="color:#0A3069;--shiki-dark:#569CD6">}</span><span style="color:#0A3069;--shiki-dark:#CE9178">`</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">,</span></span>
<span class="line"><span style="color:#0A3069;--shiki-dark:#CE9178">    &#x27;Content-Type&#x27;</span><span style="color:#1F2328;--shiki-dark:#9CDCFE">:</span><span style="color:#0A3069;--shiki-dark:#CE9178"> &#x27;application/json&#x27;</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">,</span></span>
<span class="line"><span style="color:#1F2328;--shiki-dark:#D4D4D4">  },</span></span>
<span class="line"><span style="color:#1F2328;--shiki-dark:#9CDCFE">  body:</span><span style="color:#0550AE;--shiki-dark:#4FC1FF"> JSON</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">.</span><span style="color:#8250DF;--shiki-dark:#DCDCAA">stringify</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">({</span></span>
<span class="line"><span style="color:#1F2328;--shiki-dark:#9CDCFE">    model:</span><span style="color:#0A3069;--shiki-dark:#CE9178"> &#x27;openai/gpt-4o&#x27;</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">,</span></span>
<span class="line"><span style="color:#1F2328;--shiki-dark:#9CDCFE">    messages:</span><span style="color:#1F2328;--shiki-dark:#D4D4D4"> [{ </span><span style="color:#1F2328;--shiki-dark:#9CDCFE">role:</span><span style="color:#0A3069;--shiki-dark:#CE9178"> &#x27;user&#x27;</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">, </span><span style="color:#1F2328;--shiki-dark:#9CDCFE">content:</span><span style="color:#0A3069;--shiki-dark:#CE9178"> &#x27;Hello&#x27;</span><span style="color:#1F2328;--shiki-dark:#D4D4D4"> }],</span></span>
<span class="line"><span style="color:#1F2328;--shiki-dark:#9CDCFE">    stream:</span><span style="color:#0550AE;--shiki-dark:#569CD6"> true</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">,</span></span>
<span class="line"><span style="color:#1F2328;--shiki-dark:#D4D4D4">  }),</span></span>
<span class="line"><span style="color:#1F2328;--shiki-dark:#D4D4D4">});</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6E7781;--shiki-dark:#6A9955">// Errors that occur before streaming starts are plain JSON, not SSE</span></span>
<span class="line"><span style="color:#CF222E;--shiki-dark:#C586C0">if</span><span style="color:#1F2328;--shiki-dark:#D4D4D4"> (</span><span style="color:#CF222E;--shiki-dark:#D4D4D4">!</span><span style="color:#1F2328;--shiki-dark:#9CDCFE">response</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">.</span><span style="color:#1F2328;--shiki-dark:#9CDCFE">ok</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">) {</span></span>
<span class="line"><span style="color:#CF222E;--shiki-dark:#569CD6">  const</span><span style="color:#0550AE;--shiki-dark:#4FC1FF"> error</span><span style="color:#CF222E;--shiki-dark:#D4D4D4"> =</span><span style="color:#CF222E;--shiki-dark:#C586C0"> await</span><span style="color:#1F2328;--shiki-dark:#9CDCFE"> response</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">.</span><span style="color:#8250DF;--shiki-dark:#DCDCAA">json</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">();</span></span>
<span class="line"><span style="color:#CF222E;--shiki-dark:#C586C0">  throw</span><span style="color:#CF222E;--shiki-dark:#569CD6"> new</span><span style="color:#8250DF;--shiki-dark:#DCDCAA"> Error</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">(</span><span style="color:#1F2328;--shiki-dark:#9CDCFE">error</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">.</span><span style="color:#1F2328;--shiki-dark:#9CDCFE">error</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">.</span><span style="color:#1F2328;--shiki-dark:#9CDCFE">message</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">);</span></span>
<span class="line"><span style="color:#1F2328;--shiki-dark:#D4D4D4">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#CF222E;--shiki-dark:#569CD6">const</span><span style="color:#0550AE;--shiki-dark:#4FC1FF"> parser</span><span style="color:#CF222E;--shiki-dark:#D4D4D4"> =</span><span style="color:#8250DF;--shiki-dark:#DCDCAA"> createParser</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">({</span></span>
<span class="line"><span style="color:#8250DF;--shiki-dark:#DCDCAA">  onEvent</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">(</span><span style="color:#953800;--shiki-dark:#9CDCFE">event</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">) {</span></span>
<span class="line"><span style="color:#CF222E;--shiki-dark:#C586C0">    if</span><span style="color:#1F2328;--shiki-dark:#D4D4D4"> (</span><span style="color:#1F2328;--shiki-dark:#9CDCFE">event</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">.</span><span style="color:#1F2328;--shiki-dark:#9CDCFE">data</span><span style="color:#CF222E;--shiki-dark:#D4D4D4"> ===</span><span style="color:#0A3069;--shiki-dark:#CE9178"> &#x27;[DONE]&#x27;</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">) </span><span style="color:#CF222E;--shiki-dark:#C586C0">return</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">;</span></span>
<span class="line"><span style="color:#CF222E;--shiki-dark:#C586C0">    try</span><span style="color:#1F2328;--shiki-dark:#D4D4D4"> {</span></span>
<span class="line"><span style="color:#CF222E;--shiki-dark:#569CD6">      const</span><span style="color:#0550AE;--shiki-dark:#4FC1FF"> chunk</span><span style="color:#CF222E;--shiki-dark:#D4D4D4"> =</span><span style="color:#0550AE;--shiki-dark:#4FC1FF"> JSON</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">.</span><span style="color:#8250DF;--shiki-dark:#DCDCAA">parse</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">(</span><span style="color:#1F2328;--shiki-dark:#9CDCFE">event</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">.</span><span style="color:#1F2328;--shiki-dark:#9CDCFE">data</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">);</span></span>
<span class="line"><span style="color:#CF222E;--shiki-dark:#569CD6">      const</span><span style="color:#0550AE;--shiki-dark:#4FC1FF"> content</span><span style="color:#CF222E;--shiki-dark:#D4D4D4"> =</span><span style="color:#1F2328;--shiki-dark:#9CDCFE"> chunk</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">.</span><span style="color:#1F2328;--shiki-dark:#9CDCFE">choices</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">?.[</span><span style="color:#0550AE;--shiki-dark:#B5CEA8">0</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">]?.</span><span style="color:#1F2328;--shiki-dark:#9CDCFE">delta</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">?.</span><span style="color:#1F2328;--shiki-dark:#9CDCFE">content</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">;</span></span>
<span class="line"><span style="color:#CF222E;--shiki-dark:#C586C0">      if</span><span style="color:#1F2328;--shiki-dark:#D4D4D4"> (</span><span style="color:#1F2328;--shiki-dark:#9CDCFE">content</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">) {</span></span>
<span class="line"><span style="color:#1F2328;--shiki-dark:#9CDCFE">        console</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">.</span><span style="color:#8250DF;--shiki-dark:#DCDCAA">log</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">(</span><span style="color:#1F2328;--shiki-dark:#9CDCFE">content</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">);</span></span>
<span class="line"><span style="color:#1F2328;--shiki-dark:#D4D4D4">      }</span></span>
<span class="line"><span style="color:#1F2328;--shiki-dark:#D4D4D4">    } </span><span style="color:#CF222E;--shiki-dark:#C586C0">catch</span><span style="color:#1F2328;--shiki-dark:#D4D4D4"> {</span></span>
<span class="line"><span style="color:#6E7781;--shiki-dark:#6A9955">      // Ignore invalid JSON</span></span>
<span class="line"><span style="color:#1F2328;--shiki-dark:#D4D4D4">    }</span></span>
<span class="line"><span style="color:#1F2328;--shiki-dark:#D4D4D4">  },</span></span>
<span class="line"><span style="color:#1F2328;--shiki-dark:#D4D4D4">});</span></span>
<span class="line"></span>
<span class="line"><span style="color:#CF222E;--shiki-dark:#569CD6">const</span><span style="color:#0550AE;--shiki-dark:#4FC1FF"> reader</span><span style="color:#CF222E;--shiki-dark:#D4D4D4"> =</span><span style="color:#1F2328;--shiki-dark:#9CDCFE"> response</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">.</span><span style="color:#1F2328;--shiki-dark:#9CDCFE">body</span><span style="color:#CF222E;--shiki-dark:#D4D4D4">!</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">.</span><span style="color:#8250DF;--shiki-dark:#DCDCAA">getReader</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">();</span></span>
<span class="line"><span style="color:#CF222E;--shiki-dark:#569CD6">const</span><span style="color:#0550AE;--shiki-dark:#4FC1FF"> decoder</span><span style="color:#CF222E;--shiki-dark:#D4D4D4"> =</span><span style="color:#CF222E;--shiki-dark:#569CD6"> new</span><span style="color:#8250DF;--shiki-dark:#DCDCAA"> TextDecoder</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">();</span></span>
<span class="line"><span style="color:#CF222E;--shiki-dark:#C586C0">while</span><span style="color:#1F2328;--shiki-dark:#D4D4D4"> (</span><span style="color:#0550AE;--shiki-dark:#569CD6">true</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">) {</span></span>
<span class="line"><span style="color:#CF222E;--shiki-dark:#569CD6">  const</span><span style="color:#1F2328;--shiki-dark:#D4D4D4"> { </span><span style="color:#0550AE;--shiki-dark:#4FC1FF">done</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">, </span><span style="color:#0550AE;--shiki-dark:#4FC1FF">value</span><span style="color:#1F2328;--shiki-dark:#D4D4D4"> } </span><span style="color:#CF222E;--shiki-dark:#D4D4D4">=</span><span style="color:#CF222E;--shiki-dark:#C586C0"> await</span><span style="color:#1F2328;--shiki-dark:#9CDCFE"> reader</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">.</span><span style="color:#8250DF;--shiki-dark:#DCDCAA">read</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">();</span></span>
<span class="line"><span style="color:#CF222E;--shiki-dark:#C586C0">  if</span><span style="color:#1F2328;--shiki-dark:#D4D4D4"> (</span><span style="color:#1F2328;--shiki-dark:#9CDCFE">done</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">) </span><span style="color:#CF222E;--shiki-dark:#C586C0">break</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">;</span></span>
<span class="line"><span style="color:#1F2328;--shiki-dark:#9CDCFE">  parser</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">.</span><span style="color:#8250DF;--shiki-dark:#DCDCAA">feed</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">(</span><span style="color:#1F2328;--shiki-dark:#9CDCFE">decoder</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">.</span><span style="color:#8250DF;--shiki-dark:#DCDCAA">decode</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">(</span><span style="color:#1F2328;--shiki-dark:#9CDCFE">value</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">, { </span><span style="color:#1F2328;--shiki-dark:#9CDCFE">stream:</span><span style="color:#0550AE;--shiki-dark:#569CD6"> true</span><span style="color:#1F2328;--shiki-dark:#D4D4D4"> }));</span></span>
<span class="line"><span style="color:#1F2328;--shiki-dark:#D4D4D4">}</span></span>
</code></pre></div></div></div></div><div data-component-part="code-block-footer" class="px-3 py-1 flex items-center text-xs font-medium text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300"><button data-component-part="code-block-footer-button" class="flex-1 gap-1.5 flex items-center py-1.5"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-3.5 shrink-0 text-gray-500 dark:text-gray-400"><path d="M9 9.5C9.27614 9.5 9.5 9.27614 9.5 9C9.5 8.72386 9.27614 8.5 9 8.5C8.72386 8.5 8.5 8.72386 8.5 9C8.5 9.27614 8.72386 9.5 9 9.5Z" fill="currentColor" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M3.25 9.5C3.52614 9.5 3.75 9.27614 3.75 9C3.75 8.72386 3.52614 8.5 3.25 8.5C2.97386 8.5 2.75 8.72386 2.75 9C2.75 9.27614 2.97386 9.5 3.25 9.5Z" fill="currentColor" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M14.75 9.5C15.0261 9.5 15.25 9.27614 15.25 9C15.25 8.72386 15.0261 8.5 14.75 8.5C14.4739 8.5 14.25 8.72386 14.25 9C14.25 9.27614 14.4739 9.5 14.75 9.5Z" fill="currentColor" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg>See all 43 lines</button></div></div>
<span data-as="p">A parser only handles the SSE framing. Errors that occur mid-generation still arrive as regular <code>data:</code> events with an <code>error</code> field. See <a href="#handling-errors-during-streaming" class="link">Handling Errors During Streaming</a> below.</span>
<span data-as="p">The generation ID is returned in the <code>X-Generation-Id</code> response header for all endpoints (chat completions, completions, responses, and messages), which can be useful for debugging and correlating requests.</span>
<span data-as="p">Some SSE client implementations might not parse the payload according to spec, which leads to an uncaught error when you <code>JSON.stringify</code> the non-JSON payloads. We recommend the following clients:</span>
<ul>
<li><a href="https://github.com/rexxars/eventsource-parser" target="_blank" rel="noreferrer" class="link">eventsource-parser</a></li>
<li><a href="https://www.npmjs.com/package/openai" target="_blank" rel="noreferrer" class="link">OpenAI SDK</a></li>
<li><a href="https://www.npmjs.com/package/ai" target="_blank" rel="noreferrer" class="link">Vercel AI SDK</a></li>
</ul>
<h3 class="flex whitespace-pre-wrap group font-semibold" id="the-final-usage-chunk-chat-completions"><div class="absolute" tabindex="-1"><a href="#the-final-usage-chunk-chat-completions" class="-ml-10 flex items-center opacity-0 border-0 group-hover:opacity-100 focus:opacity-100 focus:outline-0 group/link" aria-label="Navigate to header">​<div class="size-6 rounded-md flex items-center justify-center shadow-xs text-gray-400 dark:text-white/50 dark:bg-background-dark dark:brightness-[1.35] dark:ring-1 dark:hover:brightness-150 bg-white ring-1 ring-gray-400/30 dark:ring-gray-700/25 hover:ring-gray-400/60 dark:hover:ring-white/20 group-focus/link:border-2 group-focus/link:border-primary dark:group-focus/link:border-primary-light"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-3 shrink-0"><path d="M8.50001 6.827C8.14801 6.995 7.81801 7.225 7.52701 7.517L7.51701 7.527C6.13601 8.908 6.13601 11.146 7.51701 12.527L9.69201 14.702C11.073 16.083 13.311 16.083 14.692 14.702L14.702 14.692C16.083 13.311 16.083 11.073 14.702 9.692L13.771 8.761" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M9.50002 11.173C9.85202 11.005 10.182 10.775 10.473 10.483L10.483 10.473C11.864 9.092 11.864 6.854 10.483 5.473L8.30802 3.298C6.92702 1.917 4.68902 1.917 3.30802 3.298L3.29802 3.308C1.91702 4.689 1.91702 6.927 3.29802 8.308L4.22902 9.239" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></a></div><span class="cursor-pointer">The final usage chunk (Chat Completions)</span></h3>
<span data-as="p">On the Chat Completions endpoint (<code>/api/v1/chat/completions</code>), every stream ends with an extra chunk that carries the <code>usage</code> object for the request, sent just before the <code>[DONE]</code> message. OpenAI’s spec emits this chunk with an empty <code>choices</code> array, but many clients crash when accessing <code>choices[0].delta</code> on it, so OpenRouter intentionally deviates: the usage chunk contains one choice with a content-free <code>delta</code> that repeats the <code>finish_reason</code> (and <code>native_finish_reason</code>) of the stream.</span>
<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group min-w-0 print:print-color-exact text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" data-has-floating-buttons="" lines="true" numberOfLines="4" language="text"><div data-floating-buttons="true" class="absolute top-3 right-4 flex items-center gap-1.5 print:hidden"><div class="z-10 select-none" id="base-ui-_R_fakcllktbsnlhjiuqsnpfiutb_" data-base-ui-tooltip-trigger=""><button class="size-6.5 flex items-center justify-center rounded-md group/code-snippet-feedback-button [.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-100 dark:[.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-800" id="code-snippet-feedback-button" aria-label="Report incorrect code"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-4 shrink-0 text-gray-400 group-hover/code-snippet-feedback-button:text-gray-500 dark:text-white/40 dark:group-hover/code-snippet-feedback-button:text-white/60"><path d="M9 5.431V9.569" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M9 11.417C8.449 11.417 8 11.866 8 12.417C8 12.968 8.449 13.417 9 13.417C9.551 13.417 10 12.968 10 12.417C10 11.866 9.551 11.417 9 11.417Z" fill="currentColor" stroke="none"></path><path d="M10.968 2.25H7.03301C6.50301 2.25 5.99401 2.461 5.61901 2.836L2.83701 5.618C2.46201 5.993 2.25101 6.502 2.25101 7.032V10.967C2.25101 11.497 2.46201 12.006 2.83701 12.381L5.61901 15.163C5.99401 15.538 6.50301 15.749 7.03301 15.749H10.968C11.498 15.749 12.007 15.538 12.382 15.163L15.164 12.381C15.539 12.006 15.75 11.497 15.75 10.967V7.032C15.75 6.502 15.539 5.993 15.164 5.618L12.382 2.836C12.007 2.461 11.498 2.25 10.968 2.25Z" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></button></div><div class="code-block-copy-button z-10 select-none" id="base-ui-_R_fikcllktbsnlhjiuqsnpfiutb_" data-base-ui-tooltip-trigger=""><button class="size-6.5 flex items-center justify-center rounded-md group/copy-button [.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-100 dark:[.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-800" data-testid="copy-code-button" aria-label="Copy the contents from the code block"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-4 shrink-0 text-gray-400 group-hover/copy-button:text-gray-500 dark:text-white/40 dark:group-hover/copy-button:text-white/60"><path d="M14.25 5.25H7.25C6.14543 5.25 5.25 6.14543 5.25 7.25V14.25C5.25 15.3546 6.14543 16.25 7.25 16.25H14.25C15.3546 16.25 16.25 15.3546 16.25 14.25V7.25C16.25 6.14543 15.3546 5.25 14.25 5.25Z" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M2.80103 11.998L1.77203 5.07397C1.61003 3.98097 2.36403 2.96397 3.45603 2.80197L10.38 1.77297C11.313 1.63397 12.19 2.16297 12.528 3.00097" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></button><span role="status" class="sr-only"></span></div><div class="z-10 select-none" id="base-ui-_R_fqkcllktbsnlhjiuqsnpfiutb_" data-base-ui-tooltip-trigger=""><button class="size-6.5 flex items-center justify-center rounded-md group/ask-assistant-button [.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-100 dark:[.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-800" id="ask-assistant-code-block-button" aria-label="Ask Assistant" data-chat-payload-element-id="lang-text-code-data____id___gen-abc"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-4 shrink-0 text-gray-400 group-hover/ask-assistant-button:text-gray-500 dark:text-white/40 dark:group-hover/ask-assistant-button:text-white/60"><path d="M5.65799 2.99L4.39499 2.569L3.97399 1.306C3.83699 0.898 3.16199 0.898 3.02499 1.306L2.60399 2.569L1.34099 2.99C1.13699 3.058 0.998993 3.249 0.998993 3.464C0.998993 3.679 1.13699 3.87 1.34099 3.938L2.60399 4.359L3.02499 5.622C3.09299 5.826 3.28499 5.964 3.49999 5.964C3.71499 5.964 3.90599 5.826 3.97499 5.622L4.39599 4.359L5.65899 3.938C5.86299 3.87 6.00099 3.679 6.00099 3.464C6.00099 3.249 5.86199 3.058 5.65799 2.99Z" fill="currentColor" stroke="none"></path><path d="M9.5 2.75L11.412 7.587L16.25 9.5L11.412 11.413L9.5 16.25L7.587 11.413L2.75 9.5L7.587 7.587L9.5 2.75Z" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></button></div></div><div role="presentation" style="position:relative;--scroll-area-corner-height:0px;--scroll-area-corner-width:0px;font-variant-ligatures:none;height:auto;background-color:#ffffff;--shiki-dark-bg:#0B0C0E" data-component-part="code-block-root" class="w-0 min-w-full max-w-full h-full dark:bg-codeblock text-sm leading-6 transition-[height] duration-300 ease-in-out code-block-background **:ring-0 **:outline-0 **:focus:ring-0 **:focus:outline-0 rounded-2xl bg-white has-line-numbers"><div role="presentation" data-id="base-ui-_R_ckcllktbsnlhjiuqsnpfiutb_-viewport" tabindex="-1" class="size-full rounded-[inherit] [--scroll-area-fade-size:32px] py-3.5 px-4 overflow-y-hidden! base-ui-disable-scrollbar" style="overflow:scroll" data-component-part="scroll-area-viewport"><div role="presentation" style="min-width:fit-content" data-component-part="scroll-area-content" class="min-w-full! h-full children:my-0! children:shadow-none! children:bg-transparent!"><div class="font-mono whitespace-pre leading-6"><pre class="shiki shiki-themes github-light-default dark-plus" style="background-color:#ffffff;--shiki-dark-bg:#0B0C0E;color:#1f2328;--shiki-dark:#D4D4D4" language="text"><code language="text" numberOfLines="4"><span class="line"><span>data: {&quot;id&quot;:&quot;gen-abc123&quot;,...,&quot;choices&quot;:[{&quot;index&quot;:0,&quot;delta&quot;:{&quot;content&quot;:&quot;&quot;,&quot;role&quot;:&quot;assistant&quot;},&quot;finish_reason&quot;:&quot;stop&quot;,&quot;native_finish_reason&quot;:&quot;stop&quot;}]}</span></span>
<span class="line"><span>data: {&quot;id&quot;:&quot;gen-abc123&quot;,...,&quot;choices&quot;:[{&quot;index&quot;:0,&quot;delta&quot;:{&quot;content&quot;:&quot;&quot;,&quot;role&quot;:&quot;assistant&quot;},&quot;finish_reason&quot;:&quot;stop&quot;,&quot;native_finish_reason&quot;:&quot;stop&quot;}],&quot;usage&quot;:{...}}</span></span>
<span class="line"><span>data: [DONE]</span></span>
<span class="line"><span></span></span></code></pre></div></div></div></div><div class="code-block-fade-overlay print:hidden" data-fade-overlay="true" aria-hidden="true" style="--fade-color-light:#ffffff;--fade-color-dark:#0B0C0E"></div></div>
<span data-as="p">This means the terminal <code>finish_reason</code> appears twice: once on the last content-bearing chunk and again on the usage chunk. Clients that validate streams should treat the usage chunk as an accounting frame rather than a second terminal event.</span>
<span data-as="p">This shape is specific to Chat Completions. Other endpoints follow their own specs: the Responses API (<code>/api/v1/responses</code>) reports usage in the <code>response.completed</code> event, and the Messages API (<code>/api/v1/messages</code>) reports it in the <code>message_delta</code> event before <code>message_stop</code>.</span>
<h3 class="flex whitespace-pre-wrap group font-semibold" id="stream-cancellation"><div class="absolute" tabindex="-1"><a href="#stream-cancellation" class="-ml-10 flex items-center opacity-0 border-0 group-hover:opacity-100 focus:opacity-100 focus:outline-0 group/link" aria-label="Navigate to header">​<div class="size-6 rounded-md flex items-center justify-center shadow-xs text-gray-400 dark:text-white/50 dark:bg-background-dark dark:brightness-[1.35] dark:ring-1 dark:hover:brightness-150 bg-white ring-1 ring-gray-400/30 dark:ring-gray-700/25 hover:ring-gray-400/60 dark:hover:ring-white/20 group-focus/link:border-2 group-focus/link:border-primary dark:group-focus/link:border-primary-light"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-3 shrink-0"><path d="M8.50001 6.827C8.14801 6.995 7.81801 7.225 7.52701 7.517L7.51701 7.527C6.13601 8.908 6.13601 11.146 7.51701 12.527L9.69201 14.702C11.073 16.083 13.311 16.083 14.692 14.702L14.702 14.692C16.083 13.311 16.083 11.073 14.702 9.692L13.771 8.761" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M9.50002 11.173C9.85202 11.005 10.182 10.775 10.473 10.483L10.483 10.473C11.864 9.092 11.864 6.854 10.483 5.473L8.30802 3.298C6.92702 1.917 4.68902 1.917 3.30802 3.298L3.29802 3.308C1.91702 4.689 1.91702 6.927 3.29802 8.308L4.22902 9.239" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></a></div><span class="cursor-pointer">Stream cancellation</span></h3>
<span data-as="p">Streaming requests can be cancelled by aborting the connection. For supported providers, this immediately stops model processing and billing.</span>
<details class="accordion border-standard rounded-2xl mb-3 overflow-hidden bg-background-light dark:bg-codeblock cursor-default"><summary class="relative not-prose flex flex-row items-center content-center w-full cursor-pointer list-none [&amp;::-webkit-details-marker]:hidden gap-3 px-5 py-3.5 hover:bg-gray-100 hover:dark:bg-gray-800" aria-controls="provider-support-accordion-children" aria-expanded="false" data-component-part="accordion-button"><div id="provider-support" class="absolute top-[-8rem] [[data-banner-state=visible]_&amp;]:top-[-10.5rem]"></div><div class="flex size-4 shrink-0 items-center justify-center" data-component-part="accordion-caret-right"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="currentColor" stroke="none" aria-hidden="true" class="size-3 shrink-0 text-gray-600 transition-transform duration-200 dark:text-gray-400 -rotate-90"><path d="M14.0238 4.00002H3.97576C3.33776 4.00002 2.74976 4.34702 2.44276 4.90602C2.13576 5.46502 2.15576 6.14802 2.49776 6.68702L7.52176 14.61C7.84476 15.119 8.39676 15.422 8.99976 15.422C9.60276 15.422 10.1548 15.118 10.4778 14.61L15.5028 6.68602C15.8438 6.14702 15.8648 5.46402 15.5578 4.90502C15.2508 4.34602 14.6628 3.99902 14.0248 3.99902L14.0238 4.00002Z" fill="currentColor"></path></svg></div><div class="leading-tight text-left w-full min-w-0" contentEditable="false" data-component-part="accordion-title-container"><p id="provider-support-accordion-title" class="m-0 font-medium leading-6 text-gray-900 dark:text-gray-200" data-component-part="accordion-title">Provider Support</p></div></summary><div id="provider-support-accordion-children" role="region" aria-labelledby="provider-support-accordion-title" class="px-5 pb-3.5 prose prose-gray dark:prose-invert overflow-x-auto cursor-default" data-component-part="accordion-content"><span data-as="p"><strong>Supported</strong></span><ul>
<li>OpenAI, Azure, Anthropic</li>
<li>Fireworks, Mancer, Recursal</li>
<li>AnyScale, Lepton, OctoAI</li>
<li>Novita, DeepInfra, Together</li>
<li>Cohere, Hyperbolic, Infermatic</li>
<li>Avian, XAI, Cloudflare</li>
<li>SFCompute, Nineteen, Liquid</li>
<li>Friendli, Chutes, DeepSeek</li>
</ul><span data-as="p"><strong>Not Currently Supported</strong></span><ul>
<li>AWS Bedrock, Groq, Modal</li>
<li>Google, Google AI Studio, Minimax</li>
<li>HuggingFace, Replicate, Perplexity</li>
<li>Mistral, AI21, Featherless</li>
<li>Lynn, Lambda, Reflection</li>
<li>SambaNova, Inflection, ZeroOneAI</li>
<li>AionLabs, Alibaba, Nebius</li>
<li>Kluster, Targon, InferenceNet</li>
</ul></div></details>
<span data-as="p">To implement stream cancellation:</span>
<!-- -->
<div role="note" aria-label="Warning" class="callout my-4 px-5 py-4 overflow-hidden rounded-2xl flex gap-3 border border-yellow-200 bg-yellow-50 dark:border-yellow-900 dark:bg-yellow-600/20 [&amp;_[data-component-part=&#x27;callout-icon&#x27;]]:mt-px" data-callout-type="warning"><div class="mt-0.5 w-4" data-component-part="callout-icon"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="flex-none size-5 text-yellow-800 dark:text-yellow-300"><path d="M 9 6.75 v 1.5 m 0 3 h 0.0075 m -5.2035 3 h 10.392 c 1.155 0 1.8765 -1.2503 1.299 -2.25 L 10.299 3 c -0.5775 -0.9997 -2.0205 -0.9997 -2.598 0 L 2.505 12 c -0.5775 0.9997 0.144 2.25 1.299 2.25 z" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg></div><div class="text-sm prose dark:prose-invert min-w-0 w-full [&amp;_kbd]:bg-background-light dark:[&amp;_kbd]:bg-background-dark [&amp;_code]:text-current! [&amp;_kbd]:text-current! [&amp;_a]:text-current! [&amp;_a]:border-current [&amp;_strong]:text-current! text-yellow-800 dark:text-yellow-300" data-component-part="callout-content"><span data-as="p">Cancellation only works for streaming requests with supported providers. For
non-streaming requests or unsupported providers, the model will continue
processing and you will be billed for the complete response.</span></div></div>
<h3 class="flex whitespace-pre-wrap group font-semibold" id="handling-errors-during-streaming"><div class="absolute" tabindex="-1"><a href="#handling-errors-during-streaming" class="-ml-10 flex items-center opacity-0 border-0 group-hover:opacity-100 focus:opacity-100 focus:outline-0 group/link" aria-label="Navigate to header">​<div class="size-6 rounded-md flex items-center justify-center shadow-xs text-gray-400 dark:text-white/50 dark:bg-background-dark dark:brightness-[1.35] dark:ring-1 dark:hover:brightness-150 bg-white ring-1 ring-gray-400/30 dark:ring-gray-700/25 hover:ring-gray-400/60 dark:hover:ring-white/20 group-focus/link:border-2 group-focus/link:border-primary dark:group-focus/link:border-primary-light"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-3 shrink-0"><path d="M8.50001 6.827C8.14801 6.995 7.81801 7.225 7.52701 7.517L7.51701 7.527C6.13601 8.908 6.13601 11.146 7.51701 12.527L9.69201 14.702C11.073 16.083 13.311 16.083 14.692 14.702L14.702 14.692C16.083 13.311 16.083 11.073 14.702 9.692L13.771 8.761" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M9.50002 11.173C9.85202 11.005 10.182 10.775 10.473 10.483L10.483 10.473C11.864 9.092 11.864 6.854 10.483 5.473L8.30802 3.298C6.92702 1.917 4.68902 1.917 3.30802 3.298L3.29802 3.308C1.91702 4.689 1.91702 6.927 3.29802 8.308L4.22902 9.239" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></a></div><span class="cursor-pointer">Handling errors during streaming</span></h3>
<span data-as="p">OpenRouter handles errors differently depending on when they occur during the streaming process:</span>
<h4 class="flex whitespace-pre-wrap group font-semibold" id="errors-before-the-response-is-committed"><div class="absolute" tabindex="-1"><a href="#errors-before-the-response-is-committed" class="-ml-10 flex items-center opacity-0 border-0 group-hover:opacity-100 focus:opacity-100 focus:outline-0 group/link" aria-label="Navigate to header">​<div class="size-6 rounded-md flex items-center justify-center shadow-xs text-gray-400 dark:text-white/50 dark:bg-background-dark dark:brightness-[1.35] dark:ring-1 dark:hover:brightness-150 bg-white ring-1 ring-gray-400/30 dark:ring-gray-700/25 hover:ring-gray-400/60 dark:hover:ring-white/20 group-focus/link:border-2 group-focus/link:border-primary dark:group-focus/link:border-primary-light"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-3 shrink-0"><path d="M8.50001 6.827C8.14801 6.995 7.81801 7.225 7.52701 7.517L7.51701 7.527C6.13601 8.908 6.13601 11.146 7.51701 12.527L9.69201 14.702C11.073 16.083 13.311 16.083 14.692 14.702L14.702 14.692C16.083 13.311 16.083 11.073 14.702 9.692L13.771 8.761" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M9.50002 11.173C9.85202 11.005 10.182 10.775 10.473 10.483L10.483 10.473C11.864 9.092 11.864 6.854 10.483 5.473L8.30802 3.298C6.92702 1.917 4.68902 1.917 3.30802 3.298L3.29802 3.308C1.91702 4.689 1.91702 6.927 3.29802 8.308L4.22902 9.239" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></a></div><span class="cursor-pointer">Errors before the response is committed</span></h4>
<span data-as="p">If an error occurs before OpenRouter has committed the response, you get a standard JSON error response with the appropriate HTTP status code. That covers failures raised before the request reaches a provider, and provider failures visible at connection time such as a connection error or a non-2xx upstream status.</span>
<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group min-w-0 print:print-color-exact text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" data-has-floating-buttons="" lines="true" numberOfLines="6" language="json"><div data-floating-buttons="true" class="absolute top-3 right-4 flex items-center gap-1.5 print:hidden"><div class="z-10 select-none" id="base-ui-_R_fankllktbsnlhjiuqsnpfiutb_" data-base-ui-tooltip-trigger=""><button class="size-6.5 flex items-center justify-center rounded-md group/code-snippet-feedback-button [.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-100 dark:[.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-800" id="code-snippet-feedback-button" aria-label="Report incorrect code"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-4 shrink-0 text-gray-400 group-hover/code-snippet-feedback-button:text-gray-500 dark:text-white/40 dark:group-hover/code-snippet-feedback-button:text-white/60"><path d="M9 5.431V9.569" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M9 11.417C8.449 11.417 8 11.866 8 12.417C8 12.968 8.449 13.417 9 13.417C9.551 13.417 10 12.968 10 12.417C10 11.866 9.551 11.417 9 11.417Z" fill="currentColor" stroke="none"></path><path d="M10.968 2.25H7.03301C6.50301 2.25 5.99401 2.461 5.61901 2.836L2.83701 5.618C2.46201 5.993 2.25101 6.502 2.25101 7.032V10.967C2.25101 11.497 2.46201 12.006 2.83701 12.381L5.61901 15.163C5.99401 15.538 6.50301 15.749 7.03301 15.749H10.968C11.498 15.749 12.007 15.538 12.382 15.163L15.164 12.381C15.539 12.006 15.75 11.497 15.75 10.967V7.032C15.75 6.502 15.539 5.993 15.164 5.618L12.382 2.836C12.007 2.461 11.498 2.25 10.968 2.25Z" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></button></div><div class="code-block-copy-button z-10 select-none" id="base-ui-_R_finkllktbsnlhjiuqsnpfiutb_" data-base-ui-tooltip-trigger=""><button class="size-6.5 flex items-center justify-center rounded-md group/copy-button [.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-100 dark:[.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-800" data-testid="copy-code-button" aria-label="Copy the contents from the code block"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-4 shrink-0 text-gray-400 group-hover/copy-button:text-gray-500 dark:text-white/40 dark:group-hover/copy-button:text-white/60"><path d="M14.25 5.25H7.25C6.14543 5.25 5.25 6.14543 5.25 7.25V14.25C5.25 15.3546 6.14543 16.25 7.25 16.25H14.25C15.3546 16.25 16.25 15.3546 16.25 14.25V7.25C16.25 6.14543 15.3546 5.25 14.25 5.25Z" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M2.80103 11.998L1.77203 5.07397C1.61003 3.98097 2.36403 2.96397 3.45603 2.80197L10.38 1.77297C11.313 1.63397 12.19 2.16297 12.528 3.00097" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></button><span role="status" class="sr-only"></span></div><div class="z-10 select-none" id="base-ui-_R_fqnkllktbsnlhjiuqsnpfiutb_" data-base-ui-tooltip-trigger=""><button class="size-6.5 flex items-center justify-center rounded-md group/ask-assistant-button [.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-100 dark:[.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-800" id="ask-assistant-code-block-button" aria-label="Ask Assistant" data-chat-payload-element-id="lang-json-code-_____error__________"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-4 shrink-0 text-gray-400 group-hover/ask-assistant-button:text-gray-500 dark:text-white/40 dark:group-hover/ask-assistant-button:text-white/60"><path d="M5.65799 2.99L4.39499 2.569L3.97399 1.306C3.83699 0.898 3.16199 0.898 3.02499 1.306L2.60399 2.569L1.34099 2.99C1.13699 3.058 0.998993 3.249 0.998993 3.464C0.998993 3.679 1.13699 3.87 1.34099 3.938L2.60399 4.359L3.02499 5.622C3.09299 5.826 3.28499 5.964 3.49999 5.964C3.71499 5.964 3.90599 5.826 3.97499 5.622L4.39599 4.359L5.65899 3.938C5.86299 3.87 6.00099 3.679 6.00099 3.464C6.00099 3.249 5.86199 3.058 5.65799 2.99Z" fill="currentColor" stroke="none"></path><path d="M9.5 2.75L11.412 7.587L16.25 9.5L11.412 11.413L9.5 16.25L7.587 11.413L2.75 9.5L7.587 7.587L9.5 2.75Z" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></button></div></div><div role="presentation" style="position:relative;--scroll-area-corner-height:0px;--scroll-area-corner-width:0px;font-variant-ligatures:none;height:auto;background-color:#ffffff;--shiki-dark-bg:#0B0C0E" data-component-part="code-block-root" class="w-0 min-w-full max-w-full h-full dark:bg-codeblock text-sm leading-6 transition-[height] duration-300 ease-in-out code-block-background **:ring-0 **:outline-0 **:focus:ring-0 **:focus:outline-0 rounded-2xl bg-white has-line-numbers"><div role="presentation" data-id="base-ui-_R_cnkllktbsnlhjiuqsnpfiutb_-viewport" tabindex="-1" class="size-full rounded-[inherit] [--scroll-area-fade-size:32px] py-3.5 px-4 overflow-y-hidden! base-ui-disable-scrollbar" style="overflow:scroll" data-component-part="scroll-area-viewport"><div role="presentation" style="min-width:fit-content" data-component-part="scroll-area-content" class="min-w-full! h-full children:my-0! children:shadow-none! children:bg-transparent!"><div class="font-mono whitespace-pre leading-6"><pre class="shiki shiki-themes github-light-default dark-plus" style="background-color:#ffffff;--shiki-dark-bg:#0B0C0E;color:#1f2328;--shiki-dark:#D4D4D4" language="json"><code language="json" numberOfLines="6"><span class="line"><span style="color:#1F2328;--shiki-dark:#D4D4D4">{</span></span>
<span class="line"><span style="color:#116329;--shiki-dark:#9CDCFE">  &quot;error&quot;</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">: {</span></span>
<span class="line"><span style="color:#116329;--shiki-dark:#9CDCFE">    &quot;code&quot;</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">: </span><span style="color:#0550AE;--shiki-dark:#B5CEA8">400</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">,</span></span>
<span class="line"><span style="color:#116329;--shiki-dark:#9CDCFE">    &quot;message&quot;</span><span style="color:#1F2328;--shiki-dark:#D4D4D4">: </span><span style="color:#0A3069;--shiki-dark:#CE9178">&quot;Invalid model specified&quot;</span></span>
<span class="line"><span style="color:#1F2328;--shiki-dark:#D4D4D4">  }</span></span>
<span class="line"><span style="color:#1F2328;--shiki-dark:#D4D4D4">}</span></span>
</code></pre></div></div></div></div><div class="code-block-fade-overlay print:hidden" data-fade-overlay="true" aria-hidden="true" style="--fade-color-light:#ffffff;--fade-color-dark:#0B0C0E"></div></div>
<span data-as="p">Common HTTP status codes include:</span>
<ul>
<li><strong>400</strong>: Bad Request (invalid parameters)</li>
<li><strong>401</strong>: Unauthorized (invalid API key)</li>
<li><strong>402</strong>: Payment Required (insufficient credits)</li>
<li><strong>429</strong>: Too Many Requests (rate limited)</li>
<li><strong>502</strong>: Bad Gateway (provider error)</li>
<li><strong>503</strong>: Service Unavailable (no available providers)</li>
</ul>
<h4 class="flex whitespace-pre-wrap group font-semibold" id="errors-after-the-response-is-committed-mid-stream"><div class="absolute" tabindex="-1"><a href="#errors-after-the-response-is-committed-mid-stream" class="-ml-10 flex items-center opacity-0 border-0 group-hover:opacity-100 focus:opacity-100 focus:outline-0 group/link" aria-label="Navigate to header">​<div class="size-6 rounded-md flex items-center justify-center shadow-xs text-gray-400 dark:text-white/50 dark:bg-background-dark dark:brightness-[1.35] dark:ring-1 dark:hover:brightness-150 bg-white ring-1 ring-gray-400/30 dark:ring-gray-700/25 hover:ring-gray-400/60 dark:hover:ring-white/20 group-focus/link:border-2 group-focus/link:border-primary dark:group-focus/link:border-primary-light"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-3 shrink-0"><path d="M8.50001 6.827C8.14801 6.995 7.81801 7.225 7.52701 7.517L7.51701 7.527C6.13601 8.908 6.13601 11.146 7.51701 12.527L9.69201 14.702C11.073 16.083 13.311 16.083 14.692 14.702L14.702 14.692C16.083 13.311 16.083 11.073 14.702 9.692L13.771 8.761" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M9.50002 11.173C9.85202 11.005 10.182 10.775 10.473 10.483L10.483 10.473C11.864 9.092 11.864 6.854 10.483 5.473L8.30802 3.298C6.92702 1.917 4.68902 1.917 3.30802 3.298L3.29802 3.308C1.91702 4.689 1.91702 6.927 3.29802 8.308L4.22902 9.239" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></a></div><span class="cursor-pointer">Errors after the response is committed (mid-stream)</span></h4>
<span data-as="p">Once the provider has returned response headers, the <code>200 OK</code> status is committed even if no token has been produced yet. Any error after that point arrives as an SSE event rather than as an HTTP status:</span>
<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group min-w-0 print:print-color-exact text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" data-has-floating-buttons="" lines="true" numberOfLines="2" language="text"><div data-floating-buttons="true" class="absolute top-3 right-4 flex items-center gap-1.5 print:hidden"><div class="z-10 select-none" id="base-ui-_R_faosllktbsnlhjiuqsnpfiutb_" data-base-ui-tooltip-trigger=""><button class="size-6.5 flex items-center justify-center rounded-md group/code-snippet-feedback-button [.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-100 dark:[.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-800" id="code-snippet-feedback-button" aria-label="Report incorrect code"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-4 shrink-0 text-gray-400 group-hover/code-snippet-feedback-button:text-gray-500 dark:text-white/40 dark:group-hover/code-snippet-feedback-button:text-white/60"><path d="M9 5.431V9.569" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M9 11.417C8.449 11.417 8 11.866 8 12.417C8 12.968 8.449 13.417 9 13.417C9.551 13.417 10 12.968 10 12.417C10 11.866 9.551 11.417 9 11.417Z" fill="currentColor" stroke="none"></path><path d="M10.968 2.25H7.03301C6.50301 2.25 5.99401 2.461 5.61901 2.836L2.83701 5.618C2.46201 5.993 2.25101 6.502 2.25101 7.032V10.967C2.25101 11.497 2.46201 12.006 2.83701 12.381L5.61901 15.163C5.99401 15.538 6.50301 15.749 7.03301 15.749H10.968C11.498 15.749 12.007 15.538 12.382 15.163L15.164 12.381C15.539 12.006 15.75 11.497 15.75 10.967V7.032C15.75 6.502 15.539 5.993 15.164 5.618L12.382 2.836C12.007 2.461 11.498 2.25 10.968 2.25Z" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></button></div><div class="code-block-copy-button z-10 select-none" id="base-ui-_R_fiosllktbsnlhjiuqsnpfiutb_" data-base-ui-tooltip-trigger=""><button class="size-6.5 flex items-center justify-center rounded-md group/copy-button [.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-100 dark:[.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-800" data-testid="copy-code-button" aria-label="Copy the contents from the code block"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-4 shrink-0 text-gray-400 group-hover/copy-button:text-gray-500 dark:text-white/40 dark:group-hover/copy-button:text-white/60"><path d="M14.25 5.25H7.25C6.14543 5.25 5.25 6.14543 5.25 7.25V14.25C5.25 15.3546 6.14543 16.25 7.25 16.25H14.25C15.3546 16.25 16.25 15.3546 16.25 14.25V7.25C16.25 6.14543 15.3546 5.25 14.25 5.25Z" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M2.80103 11.998L1.77203 5.07397C1.61003 3.98097 2.36403 2.96397 3.45603 2.80197L10.38 1.77297C11.313 1.63397 12.19 2.16297 12.528 3.00097" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></button><span role="status" class="sr-only"></span></div><div class="z-10 select-none" id="base-ui-_R_fqosllktbsnlhjiuqsnpfiutb_" data-base-ui-tooltip-trigger=""><button class="size-6.5 flex items-center justify-center rounded-md group/ask-assistant-button [.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-100 dark:[.code-block:not(:has([data-fade-overlay]))_[data-floating-buttons]_&amp;]:bg-gray-800" id="ask-assistant-code-block-button" aria-label="Ask Assistant" data-chat-payload-element-id="lang-text-code-data____id___cmpl-ab"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-4 shrink-0 text-gray-400 group-hover/ask-assistant-button:text-gray-500 dark:text-white/40 dark:group-hover/ask-assistant-button:text-white/60"><path d="M5.65799 2.99L4.39499 2.569L3.97399 1.306C3.83699 0.898 3.16199 0.898 3.02499 1.306L2.60399 2.569L1.34099 2.99C1.13699 3.058 0.998993 3.249 0.998993 3.464C0.998993 3.679 1.13699 3.87 1.34099 3.938L2.60399 4.359L3.02499 5.622C3.09299 5.826 3.28499 5.964 3.49999 5.964C3.71499 5.964 3.90599 5.826 3.97499 5.622L4.39599 4.359L5.65899 3.938C5.86299 3.87 6.00099 3.679 6.00099 3.464C6.00099 3.249 5.86199 3.058 5.65799 2.99Z" fill="currentColor" stroke="none"></path><path d="M9.5 2.75L11.412 7.587L16.25 9.5L11.412 11.413L9.5 16.25L7.587 11.413L2.75 9.5L7.587 7.587L9.5 2.75Z" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></button></div></div><div role="presentation" style="position:relative;--scroll-area-corner-height:0px;--scroll-area-corner-width:0px;font-variant-ligatures:none;height:auto;background-color:#ffffff;--shiki-dark-bg:#0B0C0E" data-component-part="code-block-root" class="w-0 min-w-full max-w-full h-full dark:bg-codeblock text-sm leading-6 transition-[height] duration-300 ease-in-out code-block-background **:ring-0 **:outline-0 **:focus:ring-0 **:focus:outline-0 rounded-2xl bg-white has-line-numbers"><div role="presentation" data-id="base-ui-_R_cosllktbsnlhjiuqsnpfiutb_-viewport" tabindex="-1" class="size-full rounded-[inherit] [--scroll-area-fade-size:32px] py-3.5 px-4 overflow-y-hidden! base-ui-disable-scrollbar" style="overflow:scroll" data-component-part="scroll-area-viewport"><div role="presentation" style="min-width:fit-content" data-component-part="scroll-area-content" class="min-w-full! h-full children:my-0! children:shadow-none! children:bg-transparent!"><div class="font-mono whitespace-pre leading-6"><pre class="shiki shiki-themes github-light-default dark-plus" style="background-color:#ffffff;--shiki-dark-bg:#0B0C0E;color:#1f2328;--shiki-dark:#D4D4D4" language="text"><code language="text" numberOfLines="2"><span class="line"><span>data: {&quot;id&quot;:&quot;cmpl-abc123&quot;,&quot;object&quot;:&quot;chat.completion.chunk&quot;,&quot;created&quot;:1234567890,&quot;model&quot;:&quot;openai/gpt-4o&quot;,&quot;provider&quot;:&quot;openai&quot;,&quot;error&quot;:{&quot;code&quot;:&quot;server_error&quot;,&quot;message&quot;:&quot;Provider disconnected unexpectedly&quot;},&quot;choices&quot;:[{&quot;index&quot;:0,&quot;delta&quot;:{&quot;content&quot;:&quot;&quot;},&quot;finish_reason&quot;:&quot;error&quot;}]}</span></span>
<span class="line"><span></span></span></code></pre></div></div></div></div><div class="code-block-fade-overlay print:hidden" data-fade-overlay="true" aria-hidden="true" style="--fade-color-light:#ffffff;--fade-color-dark:#0B0C0E"></div></div>
<span data-as="p">Key characteristics of mid-stream errors:</span>
<ul>
<li>The error appears at the <strong>top level</strong> alongside standard response fields (id, object, created, etc.)</li>
<li>A <code>choices</code> array is included with <code>finish_reason: &quot;error&quot;</code> to properly terminate the stream</li>
<li>The HTTP status remains 200 OK since headers were already sent</li>
<li>The stream is terminated after this unified error event</li>
<li>The error can be the first and only event in the stream, so treat a <code>200</code> carrying an <code>error</code> chunk with no content as a failure, not a success</li>
</ul>
<h4 class="flex whitespace-pre-wrap group font-semibold" id="code-examples"><div class="absolute" tabindex="-1"><a href="#code-examples" class="-ml-10 flex items-center opacity-0 border-0 group-hover:opacity-100 focus:opacity-100 focus:outline-0 group/link" aria-label="Navigate to header">​<div class="size-6 rounded-md flex items-center justify-center shadow-xs text-gray-400 dark:text-white/50 dark:bg-background-dark dark:brightness-[1.35] dark:ring-1 dark:hover:brightness-150 bg-white ring-1 ring-gray-400/30 dark:ring-gray-700/25 hover:ring-gray-400/60 dark:hover:ring-white/20 group-focus/link:border-2 group-focus/link:border-primary dark:group-focus/link:border-primary-light"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-3 shrink-0"><path d="M8.50001 6.827C8.14801 6.995 7.81801 7.225 7.52701 7.517L7.51701 7.527C6.13601 8.908 6.13601 11.146 7.51701 12.527L9.69201 14.702C11.073 16.083 13.311 16.083 14.692 14.702L14.702 14.692C16.083 13.311 16.083 11.073 14.702 9.692L13.771 8.761" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M9.50002 11.173C9.85202 11.005 10.182 10.775 10.473 10.483L10.483 10.473C11.864 9.092 11.864 6.854 10.483 5.473L8.30802 3.298C6.92702 1.917 4.68902 1.917 3.30802 3.298L3.29802 3.308C1.91702 4.689 1.91702 6.927 3.29802 8.308L4.22902 9.239" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></a></div><span class="cursor-pointer">Code examples</span></h4>
<span data-as="p">Here’s how to properly handle both types of errors in your streaming implementation:</span>
<!-- -->
<h4 class="flex whitespace-pre-wrap group font-semibold" id="api-specific-behavior"><div class="absolute" tabindex="-1"><a href="#api-specific-behavior" class="-ml-10 flex items-center opacity-0 border-0 group-hover:opacity-100 focus:opacity-100 focus:outline-0 group/link" aria-label="Navigate to header">​<div class="size-6 rounded-md flex items-center justify-center shadow-xs text-gray-400 dark:text-white/50 dark:bg-background-dark dark:brightness-[1.35] dark:ring-1 dark:hover:brightness-150 bg-white ring-1 ring-gray-400/30 dark:ring-gray-700/25 hover:ring-gray-400/60 dark:hover:ring-white/20 group-focus/link:border-2 group-focus/link:border-primary dark:group-focus/link:border-primary-light"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-3 shrink-0"><path d="M8.50001 6.827C8.14801 6.995 7.81801 7.225 7.52701 7.517L7.51701 7.527C6.13601 8.908 6.13601 11.146 7.51701 12.527L9.69201 14.702C11.073 16.083 13.311 16.083 14.692 14.702L14.702 14.692C16.083 13.311 16.083 11.073 14.702 9.692L13.771 8.761" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M9.50002 11.173C9.85202 11.005 10.182 10.775 10.473 10.483L10.483 10.473C11.864 9.092 11.864 6.854 10.483 5.473L8.30802 3.298C6.92702 1.917 4.68902 1.917 3.30802 3.298L3.29802 3.308C1.91702 4.689 1.91702 6.927 3.29802 8.308L4.22902 9.239" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></div></a></div><span class="cursor-pointer">API-specific behavior</span></h4>
<span data-as="p">Different API endpoints may handle streaming errors slightly differently:</span>
<ul>
<li><strong>OpenAI Chat Completions API</strong>: Returns <code>ErrorResponse</code> directly if no chunks were processed, or includes error information in the response if some chunks were processed</li>
<li><strong>OpenAI Responses API</strong>: May transform certain error codes (like <code>context_length_exceeded</code>) into a successful response with <code>finish_reason: &quot;length&quot;</code> instead of treating them as errors</li>
</ul></div><nav id="pagination" aria-label="Pagination" class="px-0.5 flex items-center gap-6 text-sm font-semibold text-gray-700 dark:text-gray-200"><a rel="prev" aria-label="Previous: Overview" data-component-part="pagination-prev" class="group flex items-center min-w-0 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary dark:focus-visible:outline-primary-light gap-3 rounded-sm pagination-prev" href="/docs/api_reference/overview"><svg viewBox="0 0 3 6" aria-hidden="true" data-component-part="pagination-chevron" class="h-1.5 shrink-0 stroke-gray-400 overflow-visible group-hover:stroke-gray-600 dark:group-hover:stroke-gray-300"><path d="M3 0L0 3L3 6" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg><div class="truncate group-hover:text-gray-900 dark:group-hover:text-white" data-component-part="pagination-title">Overview</div></a><a rel="next" aria-label="Next: Embeddings" data-component-part="pagination-next" class="group flex items-center min-w-0 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary dark:focus-visible:outline-primary-light gap-3 rounded-sm ml-auto pagination-next" href="/docs/api_reference/embeddings"><div class="truncate group-hover:text-gray-900 dark:group-hover:text-white" data-component-part="pagination-title">Embeddings</div><svg viewBox="0 0 3 6" aria-hidden="true" data-component-part="pagination-chevron" class="h-1.5 shrink-0 stroke-gray-400 overflow-visible group-hover:stroke-gray-600 dark:group-hover:stroke-gray-300 rotate-180"><path d="M3 0L0 3L3 6" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg></a></nav><div data-assistant-bar="" class="left-0 right-0 sticky bottom-0 w-full overflow-hidden z-20 pointer-events-none print:hidden"><div class="chat-assistant-floating-input w-full group/assistant-bar relative before:content-[&quot;&quot;] before:absolute before:left-0 before:right-0 before:top-[calc(50%-0.5rem)] sm:before:top-[calc(50%-0.75rem)] before:h-[200px] before:bg-background-light dark:before:bg-background-dark translate-y-[100px] opacity-0"><div class="relative pb-4 sm:pb-6"><div class="flex flex-col w-full rounded-2xl pointer-events-auto bg-background-light dark:bg-background-dark border border-gray-200 dark:border-white/10 focus-within:border-primary dark:focus-within:border-primary-light transition-colors"><div class="relative flex items-end"><textarea id="chat-assistant-textarea" aria-label="Ask a question..." autoComplete="off" placeholder="Ask a question..." class="chat-assistant-input w-full bg-transparent border-0 peer/input text-gray-900 dark:text-gray-100 placeholder-gray-600 dark:placeholder-gray-300 outline-hidden! focus:outline-hidden! focus:ring-0 py-2.5 pl-3.5 pr-10 font-bodyWeight text-sm" style="resize:none"></textarea><button class="chat-assistant-send-button flex justify-center items-center rounded-full p-1 size-6 bg-primary/30 dark:bg-primary-dark/30 absolute right-2.5 bottom-2" aria-label="Send message" disabled=""><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-2.5 shrink-0 text-white dark:text-white"><path d="M9.0 1.5754L8.9999 16.4171" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M2.2563 8.319L8.9999 1.5754L15.7435 8.3191" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></button></div></div></div></div></div><footer id="footer" class="flex gap-12 justify-between pt-10 border-t border-gray-100 sm:flex dark:border-gray-800/50 pb-28"></footer></div></div></main></div><!--$--><!--/$--></div><div data-assistant-sheet-container="" class="sticky shrink-0 z-22 bg-background-light dark:bg-background-dark mt-(--banner-height,0px) top-(--banner-height,0px) h-[calc(100vh-var(--banner-height,0px))] max-lg:hidden print:hidden" style="width:var(--assistant-sheet-width, 0px);overflow:hidden"><div class="absolute left-0 top-0 bottom-0 w-px z-10 cursor-col-resize after:content-[&quot;&quot;] after:absolute after:inset-y-0 after:-inset-x-2 after:select-none bg-gray-100 dark:bg-gray-800 hover:bg-gray-200 dark:hover:bg-gray-700"></div><div id="chat-assistant-sheet" class="flex flex-col overflow-hidden shrink-0 relative h-full bg-background-light dark:bg-background-dark chat-assistant-sheet" aria-hidden="true"><div class="w-full flex flex-col flex-1 min-h-0 lg:pt-3"><div class="chat-assistant-sheet-header flex items-center justify-between pb-3 px-4"><div class="flex items-center gap-2"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="size-5 text-primary dark:text-primary-light shrink-0" aria-hidden="true"><path d="M5.65799 2.99L4.39499 2.569L3.97399 1.306C3.83699 0.898 3.16199 0.898 3.02499 1.306L2.60399 2.569L1.34099 2.99C1.13699 3.058 0.998993 3.249 0.998993 3.464C0.998993 3.679 1.13699 3.87 1.34099 3.938L2.60399 4.359L3.02499 5.622C3.09299 5.826 3.28499 5.964 3.49999 5.964C3.71499 5.964 3.90599 5.826 3.97499 5.622L4.39599 4.359L5.65899 3.938C5.86299 3.87 6.00099 3.679 6.00099 3.464C6.00099 3.249 5.86199 3.058 5.65799 2.99Z" fill="currentColor" stroke="none"></path><path d="M9.5 2.75L11.412 7.587L16.25 9.5L11.412 11.413L9.5 16.25L7.587 11.413L2.75 9.5L7.587 7.587L9.5 2.75Z" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg><span class="font-medium text-gray-900 dark:text-gray-100">Assistant</span></div><div class="flex items-center gap-1"><button class="group hover:bg-gray-100 dark:hover:bg-white/10 p-1.5 rounded-lg" aria-label="Maximize assistant panel"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-4 sm:size-3.5 text-gray-500 group-hover:text-gray-700 dark:group-hover:text-gray-300 shrink-0"><path d="M10.75 2.75H15.25V7.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M15.25 2.75L10.75 7.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M2.75 10.75V15.25H7.25" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M2.75 15.25L7.25 10.75" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></button><button class="group hover:bg-gray-100 dark:hover:bg-white/10 p-1.5 rounded-lg" aria-label="Close assistant panel"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-[20px] sm:size-4 text-gray-500 group-hover:text-gray-700 dark:group-hover:text-gray-300 shrink-0"><path d="M14 4L4 14" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M4 4L14 14" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></button></div></div><div id="chat-content" class="chat-assistant-sheet-content flex flex-col-reverse flex-1 overflow-y-auto relative px-5 min-h-0"><div class="grow"></div><div class="h-full flex flex-col justify-between"><div class="mt-4 flex flex-col items-center text-sm"><div class="mx-8 text-center text-gray-400 dark:text-gray-600 text-xs chat-assistant-disclaimer-text">Responses are generated using AI and may contain mistakes.</div></div></div></div><div class="px-4 pb-4 shrink-0"><div class=""><div class="flex flex-col w-full rounded-2xl pointer-events-auto bg-background-light dark:bg-background-dark border border-gray-200 dark:border-white/10 focus-within:border-primary dark:focus-within:border-primary-light transition-colors"><div class="relative flex items-end"><textarea id="chat-assistant-textarea" aria-label="Ask a question..." autoComplete="off" placeholder="Ask a question..." class="chat-assistant-input w-full bg-transparent border-0 peer/input text-gray-900 dark:text-gray-100 placeholder-gray-600 dark:placeholder-gray-300 outline-hidden! focus:outline-hidden! focus:ring-0 py-2.5 pl-3.5 pr-10 font-bodyWeight text-sm pb-0!" style="resize:none" rows="2"></textarea></div><div class="flex items-center justify-between px-2 pb-2"><input type="file" accept="image/*,.pdf,.js,.jsx,.ts,.tsx,.mjs,.cjs,.md,.mdx,.json,.html,.css,.py,.csv,.txt,.yaml,.yml,.xml,.sql,.sh,.bash,.zsh,.graphql,.gql,.toml,.env,.go,.rs,.rb,.java,.kt,.swift,.c,.cpp,.cc,.h,.hpp,.cs,.php,.dart,.lua,.r,.scala,.ini,.cfg,.conf,.log,.dockerfile,.makefile,.gitignore" multiple="" class="hidden"/><button type="button" class="p-1 rounded-lg text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-white/10" aria-label="Add attachment"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class="size-3.5 shrink-0"><path d="M7.75 5V11.75C7.75 12.578 8.422 13.25 9.25 13.25C10.078 13.25 10.75 12.578 10.75 11.75V4.75C10.75 3.093 9.407 1.75 7.75 1.75C6.093 1.75 4.75 3.093 4.75 4.75V11.75C4.75 14.235 6.765 16.25 9.25 16.25C11.735 16.25 13.75 14.235 13.75 11.75V5" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></button><button class="chat-assistant-send-button flex justify-center items-center rounded-full p-1 size-6 bg-primary/30 dark:bg-primary-dark/30" aria-label="Send message" disabled=""><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="size-2.5 shrink-0 text-white dark:text-white"><path d="M9.0 1.5754L8.9999 16.4171" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path><path d="M2.2563 8.319L8.9999 1.5754L15.7435 8.3191" stroke="currentColor" width="1.5" linecap="round" linejoin="round"></path></svg></button></div></div></div></div></div></div></div></div></div><script src="/docs/_next/static/chunks/6d55b684068fd47e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx" id="_R_" async=""></script><script>(self.__next_f=self.__next_f||[]).push([0])</script><script>self.__next_f.push([1,"1:\"$Sreact.fragment\"\na:I[168027,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"default\"]\n:HL[\"/docs/_next/static/chunks/462bacc63bed9960.css?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"style\"]\n:HL[\"/docs/_next/static/chunks/bf5dec8f24f39796.css?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"style\"]\n:HL[\"/docs/_next/static/media/83afe278b6a6bb3c.p.3a6ba036.woff2\",\"font\",{\"crossOrigin\":\"\",\"type\":\"font/woff2\"}]\n:HL[\"/docs/_next/static/media/PaperMono_Variable.p.aa32f7a0.woff2\",\"font\",{\"crossOrigin\":\"\",\"type\":\"font/woff2\"}]\n:HL[\"/docs/_next/static/media/f67ad414ed34149c.p.84166d94.woff2\",\"font\",{\"crossOrigin\":\"\",\"type\":\"font/woff2\"}]\n"])</script><script>self.__next_f.push([1,"0:{\"P\":null,\"b\":\"ZNnCykY5drMGPUV70aVRc\",\"p\":\"/docs\",\"c\":[\"\",\"_sites\",\"openrouter-d02e98a0\",\"api_reference\",\"streaming\"],\"i\":false,\"f\":[[[\"\",{\"children\":[\"%5Fsites\",{\"children\":[[\"subdomain\",\"openrouter-d02e98a0\",\"d\"],{\"children\":[\"(multitenant)\",{\"children\":[[\"slug\",\"api_reference/streaming\",\"oc\"],{\"children\":[\"__PAGE__\",{}]}]}]}]}]},\"$undefined\",\"$undefined\",true],[\"\",[\"$\",\"$1\",\"c\",{\"children\":[[[\"$\",\"link\",\"0\",{\"rel\":\"stylesheet\",\"href\":\"/docs/_next/static/chunks/462bacc63bed9960.css?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\",\"nonce\":\"$undefined\"}],[\"$\",\"link\",\"1\",{\"rel\":\"stylesheet\",\"href\":\"/docs/_next/static/chunks/bf5dec8f24f39796.css?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\",\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-0\",{\"src\":\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-1\",{\"src\":\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true,\"nonce\":\"$undefined\"}]],[\"$\",\"html\",null,{\"suppressHydrationWarning\":true,\"lang\":\"en\",\"className\":\"inter_1d81deff-module__CYM0aG__variable papermono_89c757f2-module__6aS5zq__variable dark\",\"data-banner-state\":\"visible\",\"data-assistant-state\":\"closed\",\"data-page-mode\":\"none\",\"data-current-path\":\"/\",\"children\":[[\"$\",\"head\",null,{\"children\":[[\"$\",\"script\",null,{\"type\":\"text/javascript\",\"dangerouslySetInnerHTML\":{\"__html\":\"!function(){var b=\\\"/docs\\\";\\nfunction a(p){if(p==null)return\\\"/\\\";p=\\\"\\\"+p;if(\\\"\\\"===p)return\\\"/\\\";return\\\"/\\\"===p.charAt(0)?p:\\\"/\\\"+p}\\nfunction u(p){if(p==null)return p;p=\\\"\\\"+p;if(!p||p.charAt(p.length-1)===\\\"/\\\")return p.slice(0,-1);return p}\\nfunction i(p){if(p==null)return p;p=\\\"\\\"+p;if(6\u003c=p.length\u0026\u0026p.substring(p.length-6)===\\\"/index\\\")return p.substring(0,p.length-6);if(\\\"index\\\"===p)return\\\"\\\";return p}\\nvar p=(location.pathname||\\\"\\\").split(\\\"?\\\")[0].split(\\\"#\\\")[0]||\\\"\\\";\\nif(b)if(p===b)p=\\\"\\\";else if(0===p.indexOf(b+\\\"/\\\"))p=p.substring(b.length);\\np=a(p);p=u(p);p=i(p);p=\\\"\\\"===p||\\\"index\\\"===p?\\\"/\\\":a(p);\\ndocument.documentElement.setAttribute(\\\"data-current-path\\\",p);\\n}();\"}}],[\"$\",\"script\",null,{\"type\":\"text/javascript\",\"dangerouslySetInnerHTML\":{\"__html\":\"(() =\u003e {\\n  const isIOS =\\n    /iP(hone|ad|od)/.test(navigator.userAgent) ||\\n    (/Macintosh/.test(navigator.userAgent) \u0026\u0026 navigator.maxTouchPoints \u003e 1);\\n  if (!isIOS) return;\\n  const apply = () =\u003e {\\n    for (const meta of document.querySelectorAll('meta[name=\\\"viewport\\\"]')) {\\n      const content = meta.getAttribute('content') || '';\\n      if (!content.includes('maximum-scale')) {\\n        meta.setAttribute('content', content + ', maximum-scale=1');\\n      }\\n    }\\n  };\\n  apply();\\n  new MutationObserver(apply).observe(document.head, {\\n    childList: true,\\n    subtree: true,\\n    attributes: true,\\n    attributeFilter: ['content'],\\n  });\\n})();\"}}],[\"$\",\"script\",null,{\"type\":\"text/javascript\",\"dangerouslySetInnerHTML\":{\"__html\":\"!function(){\\nfunction read(){try{\\nvar e=performance.getEntriesByType?performance.getEntriesByType(\\\"navigation\\\"):[];\\nvar st=(e[0]\u0026\u0026e[0].serverTiming)||[];\\nvar g={};\\nfor(var i=0;i\u003cst.length;i++){var n=st[i].name,d=st[i].description;if(!d)continue;try{d=decodeURIComponent(d)}catch(x){}\\nif(n===\\\"country\\\")g.country=d;else if(n===\\\"region\\\")g.region=d;else if(n===\\\"continent\\\")g.continent=d;}\\nvar w=window;w.mintlify=w.mintlify||{};w.mintlify.geo=g;\\n}catch(x){}}\\nread();document.addEventListener(\\\"DOMContentLoaded\\\",read);\\n}();\"}}],[\"$\",\"script\",null,{\"type\":\"text/javascript\",\"dangerouslySetInnerHTML\":{\"__html\":\"!function(){try{\\nvar w=window;w.mintlify=w.mintlify||{};\\nvar q=w.mintlify.__apiPlaygroundInputsQueue;\\nif(!Array.isArray(q)){q=[];w.mintlify.__apiPlaygroundInputsQueue=q;}\\nw.mintlify.api=w.mintlify.api||{};\\nw.mintlify.api.playground=w.mintlify.api.playground||{};\\nif(typeof w.mintlify.api.playground.setServerVariables!==\\\"function\\\"){\\nw.mintlify.api.playground.setServerVariables=function(v){q.push({type:\\\"set\\\",variables:v});};\\n}\\nif(typeof w.mintlify.api.playground.clearServerVariables!==\\\"function\\\"){\\nw.mintlify.api.playground.clearServerVariables=function(){q.push({type:\\\"clear\\\"});};\\n}\\n}catch(e){}}();\"}}],\"$L2\",false]}],\"$L3\"]}]]}],{\"children\":[\"%5Fsites\",\"$L4\",{\"children\":[[\"subdomain\",\"openrouter-d02e98a0\",\"d\"],\"$L5\",{\"children\":[\"(multitenant)\",\"$L6\",{\"children\":[[\"slug\",\"api_reference/streaming\",\"oc\"],\"$L7\",{\"children\":[\"__PAGE__\",\"$L8\",{},null,false]},null,false]},null,false]},null,false]},null,false]},null,false],\"$L9\",false]],\"m\":\"$undefined\",\"G\":[\"$a\",[\"$Lb\",\"$Lc\"]],\"s\":false,\"S\":true}\n"])</script><script>self.__next_f.push([1,"d:I[667786,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"MintlifyApiPlaygroundInputsInit\"]\ne:I[339756,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"default\"]\nf:I[556357,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/6b1d878389ce54e6.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"default\"]\n10:I[837457,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"default\"]\n"])</script><script>self.__next_f.push([1,"11:I[894587,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"ThemeProvider\"]\n"])</script><script>self.__next_f.push([1,"12:I[152823,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"ColorVariables\"]\n"])</script><script>self.__next_f.push([1,"13:I[531961,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"FontScript\"]\n"])</script><script>self.__next_f.push([1,"14:I[649328,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"RoundedVariables\"]\n"])</script><script>self.__next_f.push([1,"15:I[702910,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ecfd3e69d0bcca28.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"RecommendedPagesList\"]\n16:I[570420,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"DataCurrentPathUpdater\"]\n17:I[341175,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/fab73139199c3663.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"default\"]\n1a:I[897367,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"OutletBoundary\"]\n1c:I[711533,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"AsyncMetadataOutlet\"]\n1e:I[897367,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSv"])</script><script>self.__next_f.push([1,"EC9fx\"],\"ViewportBoundary\"]\n20:I[897367,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"MetadataBoundary\"]\n21:\"$Sreact.suspense\"\n"])</script><script>self.__next_f.push([1,"2:[\"$\",\"script\",null,{\"type\":\"text/javascript\",\"dangerouslySetInnerHTML\":{\"__html\":\"(function(a,b){try{let c=document.getElementById(\\\"banner\\\")?.innerText;if(c){for(let d=0;d\u003clocalStorage.length;d++){let e=localStorage.key(d);if(e?.endsWith(a)\u0026\u0026localStorage.getItem(e)===c)return void document.documentElement.setAttribute(b,\\\"hidden\\\")}document.documentElement.setAttribute(b,\\\"visible\\\");return}for(let c=0;c\u003clocalStorage.length;c++){let d=localStorage.key(c);if(d?.endsWith(a)\u0026\u0026localStorage.getItem(d))return void document.documentElement.setAttribute(b,\\\"hidden\\\")}document.documentElement.setAttribute(b,\\\"visible\\\")}catch(a){document.documentElement.setAttribute(b,\\\"hidden\\\")}})(\\n  \\\"bannerDismissed\\\",\\n  \\\"data-banner-state\\\",\\n)\"}}]\n"])</script><script>self.__next_f.push([1,"3:[\"$\",\"body\",null,{\"className\":\"antialiased\",\"children\":[[\"$\",\"$Ld\",null,{}],false,[\"$\",\"$Le\",null,{\"parallelRouterKey\":\"children\",\"error\":\"$f\",\"errorStyles\":[],\"errorScripts\":[[\"$\",\"script\",\"script-0\",{\"src\":\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true}],[\"$\",\"script\",\"script-1\",{\"src\":\"/docs/_next/static/chunks/6b1d878389ce54e6.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true}],[\"$\",\"script\",\"script-2\",{\"src\":\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true}],[\"$\",\"script\",\"script-3\",{\"src\":\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true}],[\"$\",\"script\",\"script-4\",{\"src\":\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true}]],\"template\":[\"$\",\"$L10\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":[[\"$\",\"$L11\",null,{\"children\":[[\"$\",\"$L12\",null,{}],[\"$\",\"$L13\",null,{}],[\"$\",\"$L14\",null,{}],[\"$\",\"style\",null,{\"children\":\":root {\\n  --primary: 17 120 102;\\n  --primary-light: 74 222 128;\\n  --primary-dark: 22 101 52;\\n  --background-light: 255 255 255;\\n  --background-dark: 15 17 23;\\n}\"}],[\"$\",\"main\",null,{\"className\":\"h-screen bg-background-light dark:bg-background-dark text-left\",\"children\":[\"$\",\"article\",null,{\"className\":\"bg-custom bg-fixed bg-center bg-cover relative flex flex-col items-center justify-center h-full\",\"children\":[\"$\",\"div\",null,{\"className\":\"w-full max-w-xl px-10\",\"children\":[[\"$\",\"span\",null,{\"className\":\"inline-flex mb-6 rounded-full px-3 py-1 text-sm font-semibold mr-4 text-white p-1 bg-primary\",\"children\":[\"Error \",404]}],[\"$\",\"h1\",null,{\"className\":\"font-semibold mb-3 text-3xl\",\"children\":\"Page not found!\"}],[\"$\",\"p\",null,{\"className\":\"text-lg text-gray-600 dark:text-gray-400 mb-6\",\"children\":\"We couldn't find the page.\"}],[\"$\",\"$L15\",null,{}]]}]}]}]]}],[]],\"forbidden\":\"$undefined\",\"unauthorized\":\"$undefined\"}],false,[\"$\",\"$L16\",null,{}]]}]\n"])</script><script>self.__next_f.push([1,"4:[\"$\",\"$1\",\"c\",{\"children\":[null,[\"$\",\"$Le\",null,{\"parallelRouterKey\":\"children\",\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$L10\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":\"$undefined\",\"forbidden\":\"$undefined\",\"unauthorized\":\"$undefined\"}]]}]\n"])</script><script>self.__next_f.push([1,"5:[\"$\",\"$1\",\"c\",{\"children\":[null,[\"$\",\"$Le\",null,{\"parallelRouterKey\":\"children\",\"error\":\"$17\",\"errorStyles\":[],\"errorScripts\":[[\"$\",\"script\",\"script-0\",{\"src\":\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true}],[\"$\",\"script\",\"script-1\",{\"src\":\"/docs/_next/static/chunks/fab73139199c3663.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true}],[\"$\",\"script\",\"script-2\",{\"src\":\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true}],[\"$\",\"script\",\"script-3\",{\"src\":\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true}],[\"$\",\"script\",\"script-4\",{\"src\":\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true}]],\"template\":[\"$\",\"$L10\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":[[\"$\",\"$L11\",null,{\"children\":[[\"$\",\"$L12\",null,{}],[\"$\",\"$L13\",null,{}],[\"$\",\"$L14\",null,{}],[\"$\",\"style\",null,{\"children\":\":root {\\n  --primary: 17 120 102;\\n  --primary-light: 74 222 128;\\n  --primary-dark: 22 101 52;\\n  --background-light: 255 255 255;\\n  --background-dark: 15 17 23;\\n}\"}],[\"$\",\"main\",null,{\"className\":\"h-screen bg-background-light dark:bg-background-dark text-left\",\"children\":[\"$\",\"article\",null,{\"className\":\"bg-custom bg-fixed bg-center bg-cover relative flex flex-col items-center justify-center h-full\",\"children\":[\"$\",\"div\",null,{\"className\":\"w-full max-w-xl px-10\",\"children\":[[\"$\",\"span\",null,{\"className\":\"inline-flex mb-6 rounded-full px-3 py-1 text-sm font-semibold mr-4 text-white p-1 bg-primary\",\"children\":[\"Error \",404]}],[\"$\",\"h1\",null,{\"className\":\"font-semibold mb-3 text-3xl\",\"children\":\"Page not found!\"}],[\"$\",\"p\",null,{\"className\":\"text-lg text-gray-600 dark:text-gray-400 mb-6\",\"children\":\"We couldn't find the page.\"}],[\"$\",\"$L15\",null,{}]]}]}]}]]}],[]],\"forbidden\":\"$undefined\",\"unauthorized\":\"$undefined\"}]]}]\n"])</script><script>self.__next_f.push([1,"6:[\"$\",\"$1\",\"c\",{\"children\":[[[\"$\",\"script\",\"script-0\",{\"src\":\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-1\",{\"src\":\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-2\",{\"src\":\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-3\",{\"src\":\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-4\",{\"src\":\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-5\",{\"src\":\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-6\",{\"src\":\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-7\",{\"src\":\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-8\",{\"src\":\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-9\",{\"src\":\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-10\",{\"src\":\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-11\",{\"src\":\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-12\",{\"src\":\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-13\",{\"src\":\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-14\",{\"src\":\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true,\"nonce\":\"$undefined\"}]],\"$L18\"]}]\n"])</script><script>self.__next_f.push([1,"7:[\"$\",\"$1\",\"c\",{\"children\":[null,[\"$\",\"$Le\",null,{\"parallelRouterKey\":\"children\",\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$L10\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":\"$undefined\",\"forbidden\":\"$undefined\",\"unauthorized\":\"$undefined\"}]]}]\n"])</script><script>self.__next_f.push([1,"8:[\"$\",\"$1\",\"c\",{\"children\":[\"$L19\",[[\"$\",\"script\",\"script-0\",{\"src\":\"/docs/_next/static/chunks/cee6f6b26d68395d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-1\",{\"src\":\"/docs/_next/static/chunks/0eb894a8519f24ea.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-2\",{\"src\":\"/docs/_next/static/chunks/fb156bebf42da1e9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-3\",{\"src\":\"/docs/_next/static/chunks/2dd53f5a4cfe6dd5.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-4\",{\"src\":\"/docs/_next/static/chunks/e95beff806b7ab98.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-5\",{\"src\":\"/docs/_next/static/chunks/8a30b6291cd9465f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-6\",{\"src\":\"/docs/_next/static/chunks/893b80a74cde24cd.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-7\",{\"src\":\"/docs/_next/static/chunks/c0e7a98cd764702e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"async\":true,\"nonce\":\"$undefined\"}]],[\"$\",\"$L1a\",null,{\"children\":[\"$L1b\",[\"$\",\"$L1c\",null,{\"promise\":\"$@1d\"}]]}]]}]\n"])</script><script>self.__next_f.push([1,"9:[\"$\",\"$1\",\"h\",{\"children\":[null,[[\"$\",\"$L1e\",null,{\"children\":\"$L1f\"}],null],[\"$\",\"$L20\",null,{\"children\":[\"$\",\"div\",null,{\"hidden\":true,\"children\":[\"$\",\"$21\",null,{\"fallback\":null,\"children\":\"$L22\"}]}]}]]}]\nb:[\"$\",\"link\",\"0\",{\"rel\":\"stylesheet\",\"href\":\"/docs/_next/static/chunks/462bacc63bed9960.css?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\",\"nonce\":\"$undefined\"}]\nc:[\"$\",\"link\",\"1\",{\"rel\":\"stylesheet\",\"href\":\"/docs/_next/static/chunks/bf5dec8f24f39796.css?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\",\"nonce\":\"$undefined\"}]\n"])</script><script>self.__next_f.push([1,"1f:[[\"$\",\"meta\",\"0\",{\"charSet\":\"utf-8\"}],[\"$\",\"meta\",\"1\",{\"name\":\"viewport\",\"content\":\"width=device-width, initial-scale=1, viewport-fit=cover\"}]]\n1b:null\n"])</script><script>self.__next_f.push([1,"1d:{\"metadata\":[[\"$\",\"title\",\"0\",{\"children\":\"API Streaming - Real-time Model Response Integration\"}],[\"$\",\"meta\",\"1\",{\"name\":\"application-name\",\"content\":\"OpenRouter | Documentation\"}],[\"$\",\"meta\",\"2\",{\"name\":\"generator\",\"content\":\"Mintlify\"}],[\"$\",\"meta\",\"3\",{\"name\":\"msapplication-config\",\"content\":\"/docs/_mintlify/favicons/openrouter-d02e98a0/EmhfYwFO2tvnkuV-/_generated/favicon/browserconfig.xml\"}],[\"$\",\"meta\",\"4\",{\"name\":\"apple-mobile-web-app-title\",\"content\":\"OpenRouter | Documentation\"}],[\"$\",\"meta\",\"5\",{\"name\":\"msapplication-TileColor\",\"content\":\"#7624F4\"}],[\"$\",\"link\",\"6\",{\"rel\":\"canonical\",\"href\":\"https://openrouter.ai/docs/api_reference/streaming\"}],[\"$\",\"link\",\"7\",{\"rel\":\"alternate\",\"type\":\"application/xml\",\"href\":\"/docs/sitemap.xml\"}],[\"$\",\"link\",\"8\",{\"rel\":\"alternate\",\"type\":\"text/markdown\",\"href\":\"/docs/api_reference/streaming.md\"}],[\"$\",\"meta\",\"9\",{\"property\":\"og:title\",\"content\":\"API Streaming - Real-time Model Response Integration\"}],[\"$\",\"meta\",\"10\",{\"property\":\"og:description\",\"content\":\"Learn how to implement streaming responses with OpenRouter's API. Complete guide to Server-Sent Events (SSE) and real-time model outputs.\"}],[\"$\",\"meta\",\"11\",{\"property\":\"og:url\",\"content\":\"https://openrouter.ai/docs/api_reference/streaming\"}],[\"$\",\"meta\",\"12\",{\"property\":\"og:site_name\",\"content\":\"OpenRouter Documentation\"}],[\"$\",\"meta\",\"13\",{\"property\":\"og:image\",\"content\":\"https://openrouter.ai/dynamic-og?title=API%20Streaming\u0026description=Real-time%20model%20response%20streaming\"}],[\"$\",\"meta\",\"14\",{\"property\":\"og:image:width\",\"content\":\"1200\"}],[\"$\",\"meta\",\"15\",{\"property\":\"og:image:height\",\"content\":\"630\"}],[\"$\",\"meta\",\"16\",{\"property\":\"og:type\",\"content\":\"website\"}],[\"$\",\"meta\",\"17\",{\"name\":\"twitter:card\",\"content\":\"summary_large_image\"}],[\"$\",\"meta\",\"18\",{\"name\":\"twitter:title\",\"content\":\"API Streaming - Real-time Model Response Integration\"}],[\"$\",\"meta\",\"19\",{\"name\":\"twitter:description\",\"content\":\"Learn how to implement streaming responses with OpenRouter's API. Complete guide to Server-Sent Events (SSE) and real-time model outputs.\"}],[\"$\",\"meta\",\"20\",{\"name\":\"twitter:image\",\"content\":\"https://openrouter.ai/dynamic-og?title=API%20Streaming\u0026description=Real-time%20model%20response%20streaming\"}],[\"$\",\"meta\",\"21\",{\"name\":\"twitter:image:width\",\"content\":\"1200\"}],[\"$\",\"meta\",\"22\",{\"name\":\"twitter:image:height\",\"content\":\"630\"}],[\"$\",\"link\",\"23\",{\"rel\":\"icon\",\"href\":\"/docs/_mintlify/favicons/openrouter-d02e98a0/EmhfYwFO2tvnkuV-/_generated/favicon/android-chrome-192x192.png\",\"type\":\"image/png\",\"sizes\":\"192x192\",\"media\":\"(prefers-color-scheme: light)\"}],[\"$\",\"link\",\"24\",{\"rel\":\"apple-touch-icon\",\"href\":\"/docs/_mintlify/favicons/openrouter-d02e98a0/EmhfYwFO2tvnkuV-/_generated/favicon/apple-touch-icon.png\",\"type\":\"image/png\",\"sizes\":\"180x180\",\"media\":\"$undefined\"}],[\"$\",\"link\",\"25\",{\"rel\":\"icon\",\"href\":\"/docs/_mintlify/favicons/openrouter-d02e98a0/EmhfYwFO2tvnkuV-/_generated/favicon/favicon-16x16.png\",\"type\":\"image/png\",\"sizes\":\"16x16\",\"media\":\"(prefers-color-scheme: light)\"}],[\"$\",\"link\",\"26\",{\"rel\":\"icon\",\"href\":\"/docs/_mintlify/favicons/openrouter-d02e98a0/EmhfYwFO2tvnkuV-/_generated/favicon/favicon-32x32.png\",\"type\":\"image/png\",\"sizes\":\"32x32\",\"media\":\"(prefers-color-scheme: light)\"}],[\"$\",\"link\",\"27\",{\"rel\":\"shortcut icon\",\"href\":\"/docs/_mintlify/favicons/openrouter-d02e98a0/EmhfYwFO2tvnkuV-/_generated/favicon/favicon.ico\",\"type\":\"image/x-icon\",\"sizes\":\"$undefined\",\"media\":\"(prefers-color-scheme: light)\"}],[\"$\",\"link\",\"28\",{\"rel\":\"icon\",\"href\":\"/docs/_mintlify/favicons/openrouter-d02e98a0/EmhfYwFO2tvnkuV-/_generated/favicon-dark/android-chrome-192x192.png\",\"type\":\"image/png\",\"sizes\":\"192x192\",\"media\":\"(prefers-color-scheme: dark)\"}],[\"$\",\"link\",\"29\",{\"rel\":\"icon\",\"href\":\"/docs/_mintlify/favicons/openrouter-d02e98a0/EmhfYwFO2tvnkuV-/_generated/favicon-dark/favicon-16x16.png\",\"type\":\"image/png\",\"sizes\":\"16x16\",\"media\":\"(prefers-color-scheme: dark)\"}],[\"$\",\"link\",\"30\",{\"rel\":\"icon\",\"href\":\"/docs/_mintlify/favicons/openrouter-d02e98a0/EmhfYwFO2tvnkuV-/_generated/favicon-dark/favicon-32x32.png\",\"type\":\"image/png\",\"sizes\":\"32x32\",\"media\":\"(prefers-color-scheme: dark)\"}],\"$L23\",\"$L24\"],\"error\":null,\"digest\":\"$undefined\"}\n"])</script><script>self.__next_f.push([1,"22:\"$1d:metadata\"\n"])</script><script>self.__next_f.push([1,"25:I[27201,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"IconMark\"]\n23:[\"$\",\"link\",\"31\",{\"rel\":\"shortcut icon\",\"href\":\"/docs/_mintlify/favicons/openrouter-d02e98a0/EmhfYwFO2tvnkuV-/_generated/favicon-dark/favicon.ico\",\"type\":\"image/x-icon\",\"sizes\":\"$undefined\",\"media\":\"(prefers-color-scheme: dark)\"}]\n24:[\"$\",\"$L25\",\"32\",{}]\n"])</script><script>self.__next_f.push([1,"26:I[707934,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"WebMcpRegistration\"]\n"])</script><script>self.__next_f.push([1,"27:I[590280,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"LivePreviewProvider\"]\n"])</script><script>self.__next_f.push([1,"28:I[973254,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"LivePreviewFavicon\"]\n"])</script><script>self.__next_f.push([1,"29:I[197336,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"default\"]\n"])</script><script>self.__next_f.push([1,"2a:I[91557,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cee6f6b26d68395d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/0eb894a8519f24ea.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/fb156bebf42da1e9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/2dd53f5a4cfe6dd5.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/e95beff806b7ab98.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8a30b6291cd9465f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/893b80a74cde24cd.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c0e7a98cd764702e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"AuthProvider\"]\n"])</script><script>self.__next_f.push([1,"2b:I[91557,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cee6f6b26d68395d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/0eb894a8519f24ea.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/fb156bebf42da1e9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/2dd53f5a4cfe6dd5.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/e95beff806b7ab98.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8a30b6291cd9465f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/893b80a74cde24cd.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c0e7a98cd764702e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"DeploymentMetadataProvider\"]\n"])</script><script>self.__next_f.push([1,"2c:I[91557,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cee6f6b26d68395d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/0eb894a8519f24ea.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/fb156bebf42da1e9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/2dd53f5a4cfe6dd5.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/e95beff806b7ab98.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8a30b6291cd9465f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/893b80a74cde24cd.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c0e7a98cd764702e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"DocsConfigProvider\"]\n"])</script><script>self.__next_f.push([1,"18:[null,[\"$\",\"$L26\",null,{\"subdomain\":\"openrouter-d02e98a0\"}],[\"$\",\"$L27\",null,{\"isLivePreviewRoute\":false,\"children\":[[\"$\",\"$L28\",null,{}],[\"$\",\"$L11\",null,{\"appearance\":{\"default\":\"dark\"},\"codeblockTheme\":\"system\",\"children\":[[\"$\",\"blockquote\",null,{\"className\":\"sr-only\",\"data-agent-docs-index\":true,\"aria-hidden\":\"true\",\"children\":[[\"$\",\"h2\",null,{\"children\":\"Documentation Index\"}],[\"$\",\"p\",null,{\"children\":[\"Fetch the complete documentation index at:\",\" \",[\"$\",\"a\",null,{\"href\":\"/docs/llms.txt\",\"tabIndex\":-1,\"children\":\"/docs/llms.txt\"}]]}],[\"$\",\"p\",null,{\"children\":\"Use this file to discover all available pages before exploring further.\"}]]}],[\"$\",\"style\",null,{\"dangerouslySetInnerHTML\":{\"__html\":\":root{--banner-height:0px!important}\"}}],false,null,null,[\"$\",\"script\",null,{\"id\":\"_mintlify-banner-script\",\"dangerouslySetInnerHTML\":{\"__html\":\"(function i(a,b,c,d,e){try{let f,g,h=[];try{h=window.location.pathname.split(\\\"/\\\").filter(a=\u003e\\\"\\\"!==a\u0026\u0026\\\"global\\\"!==a).slice(0,2)}catch{h=[]}let i=h.find(a=\u003ec.includes(a)),j=[];for(let c of(i?j.push(i):j.push(b),j.push(\\\"global\\\"),j)){if(!c)continue;let b=a[c];if(b?.content){f=b.content,g=c;break}}if(!f)return void document.documentElement.setAttribute(d,\\\"hidden\\\");let k=!0,l=0;for(;l\u003clocalStorage.length;){let a=localStorage.key(l);if(l++,!a?.endsWith(e))continue;let b=localStorage.getItem(a);if(b\u0026\u0026b===f){k=!1;break}g\u0026\u0026(a.startsWith(`lang:${g}_`)||!a.startsWith(\\\"lang:\\\"))\u0026\u0026(localStorage.removeItem(a),l--)}document.documentElement.setAttribute(d,k?\\\"visible\\\":\\\"hidden\\\")}catch(a){console.error(a),document.documentElement.setAttribute(d,\\\"hidden\\\")}})(\\n  {},\\n  \\\"en\\\",\\n  [],\\n  \\\"data-banner-state\\\",\\n  \\\"bannerDismissed\\\",\\n)\"}}],[\"$\",\"$L29\",null,{\"appId\":\"$undefined\",\"autoBoot\":true,\"children\":[\"$\",\"$L2a\",null,{\"value\":{\"auth\":\"$undefined\",\"userAuth\":\"$undefined\"},\"children\":[\"$\",\"$L2b\",null,{\"value\":{\"subdomain\":\"openrouter-d02e98a0\",\"actualSubdomain\":\"openrouter-d02e98a0\",\"customDomains\":[\"openrouter.ai\"],\"gitSource\":{\"type\":\"github\",\"owner\":\"openrouterteam\",\"repo\":\"docs\",\"deployBranch\":\"main\",\"contentDirectory\":\"\",\"isPrivate\":false,\"mountPath\":\"\",\"label\":\"\"},\"chroma\":{\"collectionId\":\"3f7e317b-7582-480f-a2f8-336e8734b5fe\",\"liveDeploymentHistoryId\":\"6a9b8b8e46987cc436a9326b\",\"schemaVersion\":\"v3\",\"latestBuiltDeploymentHistoryId\":\"6a9b8b8e46987cc436a9326b\"},\"feedback\":{\"contextualFeedback\":{\"allowEmail\":false},\"agentFeedback\":true,\"issues\":false},\"entitlements\":{\"AI_CHAT\":{\"status\":\"ENABLED\"},\"REMOVE_BRANDING\":{\"status\":\"ENABLED\"},\"CONTEXTUAL_FEEDBACK\":{\"status\":\"ENABLED\"},\"CODE_SNIPPET_FEEDBACK\":{\"status\":\"ENABLED\"}},\"buildId\":\"6a9bb2d1f116e1099422128c\",\"clientVersion\":\"0.0.3558\",\"preview\":\"$undefined\",\"searchFilterCounts\":[{\"language\":\"default\",\"tag\":\"API Reference\",\"count\":225},{\"language\":\"default\",\"tag\":\"Client SDKs\",\"count\":184},{\"language\":\"default\",\"tag\":\"Docs\",\"count\":131},{\"language\":\"default\",\"tag\":\"Cookbook\",\"count\":48},{\"language\":\"default\",\"tag\":\"Features\",\"count\":45},{\"language\":\"default\",\"tag\":\"Agent SDK\",\"count\":42},{\"language\":\"default\",\"tag\":\"Go SDK\",\"count\":30},{\"language\":\"default\",\"tag\":\"Python SDK\",\"count\":30},{\"language\":\"default\",\"tag\":\"TypeScript SDK\",\"count\":28},{\"language\":\"default\",\"tag\":\"Overview\",\"count\":22}],\"searchSettings\":\"$undefined\",\"disableKonamiCode\":\"$undefined\"},\"children\":[\"$\",\"$L2c\",null,{\"value\":{\"docsConfig\":{\"theme\":\"mint\",\"$schema\":\"https://mintlify.com/docs.json\",\"name\":\"OpenRouter | Documentation\",\"colors\":{\"primary\":\"#7624F4\",\"light\":\"#7624F4\",\"dark\":\"#C8FF00\"},\"logo\":{\"light\":\"https://mintcdn.com/openrouter-d02e98a0/ksNSeB_K7gD-BUDh/assets/logo-v2-light.svg?fit=max\u0026auto=format\u0026n=ksNSeB_K7gD-BUDh\u0026q=85\u0026s=690e45873843519efe02bcbe45795dac\",\"dark\":\"https://mintcdn.com/openrouter-d02e98a0/ksNSeB_K7gD-BUDh/assets/logo-v2-dark.svg?fit=max\u0026auto=format\u0026n=ksNSeB_K7gD-BUDh\u0026q=85\u0026s=8ba2f49b11cd9839c37dd03c62537ebd\",\"href\":\"https://openrouter.ai\"},\"favicon\":\"https://mintcdn.com/openrouter-d02e98a0/n3IgkjAMQY8SgOLX/assets/favicon-v2.svg?fit=max\u0026auto=format\u0026n=n3IgkjAMQY8SgOLX\u0026q=85\u0026s=f49800815fcadee8a07dcc093051c2de\",\"appearance\":\"$18:2:props:children:1:props:appearance\",\"background\":{\"color\":{\"light\":\"#FCFCFE\",\"dark\":\"#03080A\"}},\"navbar\":{\"links\":[{\"href\":\"https://openrouter.ai/models\",\"label\":\"Models\"},{\"href\":\"https://openrouter.ai/benchmarks\",\"label\":\"Benchmarks\"},{\"href\":\"https://openrouter.ai/chat\",\"label\":\"Chat\"},{\"href\":\"https://openrouter.ai/rankings\",\"label\":\"Rankings\"},{\"href\":\"https://openrouter.ai/apps\",\"label\":\"Apps\"}],\"primary\":{\"type\":\"button\",\"label\":\"Sign In\",\"href\":\"https://openrouter.ai/sign-in\"}},\"seo\":{\"metatags\":{\"canonical\":\"https://openrouter.ai/docs\"}},\"fonts\":{\"family\":\"Plus Jakarta Sans\",\"weight\":400},\"integrations\":{\"ga4\":{\"measurementId\":\"G-R8YZRJS2XN\"},\"posthog\":{\"apiKey\":\"phc_7ToS2jDeWBlMu4n2JoNzoA1FnArdKwFMFoHVnAqQ6O1\",\"apiHost\":\"https://us.i.posthog.com\"}},\"contextual\":{\"options\":[\"copy\",\"view\",\"chatgpt\",\"claude\",\"perplexity\"],\"display\":\"header\"},\"styling\":{\"latex\":true,\"codeblocks\":\"system\"},\"navigation\":{\"pages\":[]}},\"docsNavWithMetadata\":\"$undefined\",\"anonymizedNav\":\"$undefined\",\"hasFullNav\":false},\"children\":\"$L2d\"}]}]}]}]]}]]}]]\n"])</script><script>self.__next_f.push([1,"2e:I[604804,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"LoginButtonProvider\"]\n"])</script><script>self.__next_f.push([1,"2f:I[141180,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"SidebarLoginButtonProvider\"]\n"])</script><script>self.__next_f.push([1,"30:I[343590,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"NavigationContextController\"]\n"])</script><script>self.__next_f.push([1,"31:I[378486,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"PageListProvider\"]\n"])</script><script>self.__next_f.push([1,"32:I[742977,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"PrefetchProvider\"]\n"])</script><script>self.__next_f.push([1,"33:I[237978,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"PageModeOverrideProvider\"]\n"])</script><script>self.__next_f.push([1,"34:I[378896,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"ConfiguredVariationProvider\"]\n"])</script><script>self.__next_f.push([1,"35:I[557611,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"Fonts\"]\n"])</script><script>self.__next_f.push([1,"36:I[330080,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"BannerProvider\"]\n"])</script><script>self.__next_f.push([1,"37:I[864506,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"NavbarTransitionScript\"]\n"])</script><script>self.__next_f.push([1,"38:T9e0,"])</script><script>self.__next_f.push([1,"(function () {\n  var measure = function(){let a=document.querySelectorAll(\"[id='navbar'], [data-top-chrome]\"),b=0;a.forEach(a=\u003e{let c=a.getBoundingClientRect();c.height\u003e0\u0026\u0026(b=Math.max(b,c.bottom))});let c=0,d=document.getElementById(\"content-container\");if(d){let{overflowY:a}=getComputedStyle(d);(\"auto\"===a||\"scroll\"===a)\u0026\u0026(c=Math.max(0,d.getBoundingClientRect().top))}let e=`${Math.round(Math.max(0,b-c))+40}px`,f=document.documentElement.style;f.getPropertyValue(\"--scroll-mt\")!==e\u0026\u0026f.setProperty(\"--scroll-mt\",e)};\n  (function(a){let b=[],c=0,d=\"undefined\"==typeof ResizeObserver?null:new ResizeObserver(f);function e(){let c=Array.from(document.querySelectorAll(\"[id='navbar'], [data-top-chrome]\"));(c.length!==b.length||c.some((a,c)=\u003ea!==b[c]))\u0026\u0026d\u0026\u0026(d.disconnect(),c.forEach(a=\u003ed.observe(a))),b=c,a()}function f(){c||(c=requestAnimationFrame(()=\u003e{c=0,e()}))}let g=\"[id='navbar'], [data-top-chrome]\";function h(a){let b=a.target;if(b instanceof Element\u0026\u0026b.closest(g))return!0;for(let b of a.addedNodes)if(b instanceof Element\u0026\u0026(b.matches(g)||b.querySelector(g)))return!0;for(let b of a.removedNodes)if(b instanceof Element\u0026\u0026(b.matches(g)||b.querySelector(g)))return!0;return!1}new MutationObserver(a=\u003e{a.some(h)\u0026\u0026f()}).observe(document.documentElement,{childList:!0,subtree:!0}),window.addEventListener(\"resize\",f),\"loading\"===document.readyState\u0026\u0026document.addEventListener(\"DOMContentLoaded\",e),e()})(measure);\n  (function(a){let b=window.location.hash.slice(1);if(!b)return;function c(){return\"smooth\"===getComputedStyle(document.documentElement).scrollBehavior}function d(c){let d=document.getElementById(b);return!!d\u0026\u0026(a(),d.scrollIntoView(c?{behavior:c}:void 0),!0)}if(\"complete\"===document.readyState)return void d();let e=new MutationObserver(()=\u003e{!c()\u0026\u0026d(\"instant\")\u0026\u0026f()});function f(){e.disconnect(),window.removeEventListener(\"load\",g)}function g(){let a=c();f(),a\u0026\u0026requestAnimationFrame(()=\u003e{d(),function(){let a=[\"wheel\",\"touchstart\",\"keydown\",\"pointerdown\"],c=0,e=window.scrollY,f=setInterval(()=\u003e{c+=1;let a=document.getElementById(b);if(!a||c\u003e=6)return g();let f=Math.abs(window.scrollY-e)\u003e1;if(e=window.scrollY,f)return;let h=parseFloat(getComputedStyle(a).scrollMarginTop)||0;Math.abs(a.getBoundingClientRect().top-h)\u003e4\u0026\u0026d()},350);function g(){clearInterval(f),a.forEach(a=\u003ewindow.removeEventListener(a,g))}a.forEach(a=\u003ewindow.addEventListener(a,g,{passive:!0}))}()})}window.addEventListener(\"load\",g),e.observe(document.documentElement,{childList:!0,subtree:!0}),!c()\u0026\u0026d(\"instant\")\u0026\u0026f()})(measure);\n})();"])</script><script>self.__next_f.push([1,"2d:[\"$\",\"$L2e\",null,{\"children\":[\"$\",\"$L2f\",null,{\"children\":[\"$\",\"$L30\",null,{\"children\":[\"$\",\"$L31\",null,{\"pageListDataMap\":{},\"children\":[\"$\",\"$L32\",null,{\"disabled\":\"$undefined\",\"children\":[\"$\",\"$L33\",null,{\"children\":[\"$\",\"$L34\",null,{\"children\":[[\"$\",\"$L13\",null,{\"fonts\":\"$18:2:props:children:1:props:children:6:props:children:props:children:props:children:props:value:docsConfig:fonts\",\"theme\":\"mint\",\"subdomain\":\"openrouter-d02e98a0\"}],[[\"$\",\"$L12\",null,{\"docsConfig\":\"$18:2:props:children:1:props:children:6:props:children:props:children:props:children:props:value:docsConfig\"}],[[\"$\",\"link\",null,{\"rel\":\"preload\",\"href\":\"https://d4tuoctqmanu0.cloudfront.net/katex.min.css\",\"as\":\"style\"}],[\"$\",\"script\",null,{\"type\":\"text/javascript\",\"children\":\"\\n          (function() {\\n            function loadKatex() {\\n              const link = document.querySelector('link[href=\\\"https://d4tuoctqmanu0.cloudfront.net/katex.min.css\\\"]');\\n              if (link) link.rel = 'stylesheet';\\n            }\\n            if (document.readyState === 'loading') {\\n              document.addEventListener('DOMContentLoaded', loadKatex);\\n            } else {\\n              loadKatex();\\n            }\\n          })();\\n        \"}]],[\"$\",\"$L14\",null,{\"theme\":\"mint\"}],[\"$\",\"$L35\",null,{\"fonts\":\"$18:2:props:children:1:props:children:6:props:children:props:children:props:children:props:value:docsConfig:fonts\",\"children\":[\"$\",\"$L36\",null,{\"bannersByLocale\":{},\"subdomain\":\"openrouter-d02e98a0\",\"children\":[[\"$\",\"$L37\",null,{\"theme\":\"mint\"}],[\"$\",\"script\",null,{\"id\":\"_mintlify-scroll-margin-script\",\"dangerouslySetInnerHTML\":{\"__html\":\"$38\"},\"suppressHydrationWarning\":true}],\"$L39\"]}]}]]]}]}]}]}]}]}]}]\n"])</script><script>self.__next_f.push([1,"3a:I[540345,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"ConsentProvider\"]\n"])</script><script>self.__next_f.push([1,"3b:I[529058,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"LocalStorageAndAnalyticsProviders\"]\n"])</script><script>self.__next_f.push([1,"3c:I[958547,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"default\"]\n"])</script><script>self.__next_f.push([1,"3d:I[604780,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"CaptchaProvider\"]\n"])</script><script>self.__next_f.push([1,"3e:I[601054,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"SearchProvider\"]\n"])</script><script>self.__next_f.push([1,"3f:I[28330,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"SkipToContent\"]\n"])</script><script>self.__next_f.push([1,"39:[\"$\",\"$L3a\",null,{\"privacy\":\"$undefined\",\"children\":[\"$\",\"$L3b\",null,{\"subdomain\":\"openrouter-d02e98a0\",\"isAtlas\":false,\"children\":[\"$\",\"$L3c\",null,{\"toggles\":[{\"name\":\"dashboard-editor-theseus\",\"enabled\":true,\"variant\":{\"name\":\"disabled\",\"enabled\":false,\"feature_enabled\":true},\"impressionData\":false},{\"name\":\"kill-isr\",\"enabled\":true,\"variant\":{\"name\":\"disabled\",\"enabled\":false,\"feature_enabled\":true},\"impressionData\":false},{\"name\":\"agent-mintlify-slack\",\"enabled\":true,\"variant\":{\"name\":\"disabled\",\"enabled\":false,\"feature_enabled\":true},\"impressionData\":false},{\"name\":\"editor-v7-file-tree\",\"enabled\":true,\"variant\":{\"name\":\"disabled\",\"enabled\":false,\"feature_enabled\":true},\"impressionData\":false},{\"name\":\"agent-integrations-settings\",\"enabled\":true,\"variant\":{\"name\":\"disabled\",\"enabled\":false,\"feature_enabled\":true},\"impressionData\":false},{\"name\":\"automations-pr-grouping\",\"enabled\":true,\"variant\":{\"name\":\"disabled\",\"enabled\":false,\"feature_enabled\":true},\"impressionData\":false},{\"name\":\"custom-prefix\",\"enabled\":true,\"variant\":{\"name\":\"disabled\",\"enabled\":false,\"feature_enabled\":true},\"impressionData\":false},{\"name\":\"analytics-v7\",\"enabled\":true,\"variant\":{\"name\":\"disabled\",\"enabled\":false,\"feature_enabled\":true},\"impressionData\":false},{\"name\":\"user-flows-analytics\",\"enabled\":true,\"variant\":{\"name\":\"disabled\",\"enabled\":false,\"feature_enabled\":true},\"impressionData\":false},{\"name\":\"no-publish-flow\",\"enabled\":true,\"variant\":{\"name\":\"disabled\",\"enabled\":false,\"feature_enabled\":true},\"impressionData\":false},{\"name\":\"llms-txt-v2\",\"enabled\":true,\"variant\":{\"name\":\"disabled\",\"enabled\":false,\"feature_enabled\":true},\"impressionData\":false},{\"name\":\"pause-universal-search-reconcile\",\"enabled\":true,\"variant\":{\"name\":\"disabled\",\"enabled\":false,\"feature_enabled\":true},\"impressionData\":false},{\"name\":\"snapshot-serving-live\",\"enabled\":true,\"variant\":{\"name\":\"disabled\",\"enabled\":false,\"feature_enabled\":true},\"impressionData\":false},{\"name\":\"stripTemperatureMiddleware\",\"enabled\":true,\"variant\":{\"name\":\"disabled\",\"enabled\":false,\"feature_enabled\":true},\"impressionData\":false},{\"name\":\"per-site-search-delta\",\"enabled\":true,\"variant\":{\"name\":\"disabled\",\"enabled\":false,\"feature_enabled\":true},\"impressionData\":false},{\"name\":\"editor-branches-v2-autocommit\",\"enabled\":true,\"variant\":{\"name\":\"disabled\",\"enabled\":false,\"feature_enabled\":true},\"impressionData\":false},{\"name\":\"editor-branches-v2\",\"enabled\":true,\"variant\":{\"name\":\"disabled\",\"enabled\":false,\"feature_enabled\":true},\"impressionData\":false},{\"name\":\"snapshot-serving\",\"enabled\":true,\"variant\":{\"name\":\"disabled\",\"enabled\":false,\"feature_enabled\":true},\"impressionData\":false},{\"name\":\"instant-rollback\",\"enabled\":true,\"variant\":{\"name\":\"disabled\",\"enabled\":false,\"feature_enabled\":true},\"impressionData\":false},{\"name\":\"granular-notifications-server\",\"enabled\":true,\"variant\":{\"name\":\"disabled\",\"enabled\":false,\"feature_enabled\":true},\"impressionData\":false},{\"name\":\"granular-notifications\",\"enabled\":true,\"variant\":{\"name\":\"disabled\",\"enabled\":false,\"feature_enabled\":true},\"impressionData\":false},{\"name\":\"editor-private-page-search\",\"enabled\":true,\"variant\":{\"name\":\"disabled\",\"enabled\":false,\"feature_enabled\":true},\"impressionData\":false},{\"name\":\"automations-fable\",\"enabled\":true,\"variant\":{\"name\":\"disabled\",\"enabled\":false,\"feature_enabled\":true},\"impressionData\":false}],\"children\":[\"$\",\"$L3d\",null,{\"enabled\":true,\"isPreview\":false,\"children\":[\"$\",\"$L3e\",null,{\"subdomain\":\"openrouter-d02e98a0\",\"hasChatPermissions\":true,\"isLoggedInCli\":false,\"assistantConfig\":{\"enableAskAiButton\":false,\"enableStarterQuestions\":false,\"enableContextualStarterQuestions\":false,\"enableAskAiSearchBar\":true},\"starterQuestions\":\"$undefined\",\"children\":[[\"$\",\"$L3f\",null,{}],[\"$\",\"script\",null,{\"dangerouslySetInnerHTML\":{\"__html\":\"(function i(a,b,c,d){try{if(window.matchMedia(\\\"(max-width: 1024px)\\\").matches||!d){document.documentElement.style.setProperty(c,\\\"0px\\\"),document.documentElement.setAttribute(\\\"data-assistant-state\\\",\\\"closed\\\"),d||localStorage.setItem(a,\\\"false\\\");return}let e=localStorage.getItem(a);if(null===e){document.documentElement.style.setProperty(c,\\\"0px\\\"),document.documentElement.setAttribute(\\\"data-assistant-state\\\",\\\"closed\\\");return}let f=JSON.parse(e),g=localStorage.getItem(b),h=null!==g?JSON.parse(g):368;document.documentElement.style.setProperty(c,f?h+\\\"px\\\":\\\"0px\\\"),document.documentElement.setAttribute(\\\"data-assistant-state\\\",f?\\\"open\\\":\\\"closed\\\")}catch(a){document.documentElement.style.setProperty(c,\\\"0px\\\"),document.documentElement.setAttribute(\\\"data-assistant-state\\\",\\\"closed\\\")}})(\\n    \\\"chat-assistant-sheet-open\\\",\\n    \\\"chat-assistant-sheet-width\\\",\\n    \\\"--assistant-sheet-width\\\",\\n    true\\n  )\"}}],false,\"$L40\"]}]}]}]}]}]\n"])</script><script>self.__next_f.push([1,"41:I[87732,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"AssistantLayoutWrapper\"]\n"])</script><script>self.__next_f.push([1,"42:I[118717,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ef83d4b60122b4a4.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"NotFoundHydrator\"]\n"])</script><script>self.__next_f.push([1,"40:[\"$\",\"$L41\",null,{\"children\":[[\"$\",\"$Le\",null,{\"parallelRouterKey\":\"children\",\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$L10\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":[[\"$\",\"$L42\",null,{\"source\":\"multitenant\"}],[]],\"forbidden\":\"$undefined\",\"unauthorized\":\"$undefined\"}],\"$undefined\"]}]\n"])</script><script>self.__next_f.push([1,"43:I[597003,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cee6f6b26d68395d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/0eb894a8519f24ea.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/fb156bebf42da1e9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/2dd53f5a4cfe6dd5.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/e95beff806b7ab98.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8a30b6291cd9465f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/893b80a74cde24cd.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c0e7a98cd764702e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"ScopedNavProvider\"]\n"])</script><script>self.__next_f.push([1,"44:T5ef,"])</script><script>self.__next_f.push([1,"Returns the top public apps on OpenRouter ranked by token usage inside the requested\ndate window, matching the public apps marketplace on openrouter.ai/apps. Token totals\nare `prompt_tokens + completion_tokens`; hidden and private apps are excluded and\ntraffic from related app aliases is merged into the canonical visible app.\n\n`sort=popular` (default) ranks by total token volume inside the window.\n`sort=trending` ranks by absolute excess token growth: window volume minus the average\nvolume of the three equal-length periods immediately preceding the window. Apps with\nno excess growth are omitted, so `trending` may return fewer than `limit` rows.\n\nFilter with `category` (marketplace category group, e.g. `coding`) or `subcategory`\n(e.g. `cli-agent`). Ranks are re-numbered 1..N after filtering. Page with `offset` —\n`rank` stays absolute, so the first row of `offset=50` is `rank: 51`.\n\nAuthenticate with any valid OpenRouter API key (same key used for inference).\nRate-limited to 30 requests/minute per key and 500 requests/day per account.\n\nWhen republishing or quoting this dataset, OpenRouter must be cited as:\n\"Source: OpenRouter (openrouter.ai/apps), as of {as_of}.\"\n\nToken counts come from each upstream provider's own tokenizer, so a token attributed\nto one app is not directly comparable to a token attributed to another app whose\ntraffic flows through a different provider.\n\nLicensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/): reuse and republish with attribution to OpenRouter."])</script><script>self.__next_f.push([1,"45:T677,"])</script><script>self.__next_f.push([1,"Returns the top 50 public models per day by total token usage on OpenRouter, plus a\nsingle aggregated `other` row per day that sums every model outside that top 50.\nToken totals are `prompt_tokens + completion_tokens`, matching the public rankings\nchart on openrouter.ai/rankings.\n\nEach row is a distinct `(date, model_permaslug)` pair. The `other` row uses the\nreserved permaslug `other` and is always returned last within its date, so callers\ncan compute `top-50 traffic / total daily traffic` without a second request.\n\nOptional filters slice the dataset. `period` (`day`/`week`/`month`) sets the time\ngrain. `modality` and `context_bucket` narrow the exact dataset by output/input\nmodality (or tool-calling activity) and request context length. `category` and\n`language_type` instead read a sampled, upsampled dataset whose `total_tokens` are\nweekly-grain estimates — they cannot be combined with each other or with the exact\nfilters, and reject `period=day` with a 400.\n\nAuthenticate with any valid OpenRouter API key (same key used for inference).\nRate-limited to 30 requests/minute per key and 500 requests/day per account.\n\nWhen republishing or quoting this dataset, OpenRouter must be cited as:\n\"Source: OpenRouter (openrouter.ai/rankings), as of {as_of}.\"\n\nToken counts come from each upstream provider's own tokenizer (Anthropic counts\nare as reported by Anthropic, OpenAI counts are as reported by OpenAI, etc.), so\na token in one row is not directly comparable to a token in another row from a\ndifferent provider.\n\nLicensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/): reuse and republish with attribution to OpenRouter."])</script><script>self.__next_f.push([1,"19:[\"$\",\"$L43\",null,{\"scopedNav\":{\"global\":null,\"tabs\":[{\"tab\":\"Docs\",\"icon\":\"book\",\"pages\":[{\"title\":\"Docs\",\"href\":\"/quickstart\"}]},{\"tab\":\"API Reference\",\"icon\":\"code\",\"groups\":[{\"group\":\"API Guides\",\"icon\":\"code\",\"pages\":[{\"title\":\"API Reference\",\"description\":\"An overview of OpenRouter's API\",\"seoTitle\":\"OpenRouter API Reference | Complete API Documentation\",\"og:site_name\":\"OpenRouter Documentation\",\"og:title\":\"OpenRouter API Reference - Complete Documentation\",\"og:description\":\"Comprehensive guide to OpenRouter's API. Learn about request/response schemas, authentication, parameters, and integration with multiple AI model providers.\",\"og:image\":\"https://openrouter.ai/dynamic-og?title=OpenRouter%20API%20Reference\u0026description=Comprehensive%20guide%20to%20OpenRouter's%20API.\",\"og:image:width\":1200,\"og:image:height\":630,\"twitter:card\":\"summary_large_image\",\"twitter:site\":\"@OpenRouter\",\"noindex\":false,\"nofollow\":false,\"icon\":\"book-open\",\"sidebarTitle\":\"Overview\",\"href\":\"/api_reference/overview\"},{\"title\":\"Streaming\",\"seoTitle\":\"API Streaming | Real-time Model Responses in OpenRouter\",\"og:site_name\":\"OpenRouter Documentation\",\"og:title\":\"API Streaming - Real-time Model Response Integration\",\"og:description\":\"Learn how to implement streaming responses with OpenRouter's API. Complete guide to Server-Sent Events (SSE) and real-time model outputs.\",\"og:image\":\"https://openrouter.ai/dynamic-og?title=API%20Streaming\u0026description=Real-time%20model%20response%20streaming\",\"og:image:width\":1200,\"og:image:height\":630,\"twitter:card\":\"summary_large_image\",\"twitter:site\":\"@OpenRouter\",\"noindex\":false,\"nofollow\":false,\"icon\":\"bars-staggered\",\"description\":null,\"href\":\"/api_reference/streaming\"},{\"title\":\"Embeddings\",\"description\":\"Generate vector embeddings from text and images\",\"seoTitle\":\"Embeddings API | Convert Text and Images to Vector Representations with OpenRouter\",\"og:site_name\":\"OpenRouter Documentation\",\"og:title\":\"Embeddings API - Generate Vector Embeddings from Text and Images\",\"og:description\":\"Generate vector embeddings from text and images using OpenRouter's unified embeddings API. Access multiple embedding models from different providers with a single interface.\",\"og:image\":\"https://openrouter.ai/dynamic-og?title=Embeddings%20API\u0026description=Generate%20Vector%20Embeddings%20from%20Text%20and%20Images\",\"og:image:width\":1200,\"og:image:height\":630,\"twitter:card\":\"summary_large_image\",\"twitter:site\":\"@OpenRouter\",\"noindex\":false,\"nofollow\":false,\"icon\":\"draw-square\",\"href\":\"/api_reference/embeddings\"},{\"title\":\"Limits\",\"description\":\"Credit Limits and Rate Limits\",\"seoTitle\":\"API Credit \u0026 Rate Limits | Handle 402 and 429 Errors in OpenRouter\",\"og:site_name\":\"OpenRouter Documentation\",\"og:title\":\"API Credit \u0026 Rate Limits - Handle 402 and 429 Errors\",\"og:description\":\"Learn about OpenRouter's credit limits (402) and rate limits (429), free-model quotas, and DDoS protection. Monitor usage and handle limit errors effectively.\",\"og:image\":\"https://openrouter.ai/dynamic-og?title=API%20Credit%20%26%20Rate%20Limits\u0026description=Handle%20402%20and%20429%20Errors\",\"og:image:width\":1200,\"og:image:height\":630,\"twitter:card\":\"summary_large_image\",\"twitter:site\":\"@OpenRouter\",\"noindex\":false,\"nofollow\":false,\"icon\":\"gauge-high\",\"href\":\"/api_reference/limits\"},{\"title\":\"Authentication\",\"description\":\"API Authentication\",\"seoTitle\":\"API Authentication | OpenRouter OAuth and API Keys\",\"og:site_name\":\"OpenRouter Documentation\",\"og:title\":\"API Authentication - Secure Access to OpenRouter\",\"og:description\":\"Learn how to authenticate with OpenRouter using API keys and Bearer tokens. Complete guide to secure authentication methods and best practices.\",\"og:image\":\"https://openrouter.ai/dynamic-og?title=API%20Authentication\u0026description=Secure%20access%20to%20OpenRouter\",\"og:image:width\":1200,\"og:image:height\":630,\"twitter:card\":\"summary_large_image\",\"twitter:site\":\"@OpenRouter\",\"noindex\":false,\"nofollow\":false,\"icon\":\"lock\",\"href\":\"/api_reference/authentication\"},{\"title\":\"Parameters\",\"seoTitle\":\"API Parameters | Configure OpenRouter API Requests\",\"og:site_name\":\"OpenRouter Documentation\",\"og:title\":\"API Parameters - Complete Guide to Request Configuration\",\"og:description\":\"Learn about all available parameters for OpenRouter API requests. Configure temperature, max tokens, top_p, and other model-specific settings.\",\"og:image\":\"https://openrouter.ai/dynamic-og?title=API%20Parameters\u0026description=Complete%20guide%20to%20request%20configuration\",\"og:image:width\":1200,\"og:image:height\":630,\"twitter:card\":\"summary_large_image\",\"twitter:site\":\"@OpenRouter\",\"noindex\":false,\"nofollow\":false,\"icon\":\"gear\",\"description\":null,\"href\":\"/api_reference/parameters\"},{\"title\":\"Errors and Debugging\",\"description\":\"API Errors and Debugging\",\"seoTitle\":\"API Error Handling and Debugging | OpenRouter Documentation\",\"og:site_name\":\"OpenRouter Documentation\",\"og:title\":\"API Error Handling and Debugging - Complete Guide\",\"og:description\":\"Learn how to handle errors and debug requests in OpenRouter API interactions. Comprehensive guide to error codes, messages, debugging options, and best practices.\",\"og:image\":\"https://openrouter.ai/dynamic-og?title=API%20Error%20Handling%20and%20Debugging\u0026description=Learn%20how%20to%20handle%20errors%20and%20debug%20requests%20in%20OpenRouter%20API%20interactions.\",\"og:image:width\":1200,\"og:image:height\":630,\"twitter:card\":\"summary_large_image\",\"twitter:site\":\"@OpenRouter\",\"noindex\":false,\"nofollow\":false,\"icon\":\"triangle-exclamation\",\"href\":\"/api_reference/errors-and-debugging\"},{\"group\":\"Responses API\",\"icon\":\"reply\",\"pages\":[{\"title\":\"Responses API\",\"sidebarTitle\":\"Overview\",\"description\":\"OpenAI-compatible Responses API\",\"seoTitle\":\"OpenRouter Responses API\",\"og:site_name\":\"OpenRouter Documentation\",\"og:title\":\"OpenRouter Responses API - OpenAI-Compatible Documentation\",\"og:description\":\"OpenRouter's OpenAI-compatible Responses API. Stateless transformation layer with support for reasoning, tool calling, and web search.\",\"og:image\":\"https://openrouter.ai/dynamic-og?title=Responses%20API\u0026description=OpenAI-compatible%20stateless%20API\",\"og:image:width\":1200,\"og:image:height\":630,\"twitter:card\":\"summary_large_image\",\"twitter:site\":\"@OpenRouter\",\"noindex\":false,\"nofollow\":false,\"icon\":\"compass\",\"href\":\"/api_reference/responses/overview\"},{\"title\":\"Basic Usage\",\"description\":\"Getting started with the Responses API\",\"seoTitle\":\"Responses API Basic Usage | Simple Text Requests\",\"og:site_name\":\"OpenRouter Documentation\",\"og:title\":\"Responses API Basic Usage - Simple Text Requests\",\"og:description\":\"Learn the basics of OpenRouter's Responses API with simple text input examples and response handling.\",\"og:image\":\"https://openrouter.ai/dynamic-og?title=Responses%20API%20Basic%20Usage\u0026description=Simple%20text%20requests%20and%20responses\",\"og:image:width\":1200,\"og:image:height\":630,\"twitter:card\":\"summary_large_image\",\"twitter:site\":\"@OpenRouter\",\"noindex\":false,\"nofollow\":false,\"icon\":\"play\",\"href\":\"/api_reference/responses/basic-usage\"},{\"title\":\"Reasoning\",\"description\":\"Advanced reasoning capabilities with the Responses API\",\"seoTitle\":\"Responses API Reasoning | Advanced AI Reasoning Capabilities\",\"og:site_name\":\"OpenRouter Documentation\",\"og:title\":\"Responses API Reasoning - Advanced AI Reasoning\",\"og:description\":\"Access advanced reasoning capabilities with configurable effort levels and encrypted reasoning chains using OpenRouter's Responses API.\",\"og:image\":\"https://openrouter.ai/dynamic-og?title=Responses%20API%20Reasoning\u0026description=Advanced%20AI%20reasoning%20capabilities\",\"og:image:width\":1200,\"og:image:height\":630,\"twitter:card\":\"summary_large_image\",\"twitter:site\":\"@OpenRouter\",\"noindex\":false,\"nofollow\":false,\"icon\":\"lightbulb\",\"href\":\"/api_reference/responses/reasoning\"},{\"title\":\"Tool Calling\",\"description\":\"Function calling and tool integration with the Responses API\",\"seoTitle\":\"Responses API Tool Calling | Function Calling Integration\",\"og:site_name\":\"OpenRouter Documentation\",\"og:title\":\"Responses API Tool Calling - Function Calling Integration\",\"og:description\":\"Integrate function calling with support for parallel execution and complex tool interactions using OpenRouter's Responses API.\",\"og:image\":\"https://openrouter.ai/dynamic-og?title=Responses%20API%20Tool%20Calling\u0026description=Function%20calling%20integration\",\"og:image:width\":1200,\"og:image:height\":630,\"twitter:card\":\"summary_large_image\",\"twitter:site\":\"@OpenRouter\",\"noindex\":false,\"nofollow\":false,\"icon\":\"toolbox\",\"href\":\"/api_reference/responses/tool-calling\"},{\"title\":\"Web Search\",\"description\":\"Real-time web search integration with the Responses API\",\"seoTitle\":\"Responses API Web Search | Real-time Information Retrieval\",\"og:site_name\":\"OpenRouter Documentation\",\"og:title\":\"Responses API Web Search - Real-time Information Retrieval\",\"og:description\":\"Enable web search capabilities with real-time information retrieval and citation annotations using OpenRouter's Responses API.\",\"og:image\":\"https://openrouter.ai/dynamic-og?title=Responses%20API%20Web%20Search\u0026description=Real-time%20information%20retrieval\",\"og:image:width\":1200,\"og:image:height\":630,\"twitter:card\":\"summary_large_image\",\"twitter:site\":\"@OpenRouter\",\"noindex\":false,\"nofollow\":false,\"icon\":\"globe-pointer\",\"href\":\"/api_reference/responses/web-search\"},{\"title\":\"Error Handling\",\"description\":\"Understanding and handling errors in the Responses API\",\"seoTitle\":\"Responses API Error Handling | Basic Error Guide\",\"og:site_name\":\"OpenRouter Documentation\",\"og:title\":\"Responses API Error Handling - Basic Error Guide\",\"og:description\":\"Learn how to handle errors in OpenRouter's Responses API with the basic error response format.\",\"og:image\":\"https://openrouter.ai/dynamic-og?title=Responses%20API%20Error%20Handling\u0026description=Basic%20error%20handling%20guide\",\"og:image:width\":1200,\"og:image:height\":630,\"twitter:card\":\"summary_large_image\",\"twitter:site\":\"@OpenRouter\",\"noindex\":false,\"nofollow\":false,\"icon\":\"triangle-exclamation\",\"href\":\"/api_reference/responses/error-handling\"}]}]},{\"group\":\"Versioning\",\"icon\":\"code-branch\",\"pages\":[{\"title\":\"API Versioning\",\"description\":\"How the OpenRouter API is versioned, what we consider a breaking change, and how deprecations are communicated.\",\"icon\":\"code-branch\",\"href\":\"/api_reference/versioning\"},{\"title\":\"API Changelog\",\"description\":\"Changes to the OpenRouter API, generated from the OpenAPI specification on every release.\",\"icon\":\"clock-rotate-left\",\"rss\":true,\"href\":\"/changelog\"}]},{\"group\":\"API Reference\",\"icon\":\"code\",\"pages\":[{\"group\":\"Analytics\",\"pages\":[{\"title\":\"Get user activity grouped by endpoint\",\"description\":\"Returns user activity data grouped by endpoint for the last 30 (completed) UTC days. Pass `workspace_id` to scope the response to a single workspace. Pass `group_by=workspace` to split each row per workspace and include `workspace_id` on every item; by default rows are aggregated across workspaces and `workspace_id` is not returned. Activity recorded before workspace resolution existed is permanently attributed to the account default workspace (no backfill is possible). [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /activity\",\"href\":\"/api/api-reference/analytics/get-user-activity-grouped-by-endpoint\",\"autogeneratedByOpenApi\":true},{\"title\":\"Get available analytics metrics and dimensions\",\"description\":\"Returns the available metrics, dimensions, filter operators, and granularities for the analytics query endpoint. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /analytics/meta\",\"href\":\"/api/api-reference/analytics/get-available-analytics-metrics-and-dimensions\",\"autogeneratedByOpenApi\":true},{\"title\":\"Query analytics data\",\"description\":\"Execute an analytics query with specified metrics, dimensions, filters, and time range. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /analytics/query\",\"href\":\"/api/api-reference/analytics/query-analytics-data\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"TTS\",\"pages\":[{\"title\":\"Create speech\",\"description\":\"Synthesizes audio from the input text. Returns a raw audio bytestream in the requested format (e.g. mp3, pcm, wav).\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /audio/speech\",\"href\":\"/api/api-reference/tts/create-speech\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"STT\",\"pages\":[{\"title\":\"Create transcription\",\"description\":\"Transcribes audio into text. Accepts base64-encoded audio input as JSON or an OpenAI-style multipart/form-data file upload, and returns the transcribed text.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /audio/transcriptions\",\"href\":\"/api/api-reference/stt/create-transcription\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"OAuth\",\"pages\":[{\"title\":\"Exchange authorization code for API key\",\"description\":\"Exchange an authorization code from the PKCE flow for a user-controlled API key\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /auth/keys\",\"href\":\"/api/api-reference/oauth/exchange-authorization-code-for-api-key\",\"autogeneratedByOpenApi\":true},{\"title\":\"Create authorization code\",\"description\":\"Create an authorization code for the PKCE flow to generate a user-controlled API key\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /auth/keys/code\",\"href\":\"/api/api-reference/oauth/create-authorization-code\",\"autogeneratedByOpenApi\":true},{\"title\":\"OpenRouter access token signing keys\",\"description\":\"RFC 7517 JWK Set containing the public keys OpenRouter signs access tokens with.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /oauth/jwks\",\"href\":\"/api/api-reference/oauth/openrouter-access-token-signing-keys\",\"autogeneratedByOpenApi\":true},{\"title\":\"Exchange a workload identity token\",\"description\":\"RFC 8693 token exchange. Presents a JWT from an issuer your organization trusts (Settings → Workload identity) and receives a short-lived OpenRouter access token that acts as the API key the matching federation policy targets.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /oauth/token\",\"href\":\"/api/api-reference/oauth/exchange-a-workload-identity-token\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"Benchmarks\",\"pages\":[{\"title\":\"List Benchmarks\",\"description\":\"Unified benchmark endpoint that aggregates scores from multiple benchmark sources (Artificial Analysis, Design Arena, and OpenRouter's own tau-bench, GPQA, and web-search evals). Filter by source to reproduce the exact shapes from the legacy per-source endpoints, or use task_type to find models suited for specific workloads. Use task_type=search (or a search_* benchmark_type) for OpenRouter's search benchmarks, which publish each model's highest-scoring eligible evaluation configuration with same-configuration runs combined by task-weighted mean. Authenticate with any valid OpenRouter API key. Rate-limited to 30 requests/minute per key and 500 requests/day per account.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /benchmarks\",\"href\":\"/api/api-reference/benchmarks/list-benchmarks\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"BYOK\",\"pages\":[{\"title\":\"List BYOK provider credentials\",\"description\":\"List the bring-your-own-key (BYOK) provider credentials for the authenticated entity's default workspace. Use the `workspace_id` query parameter to scope the result to a different workspace, or the `provider` query parameter to filter by upstream provider. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /byok\",\"href\":\"/api/api-reference/byok/list-byok-provider-credentials\",\"autogeneratedByOpenApi\":true},{\"title\":\"Create a BYOK provider credential\",\"description\":\"Create a new bring-your-own-key (BYOK) provider credential. The raw key is encrypted at rest and never returned in API responses. When `workspace_id` is omitted, the credential is created in the default workspace; if that default has been deleted, the request returns a 400 and you must pass `workspace_id` explicitly. Treat the raw key as write-only; it is never returned after creation. Use `allowed_api_key_hashes` to restrict the credential to specific OpenRouter API keys. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /byok\",\"href\":\"/api/api-reference/byok/create-a-byok-provider-credential\",\"autogeneratedByOpenApi\":true},{\"title\":\"Get a BYOK provider credential\",\"description\":\"Get a single bring-your-own-key (BYOK) provider credential by its `id`. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /byok/{id}\",\"href\":\"/api/api-reference/byok/get-a-byok-provider-credential\",\"autogeneratedByOpenApi\":true},{\"title\":\"Delete a BYOK provider credential\",\"description\":\"Delete (soft-delete) a bring-your-own-key (BYOK) provider credential by its `id`. The encrypted key material is wiped and the record is marked as deleted. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml delete /byok/{id}\",\"href\":\"/api/api-reference/byok/delete-a-byok-provider-credential\",\"autogeneratedByOpenApi\":true},{\"title\":\"Update a BYOK provider credential\",\"description\":\"Update an existing bring-your-own-key (BYOK) provider credential by its `id`. Include the `key` field to rotate the raw provider API key in-place (the previous key material is overwritten). Use `allowed_api_key_hashes` to restrict the credential to specific OpenRouter API keys (`null` clears the restriction). [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml patch /byok/{id}\",\"href\":\"/api/api-reference/byok/update-a-byok-provider-credential\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"Chat\",\"pages\":[{\"title\":\"Create a chat completion\",\"description\":\"Sends a request for a model response for the given chat conversation. Supports both streaming and non-streaming modes.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /chat/completions\",\"href\":\"/api/api-reference/chat/create-a-chat-completion\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"Classifications\",\"pages\":[{\"title\":\"Task classification market share\",\"description\":\"Returns the market-share breakdown of OpenRouter traffic by task classification\\n(e.g. code generation, web search, summarization) over a trailing time window.\\n\\nEach classification reports its share of classified sampled requests (`usage_share`)\\nand classified sampled token volume (`token_share`) as fractions between 0 and 1.\\nThe unclassified `other` bucket is excluded. Absolute volumes are not exposed\\nbecause the underlying data is sampled.\\n\\nEach classification also includes a `models` array listing the top models by\\nrequest volume within that classification, with their within-tag usage and token shares.\\n\\nClassifications are grouped into macro-categories (Code, Data, Agent, General)\\nwith aggregate shares provided for each.\\n\\nAuthenticate with any valid OpenRouter API key (same key used for inference).\\nRate-limited to 30 requests/minute per key and 500 requests/day per account.\\n\\nWhen republishing or quoting this data, cite as:\\n\\\"Source: OpenRouter (openrouter.ai/rankings), as of {as_of}.\\\"\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /classifications/task\",\"href\":\"/api/api-reference/classifications/task-classification-market-share\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"Containers\",\"pages\":[{\"title\":\"List container files\",\"description\":\"Lists the files in a container, in lexicographic path order. The container id is the canonical id returned in bash/shell tool results; a restarted session is a separate container with its own id. Paginate with `limit` and `after` (pass the previous page’s `last_id`); `has_more: true` always means the next page is fetchable that way.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /containers/{container_id}/files\",\"href\":\"/api/api-reference/containers/list-container-files\",\"autogeneratedByOpenApi\":true},{\"title\":\"Retrieve a container file\",\"description\":\"Returns the metadata of a single file in a container.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /containers/{container_id}/files/{file_id}\",\"href\":\"/api/api-reference/containers/retrieve-a-container-file\",\"autogeneratedByOpenApi\":true},{\"title\":\"Download container file content\",\"description\":\"Streams the raw bytes of a file in a container.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /containers/{container_id}/files/{file_id}/content\",\"href\":\"/api/api-reference/containers/download-container-file-content\",\"autogeneratedByOpenApi\":true},{\"title\":\"Promote a container file into workspace documents\",\"description\":\"Copies a file from the container's sandbox prefix into the workspace's durable document storage, so it outlives the container. Returns the new document in the Files API shape, with a durable file id in the documents namespace. The copy counts against the workspace's storage quota. Unlike a direct upload, promoted files are downloadable.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /containers/{container_id}/files/{file_id}/promote\",\"href\":\"/api/api-reference/containers/promote-a-container-file-into-workspace-documents\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"Credits\",\"pages\":[{\"title\":\"Get remaining credits\",\"description\":\"Get total credits purchased and used for the authenticated user. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /credits\",\"href\":\"/api/api-reference/credits/get-remaining-credits\",\"autogeneratedByOpenApi\":true},{\"title\":\"Deprecated Coinbase Commerce charge endpoint\",\"description\":\"Deprecated. The Coinbase APIs used by this endpoint have been deprecated, so Coinbase Commerce charges have been removed. Use the web credits purchase flow instead.\",\"deprecated\":true,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /credits/coinbase\",\"href\":\"/api/api-reference/credits/deprecated-coinbase-commerce-charge-endpoint\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"Datasets\",\"pages\":[{\"title\":\"Top apps by token usage\",\"description\":\"$44\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /datasets/app-rankings\",\"href\":\"/api/api-reference/datasets/top-apps-by-token-usage\",\"autogeneratedByOpenApi\":true},{\"title\":\"Daily token totals for top 50 models\",\"description\":\"$45\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /datasets/rankings-daily\",\"href\":\"/api/api-reference/datasets/daily-token-totals-for-top-50-models\",\"autogeneratedByOpenApi\":true},{\"title\":\"Cost per session by harness and model\",\"description\":\"Returns weekly refreshed, aggregated cost-per-session cells for the published harnesses.\\nSessions are never pooled across apps. Medians are of per-session USD spend, and\\nprivacy-preserving aggregation never exposes clerk_user_id values or per-session rows.\\n\\nFilter by `app_slug`, `model`, or `turn_range`. Filtering by `model` alone works across apps\\nfor harness-vs-harness comparison at a fixed model. Results refresh weekly and include the source snapshot\\nwindow in `meta`.\\n\\nLicensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/): reuse and republish with attribution to OpenRouter.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /datasets/session-cost\",\"href\":\"/api/api-reference/datasets/cost-per-session-by-harness-and-model\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"Embeddings\",\"pages\":[{\"title\":\"Submit an embedding request\",\"description\":\"Submits an embedding request to the embeddings router\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /embeddings\",\"href\":\"/api/api-reference/embeddings/submit-an-embedding-request\",\"autogeneratedByOpenApi\":true},{\"title\":\"List all embeddings models\",\"description\":\"Returns a list of all available embeddings models and their properties\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /embeddings/models\",\"href\":\"/api/api-reference/embeddings/list-all-embeddings-models\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"Endpoints\",\"pages\":[{\"title\":\"Preview the impact of ZDR on the available endpoints\",\"description\":null,\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /endpoints/zdr\",\"href\":\"/api/api-reference/endpoints/preview-the-impact-of-zdr-on-the-available-endpoints\",\"autogeneratedByOpenApi\":true},{\"title\":\"List all endpoints for a model\",\"description\":null,\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /models/{author}/{slug}/endpoints\",\"href\":\"/api/api-reference/endpoints/list-all-endpoints-for-a-model\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"Files\",\"pages\":[{\"title\":\"List files\",\"description\":\"Lists files belonging to the workspace of the authenticating API key.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /files\",\"href\":\"/api/api-reference/files/list-files\",\"autogeneratedByOpenApi\":true},{\"title\":\"Upload a file\",\"description\":\"Uploads a file to be referenced in future API calls. The file is stored under the workspace of the authenticating API key. Maximum file size: 100 MB; empty files are rejected. The file type is determined from the file contents — not the filename or the declared content type — and must be a PDF, a PNG/JPEG/GIF/WebP image, a DOCX/XLSX/PPTX document, an MP3/WAV/FLAC/OGG audio file, or UTF-8 text. Text is reported by its structure as `application/json`, `application/x-ndjson`, `text/csv`, `text/markdown`, or `text/plain`.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /files\",\"href\":\"/api/api-reference/files/upload-a-file\",\"autogeneratedByOpenApi\":true},{\"title\":\"Get file metadata\",\"description\":\"Retrieves metadata for a single file owned by the requesting workspace.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /files/{file_id}\",\"href\":\"/api/api-reference/files/get-file-metadata\",\"autogeneratedByOpenApi\":true},{\"title\":\"Delete a file\",\"description\":\"Deletes a file owned by the requesting workspace. Deletion is irreversible.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml delete /files/{file_id}\",\"href\":\"/api/api-reference/files/delete-a-file\",\"autogeneratedByOpenApi\":true},{\"title\":\"Download file content\",\"description\":\"Downloads the raw bytes of a file. Only files created server-side are downloadable; uploaded files return 400.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /files/{file_id}/content\",\"href\":\"/api/api-reference/files/download-file-content\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"Generations\",\"pages\":[{\"title\":\"Get request \u0026 usage metadata for a generation\",\"description\":null,\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /generation\",\"href\":\"/api/api-reference/generations/get-request-\u0026-usage-metadata-for-a-generation\",\"autogeneratedByOpenApi\":true},{\"title\":\"Get stored prompt, completion, and error content for a generation\",\"description\":null,\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /generation/content\",\"href\":\"/api/api-reference/generations/get-stored-prompt-completion-and-error-content-for-a-generation\",\"autogeneratedByOpenApi\":true},{\"title\":\"Submit feedback for a generation\",\"description\":\"Submit structured feedback on a generation the authenticated user made. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /generation/feedback\",\"href\":\"/api/api-reference/generations/submit-feedback-for-a-generation\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"Guardrails\",\"pages\":[{\"title\":\"List guardrails\",\"description\":\"List all guardrails for the authenticated user. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /guardrails\",\"href\":\"/api/api-reference/guardrails/list-guardrails\",\"autogeneratedByOpenApi\":true},{\"title\":\"Create a guardrail\",\"description\":\"Create a new guardrail for the authenticated user. A newly created guardrail enforces nothing until it is assigned to API keys or organization members; `workspace_id` places the guardrail in a workspace but does not apply it to that workspace's traffic. To restrict all traffic in a workspace, update the workspace's default guardrail instead. Set `allowed_data_regions` to enforce [In-Region Routing](/docs/guides/features/in-region-routing#enforcing-in-region-routing-with-guardrails): governed requests must arrive through one of the listed OpenRouter domains and are rejected with a 403 otherwise. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /guardrails\",\"href\":\"/api/api-reference/guardrails/create-a-guardrail\",\"autogeneratedByOpenApi\":true},{\"title\":\"Get a guardrail\",\"description\":\"Get a single guardrail by ID. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /guardrails/{id}\",\"href\":\"/api/api-reference/guardrails/get-a-guardrail\",\"autogeneratedByOpenApi\":true},{\"title\":\"Delete a guardrail\",\"description\":\"Delete an existing guardrail. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml delete /guardrails/{id}\",\"href\":\"/api/api-reference/guardrails/delete-a-guardrail\",\"autogeneratedByOpenApi\":true},{\"title\":\"Update a guardrail\",\"description\":\"Update an existing guardrail, or materialize an unconfigured workspace default guardrail. Collection fields use replace semantics: send the full desired set on every update. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml patch /guardrails/{id}\",\"href\":\"/api/api-reference/guardrails/update-a-guardrail\",\"autogeneratedByOpenApi\":true},{\"title\":\"List key assignments for a guardrail\",\"description\":\"List all API key assignments for a specific guardrail. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /guardrails/{id}/assignments/keys\",\"href\":\"/api/api-reference/guardrails/list-key-assignments-for-a-guardrail\",\"autogeneratedByOpenApi\":true},{\"title\":\"Bulk assign keys to a guardrail\",\"description\":\"Assign multiple API keys to a specific guardrail. A key may hold at most one guardrail; assigning replaces any existing assignment. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /guardrails/{id}/assignments/keys\",\"href\":\"/api/api-reference/guardrails/bulk-assign-keys-to-a-guardrail\",\"autogeneratedByOpenApi\":true},{\"title\":\"Bulk unassign keys from a guardrail\",\"description\":\"Unassign multiple API keys from a specific guardrail. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /guardrails/{id}/assignments/keys/remove\",\"href\":\"/api/api-reference/guardrails/bulk-unassign-keys-from-a-guardrail\",\"autogeneratedByOpenApi\":true},{\"title\":\"List member assignments for a guardrail\",\"description\":\"List all organization member assignments for a specific guardrail. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /guardrails/{id}/assignments/members\",\"href\":\"/api/api-reference/guardrails/list-member-assignments-for-a-guardrail\",\"autogeneratedByOpenApi\":true},{\"title\":\"Bulk assign members to a guardrail\",\"description\":\"Assign multiple organization members to a specific guardrail. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /guardrails/{id}/assignments/members\",\"href\":\"/api/api-reference/guardrails/bulk-assign-members-to-a-guardrail\",\"autogeneratedByOpenApi\":true},{\"title\":\"Bulk unassign members from a guardrail\",\"description\":\"Unassign multiple organization members from a specific guardrail. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /guardrails/{id}/assignments/members/remove\",\"href\":\"/api/api-reference/guardrails/bulk-unassign-members-from-a-guardrail\",\"autogeneratedByOpenApi\":true},{\"title\":\"List all key assignments\",\"description\":\"List all API key guardrail assignments for the authenticated user. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /guardrails/assignments/keys\",\"href\":\"/api/api-reference/guardrails/list-all-key-assignments\",\"autogeneratedByOpenApi\":true},{\"title\":\"List all member assignments\",\"description\":\"List all organization member guardrail assignments for the authenticated user. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /guardrails/assignments/members\",\"href\":\"/api/api-reference/guardrails/list-all-member-assignments\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"Images\",\"pages\":[{\"title\":\"Generate an image\",\"description\":\"Generates an image from a text prompt via the image generation router\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /images\",\"href\":\"/api/api-reference/images/generate-an-image\",\"autogeneratedByOpenApi\":true},{\"title\":\"List image generation models\",\"description\":\"Lists every image generation model with its top-level supported-parameter superset and a URL to its full per-endpoint records.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /images/models\",\"href\":\"/api/api-reference/images/list-image-generation-models\",\"autogeneratedByOpenApi\":true},{\"title\":\"List endpoints for an image model\",\"description\":\"Returns the full per-endpoint records for an image model: each endpoint's definitive supported parameters, pricing, and passthrough allowlist.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /images/models/{author}/{slug}/endpoints\",\"href\":\"/api/api-reference/images/list-endpoints-for-an-image-model\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"API Keys\",\"pages\":[{\"title\":\"Get current API key\",\"description\":\"Get information on the API key associated with the current authentication session\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /key\",\"href\":\"/api/api-reference/api-keys/get-current-api-key\",\"autogeneratedByOpenApi\":true},{\"title\":\"List API keys\",\"description\":\"List all API keys for the authenticated user. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /keys\",\"href\":\"/api/api-reference/api-keys/list-api-keys\",\"autogeneratedByOpenApi\":true},{\"title\":\"Create a new API key\",\"description\":\"Create a new API key for the authenticated user. The plaintext `key` is returned only in this response. Treat it as a write-only, sensitive value; it cannot be retrieved later. Authenticate with a [management key](/docs/guides/overview/auth/management-api-keys). The optional `external` object associates the key with a partner-defined user and lookup key.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /keys\",\"href\":\"/api/api-reference/api-keys/create-a-new-api-key\",\"autogeneratedByOpenApi\":true},{\"title\":\"Get a single API key\",\"description\":\"Get a single API key by hash. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /keys/{hash}\",\"href\":\"/api/api-reference/api-keys/get-a-single-api-key\",\"autogeneratedByOpenApi\":true},{\"title\":\"Delete an API key\",\"description\":\"Delete an existing API key. Authenticate with a [management key](/docs/guides/overview/auth/management-api-keys).\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml delete /keys/{hash}\",\"href\":\"/api/api-reference/api-keys/delete-an-api-key\",\"autogeneratedByOpenApi\":true},{\"title\":\"Update an API key\",\"description\":\"Update an existing API key. Authenticate with a [management key](/docs/guides/overview/auth/management-api-keys).\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml patch /keys/{hash}\",\"href\":\"/api/api-reference/api-keys/update-an-api-key\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"Anthropic Messages\",\"pages\":[{\"title\":\"Create a message\",\"description\":\"Creates a message using the Anthropic Messages API format. Supports text, images, PDFs, tools, and extended thinking.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /messages\",\"href\":\"/api/api-reference/anthropic-messages/create-a-message\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"Models\",\"pages\":[{\"title\":\"Get a model by its slug\",\"description\":\"Returns full details for a single model identified by its author and slug (e.g. openai/gpt-4). Supports variant suffixes (e.g. openai/gpt-4:free) and resolves known slug aliases.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /model/{author}/{slug}\",\"href\":\"/api/api-reference/models/get-a-model-by-its-slug\",\"autogeneratedByOpenApi\":true},{\"title\":\"List all models and their properties\",\"description\":null,\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /models\",\"href\":\"/api/api-reference/models/list-all-models-and-their-properties\",\"autogeneratedByOpenApi\":true},{\"title\":\"Get total count of available models\",\"description\":null,\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /models/count\",\"href\":\"/api/api-reference/models/get-total-count-of-available-models\",\"autogeneratedByOpenApi\":true},{\"title\":\"List models filtered by user provider preferences, privacy settings, and guardrails\",\"description\":\"List models filtered by user provider preferences, [privacy settings](https://openrouter.ai/docs/guides/privacy/provider-logging), and [guardrails](https://openrouter.ai/docs/guides/features/guardrails). Returns text-output models by default; pass `output_modalities` (a comma-separated list of `text`, `image`, `embeddings`, `audio`, `video`, `rerank`, `speech`, `transcription`, or `all`) to include other modalities. If requesting through a regional hostname, the results will be filtered to models that satisfy in-region routing for that region.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /models/user\",\"href\":\"/api/api-reference/models/list-models-filtered-by-user-provider-preferences-privacy-settings-and-guardrails\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"Observability\",\"pages\":[{\"title\":\"List observability destinations\",\"description\":\"List the observability destinations configured for the authenticated entity's default workspace. Use the `workspace_id` query parameter to scope the result to a different workspace. Only destinations with stable release status are surfaced — destinations of other types are excluded. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /observability/destinations\",\"href\":\"/api/api-reference/observability/list-observability-destinations\",\"autogeneratedByOpenApi\":true},{\"title\":\"Create an observability destination\",\"description\":\"Create a new observability destination. A maximum of 5 destinations per type is allowed. Defaults to the authenticated entity's default workspace; use the `workspace_id` body field to scope to a different workspace. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /observability/destinations\",\"href\":\"/api/api-reference/observability/create-an-observability-destination\",\"autogeneratedByOpenApi\":true},{\"title\":\"Get an observability destination\",\"description\":\"Fetch a single observability destination by its UUID. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /observability/destinations/{id}\",\"href\":\"/api/api-reference/observability/get-an-observability-destination\",\"autogeneratedByOpenApi\":true},{\"title\":\"Delete an observability destination\",\"description\":\"Delete an existing observability destination. This performs a soft delete. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml delete /observability/destinations/{id}\",\"href\":\"/api/api-reference/observability/delete-an-observability-destination\",\"autogeneratedByOpenApi\":true},{\"title\":\"Update an observability destination\",\"description\":\"Update an existing observability destination. Only the fields provided in the request body are updated. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml patch /observability/destinations/{id}\",\"href\":\"/api/api-reference/observability/update-an-observability-destination\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"Organization\",\"pages\":[{\"title\":\"List organization members\",\"description\":\"List all members of the organization associated with the authenticated management key. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /organization/members\",\"href\":\"/api/api-reference/organization/list-organization-members\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"Presets\",\"pages\":[{\"title\":\"List presets\",\"description\":\"Lists all presets for the authenticated user, ordered by most recently updated first.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /presets\",\"href\":\"/api/api-reference/presets/list-presets\",\"autogeneratedByOpenApi\":true},{\"title\":\"Get a preset\",\"description\":\"Retrieves a preset by its slug with its currently designated version inline.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /presets/{slug}\",\"href\":\"/api/api-reference/presets/get-a-preset\",\"autogeneratedByOpenApi\":true},{\"title\":\"Create a preset from a chat-completions request body\",\"description\":\"Creates a preset (or a new version of an existing one) from an inference request body. Only fields that overlap with the preset config are persisted; other fields (e.g. `messages`, `stream`, `prompt`) are silently ignored.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /presets/{slug}/chat/completions\",\"href\":\"/api/api-reference/presets/create-a-preset-from-a-chat-completions-request-body\",\"autogeneratedByOpenApi\":true},{\"title\":\"Create a preset from a messages request body\",\"description\":\"Creates a preset (or a new version of an existing one) from an inference request body. Only fields that overlap with the preset config are persisted; other fields (e.g. `messages`, `stream`, `prompt`) are silently ignored.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /presets/{slug}/messages\",\"href\":\"/api/api-reference/presets/create-a-preset-from-a-messages-request-body\",\"autogeneratedByOpenApi\":true},{\"title\":\"Create a preset from a responses request body\",\"description\":\"Creates a preset (or a new version of an existing one) from an inference request body. Only fields that overlap with the preset config are persisted; other fields (e.g. `messages`, `stream`, `prompt`) are silently ignored.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /presets/{slug}/responses\",\"href\":\"/api/api-reference/presets/create-a-preset-from-a-responses-request-body\",\"autogeneratedByOpenApi\":true},{\"title\":\"List versions of a preset\",\"description\":\"Lists all versions of a preset, ordered by version number ascending (oldest first).\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /presets/{slug}/versions\",\"href\":\"/api/api-reference/presets/list-versions-of-a-preset\",\"autogeneratedByOpenApi\":true},{\"title\":\"Get a specific version of a preset\",\"description\":\"Retrieves a specific version of a preset by its slug and version number.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /presets/{slug}/versions/{version}\",\"href\":\"/api/api-reference/presets/get-a-specific-version-of-a-preset\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"Providers\",\"pages\":[{\"title\":\"List all providers\",\"description\":null,\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /providers\",\"href\":\"/api/api-reference/providers/list-all-providers\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"Rerank\",\"pages\":[{\"title\":\"Submit a rerank request\",\"description\":\"Submits a rerank request to the rerank router\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /rerank\",\"href\":\"/api/api-reference/rerank/submit-a-rerank-request\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"Responses\",\"pages\":[{\"title\":\"Create a response\",\"description\":\"Creates a streaming or non-streaming response using OpenResponses API format\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /responses\",\"href\":\"/api/api-reference/responses/create-a-response\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"SCIM\",\"pages\":[{\"title\":\"List SCIM group mappings\",\"description\":\"List SCIM group-to-workspace mappings for the organization. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /scim/group-mappings\",\"href\":\"/api/api-reference/scim/list-scim-group-mappings\",\"autogeneratedByOpenApi\":true},{\"title\":\"Create a SCIM group mapping\",\"description\":\"Create a SCIM group-to-workspace role mapping. Creating a mapping that already exists with the same role succeeds and re-applies the mapping to the group members. Requesting a different role for an existing mapping returns 409. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /scim/group-mappings\",\"href\":\"/api/api-reference/scim/create-a-scim-group-mapping\",\"autogeneratedByOpenApi\":true},{\"title\":\"Get a SCIM group mapping\",\"description\":\"Get a SCIM group-to-workspace mapping. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /scim/group-mappings/{id}\",\"href\":\"/api/api-reference/scim/get-a-scim-group-mapping\",\"autogeneratedByOpenApi\":true},{\"title\":\"Delete a SCIM group mapping\",\"description\":\"Delete a SCIM group-to-workspace mapping. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml delete /scim/group-mappings/{id}\",\"href\":\"/api/api-reference/scim/delete-a-scim-group-mapping\",\"autogeneratedByOpenApi\":true},{\"title\":\"Update a SCIM group mapping\",\"description\":\"Update a SCIM group mapping role. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml patch /scim/group-mappings/{id}\",\"href\":\"/api/api-reference/scim/update-a-scim-group-mapping\",\"autogeneratedByOpenApi\":true},{\"title\":\"List SCIM groups\",\"description\":\"List SCIM groups for the organization. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /scim/groups\",\"href\":\"/api/api-reference/scim/list-scim-groups\",\"autogeneratedByOpenApi\":true},{\"title\":\"Start a SCIM directory sync\",\"description\":\"Start a SCIM directory sync. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /scim/sync-jobs\",\"href\":\"/api/api-reference/scim/start-a-scim-directory-sync\",\"autogeneratedByOpenApi\":true},{\"title\":\"Get SCIM directory sync status\",\"description\":\"Get SCIM directory sync status. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /scim/sync-jobs/{id}\",\"href\":\"/api/api-reference/scim/get-scim-directory-sync-status\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"Video Generation\",\"pages\":[{\"title\":\"Submit a video generation request\",\"description\":\"Submits a video generation request and returns a polling URL to check status\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /videos\",\"href\":\"/api/api-reference/video-generation/submit-a-video-generation-request\",\"autogeneratedByOpenApi\":true},{\"title\":\"Poll video generation status\",\"description\":\"Returns job status and content URLs when completed\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /videos/{jobId}\",\"href\":\"/api/api-reference/video-generation/poll-video-generation-status\",\"autogeneratedByOpenApi\":true},{\"title\":\"Download generated video content\",\"description\":\"Streams the generated video content from the upstream provider\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /videos/{jobId}/content\",\"href\":\"/api/api-reference/video-generation/download-generated-video-content\",\"autogeneratedByOpenApi\":true},{\"title\":\"List all video generation models\",\"description\":\"Returns a list of all available video generation models and their properties\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /videos/models\",\"href\":\"/api/api-reference/video-generation/list-all-video-generation-models\",\"autogeneratedByOpenApi\":true}]},{\"group\":\"Workspaces\",\"pages\":[{\"title\":\"List workspaces\",\"description\":\"List all workspaces for the authenticated user. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /workspaces\",\"href\":\"/api/api-reference/workspaces/list-workspaces\",\"autogeneratedByOpenApi\":true},{\"title\":\"Create a workspace\",\"description\":\"Create a new workspace for the authenticated user. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /workspaces\",\"href\":\"/api/api-reference/workspaces/create-a-workspace\",\"autogeneratedByOpenApi\":true},{\"title\":\"Get a workspace\",\"description\":\"Get a single workspace by ID or slug. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /workspaces/{id}\",\"href\":\"/api/api-reference/workspaces/get-a-workspace\",\"autogeneratedByOpenApi\":true},{\"title\":\"Delete a workspace\",\"description\":\"Delete an existing workspace. Workspaces with active API keys cannot be deleted; remove the keys first. Deleting the default workspace requires confirm_default_workspace_deletion=true. Deleting any workspace permanently deletes its budgets and guardrails and disables its classifiers and broadcast destinations. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml delete /workspaces/{id}\",\"href\":\"/api/api-reference/workspaces/delete-a-workspace\",\"autogeneratedByOpenApi\":true},{\"title\":\"Update a workspace\",\"description\":\"Update an existing workspace by ID or slug. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml patch /workspaces/{id}\",\"href\":\"/api/api-reference/workspaces/update-a-workspace\",\"autogeneratedByOpenApi\":true},{\"title\":\"List workspace budgets\",\"description\":\"List all budgets configured for a workspace. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /workspaces/{id}/budgets\",\"href\":\"/api/api-reference/workspaces/list-workspace-budgets\",\"autogeneratedByOpenApi\":true},{\"title\":\"Get a workspace budget\",\"description\":\"Retrieve the budget for a given interval. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /workspaces/{id}/budgets/{interval}\",\"href\":\"/api/api-reference/workspaces/get-a-workspace-budget\",\"autogeneratedByOpenApi\":true},{\"title\":\"Create or update a workspace budget\",\"description\":\"Create or update the budget for a given interval. Budget limits must strictly decrease as the interval narrows (lifetime \u003e monthly \u003e weekly \u003e daily). The optional `include_byok_in_budgets` flag is a workspace-wide setting: when provided it applies to every budget interval for the workspace, not just the interval in this request. Note that a change made here is applied to budget enforcement immediately, but an already-open workspace settings page in the web dashboard may keep showing the previous value until it is reloaded. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml put /workspaces/{id}/budgets/{interval}\",\"href\":\"/api/api-reference/workspaces/create-or-update-a-workspace-budget\",\"autogeneratedByOpenApi\":true},{\"title\":\"Delete a workspace budget\",\"description\":\"Remove the budget for a given interval. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml delete /workspaces/{id}/budgets/{interval}\",\"href\":\"/api/api-reference/workspaces/delete-a-workspace-budget\",\"autogeneratedByOpenApi\":true},{\"title\":\"List workspace members\",\"description\":\"List all members of a workspace. Returns paginated results. For the default workspace, returns all organization members (implicit membership). [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml get /workspaces/{id}/members\",\"href\":\"/api/api-reference/workspaces/list-workspace-members\",\"autogeneratedByOpenApi\":true},{\"title\":\"Bulk add members to a workspace\",\"description\":\"Add multiple organization members to a workspace. Members are assigned the same role they hold in the organization. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /workspaces/{id}/members/add\",\"href\":\"/api/api-reference/workspaces/bulk-add-members-to-a-workspace\",\"autogeneratedByOpenApi\":true},{\"title\":\"Bulk remove members from a workspace\",\"description\":\"Remove multiple members from a workspace. Members with active API keys in the workspace cannot be removed. SCIM-managed members cannot be removed; changes must be made in your identity provider. [Management key](/docs/guides/overview/auth/management-api-keys) required.\",\"deprecated\":null,\"version\":null,\"openapi\":\"/openapi/openapi.yaml post /workspaces/{id}/members/remove\",\"href\":\"/api/api-reference/workspaces/bulk-remove-members-from-a-workspace\",\"autogeneratedByOpenApi\":true}]}]}]},{\"tab\":\"Client SDKs\",\"icon\":\"cube\",\"pages\":[{\"title\":\"Client SDKs\",\"href\":\"/client-sdks/overview\"}]},{\"tab\":\"Agent SDK\",\"icon\":\"cube\",\"pages\":[{\"title\":\"Agent SDK\",\"href\":\"/agent-sdk/overview\"}]},{\"tab\":\"Cookbook\",\"icon\":\"book-open\",\"pages\":[{\"title\":\"Cookbook\",\"href\":\"/cookbook/get-started/quickstart\"}]}]},\"maps\":{\"firstHrefInVersion\":{},\"firstHrefInLanguage\":{}},\"children\":\"$L46\"}]\n"])</script><script>self.__next_f.push([1,"47:I[763509,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cee6f6b26d68395d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/0eb894a8519f24ea.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/fb156bebf42da1e9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/2dd53f5a4cfe6dd5.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/e95beff806b7ab98.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8a30b6291cd9465f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/893b80a74cde24cd.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c0e7a98cd764702e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"ThemeLayout\"]\n"])</script><script>self.__next_f.push([1,"48:I[91557,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cee6f6b26d68395d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/0eb894a8519f24ea.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/fb156bebf42da1e9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/2dd53f5a4cfe6dd5.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/e95beff806b7ab98.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8a30b6291cd9465f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/893b80a74cde24cd.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c0e7a98cd764702e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"ApiReferenceProvider\"]\n"])</script><script>self.__next_f.push([1,"49:I[91557,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cee6f6b26d68395d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/0eb894a8519f24ea.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/fb156bebf42da1e9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/2dd53f5a4cfe6dd5.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/e95beff806b7ab98.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8a30b6291cd9465f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/893b80a74cde24cd.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c0e7a98cd764702e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"PageProvider\"]\n"])</script><script>self.__next_f.push([1,"4a:I[91557,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cee6f6b26d68395d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/0eb894a8519f24ea.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/fb156bebf42da1e9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/2dd53f5a4cfe6dd5.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/e95beff806b7ab98.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8a30b6291cd9465f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/893b80a74cde24cd.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c0e7a98cd764702e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"OpenApiProvider\"]\n"])</script><script>self.__next_f.push([1,"4b:I[525343,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cee6f6b26d68395d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/0eb894a8519f24ea.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/fb156bebf42da1e9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/2dd53f5a4cfe6dd5.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/e95beff806b7ab98.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8a30b6291cd9465f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/893b80a74cde24cd.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c0e7a98cd764702e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"TabSyncContextProvider\"]\n"])</script><script>self.__next_f.push([1,"4c:T724,"])</script><script>self.__next_f.push([1,"{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://openrouter.ai/#organization\",\"name\":\"OpenRouter | Documentation\",\"url\":\"https://openrouter.ai\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/openrouter-d02e98a0/ksNSeB_K7gD-BUDh/assets/logo-v2-light.svg?fit=max\u0026auto=format\u0026n=ksNSeB_K7gD-BUDh\u0026q=85\u0026s=690e45873843519efe02bcbe45795dac\"}},{\"@type\":\"WebSite\",\"@id\":\"https://openrouter.ai/docs#website\",\"name\":\"OpenRouter | Documentation\",\"url\":\"https://openrouter.ai/docs\",\"publisher\":{\"@id\":\"https://openrouter.ai/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://openrouter.ai/docs/api_reference/streaming#webpage\",\"url\":\"https://openrouter.ai/docs/api_reference/streaming\",\"name\":\"Streaming\",\"dateModified\":\"2026-09-05T06:13:49.881Z\",\"isPartOf\":{\"@id\":\"https://openrouter.ai/docs#website\"},\"breadcrumb\":{\"@id\":\"https://openrouter.ai/docs/api_reference/streaming#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://openrouter.ai/docs/api_reference/streaming#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"API Guides\",\"item\":\"https://openrouter.ai/docs/api_reference/overview\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Streaming\",\"item\":\"https://openrouter.ai/docs/api_reference/streaming\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://openrouter.ai/docs/api_reference/streaming#article\",\"headline\":\"Streaming\",\"name\":\"Streaming\",\"url\":\"https://openrouter.ai/docs/api_reference/streaming\",\"mainEntityOfPage\":{\"@id\":\"https://openrouter.ai/docs/api_reference/streaming#webpage\"},\"image\":\"https://openrouter.ai/dynamic-og?title=API%20Streaming\u0026description=Real-time%20model%20response%20streaming\",\"dateModified\":\"2026-09-05T06:13:49.881Z\",\"publisher\":{\"@id\":\"https://openrouter.ai/#organization\"},\"isPartOf\":{\"@id\":\"https://openrouter.ai/docs#website\"}}]}"])</script><script>self.__next_f.push([1,"46:[\"$\",\"$L47\",null,{\"theme\":\"mint\",\"pageMetadata\":{\"title\":\"Streaming\",\"seoTitle\":\"API Streaming | Real-time Model Responses in OpenRouter\",\"og:site_name\":\"OpenRouter Documentation\",\"og:title\":\"API Streaming - Real-time Model Response Integration\",\"og:description\":\"Learn how to implement streaming responses with OpenRouter's API. Complete guide to Server-Sent Events (SSE) and real-time model outputs.\",\"og:image\":\"https://openrouter.ai/dynamic-og?title=API%20Streaming\u0026description=Real-time%20model%20response%20streaming\",\"og:image:width\":1200,\"og:image:height\":630,\"twitter:card\":\"summary_large_image\",\"twitter:site\":\"@OpenRouter\",\"noindex\":false,\"nofollow\":false,\"icon\":\"bars-staggered\",\"description\":null,\"href\":\"/api_reference/streaming\"},\"children\":[\"$\",\"$L48\",null,{\"value\":{\"apiReferenceData\":{},\"graphqlReferenceData\":\"$undefined\"},\"children\":[\"$\",\"$L49\",null,{\"value\":{\"pageMetadata\":\"$46:props:pageMetadata\",\"lastModified\":\"2026-09-05T06:13:49.881Z\",\"gitLastModified\":\"$undefined\",\"originalFileLocation\":\"api_reference/streaming.mdx\",\"description\":null,\"mdxExtracts\":{\"tableOfContents\":[{\"title\":\"Additional information\",\"slug\":\"additional-information\",\"depth\":3,\"children\":[]},{\"title\":\"The final usage chunk (Chat Completions)\",\"slug\":\"the-final-usage-chunk-chat-completions\",\"depth\":3,\"children\":[]},{\"title\":\"Stream cancellation\",\"slug\":\"stream-cancellation\",\"depth\":3,\"children\":[]},{\"title\":\"Handling errors during streaming\",\"slug\":\"handling-errors-during-streaming\",\"depth\":3,\"children\":[]},{\"title\":\"Errors before the response is committed\",\"slug\":\"errors-before-the-response-is-committed\",\"depth\":4,\"children\":[]},{\"title\":\"Errors after the response is committed (mid-stream)\",\"slug\":\"errors-after-the-response-is-committed-mid-stream\",\"depth\":4,\"children\":[]},{\"title\":\"Code examples\",\"slug\":\"code-examples\",\"depth\":4,\"children\":[]},{\"title\":\"API-specific behavior\",\"slug\":\"api-specific-behavior\",\"depth\":4,\"children\":[]}],\"codeExamples\":{}},\"pageType\":\"$undefined\",\"panelMdxSource\":\"$undefined\",\"panelMdxSourceWithNoJs\":\"$undefined\",\"contextualStarterQuestions\":\"$undefined\",\"relatedPages\":\"$undefined\"},\"children\":[\"$\",\"$L4a\",null,{\"pageMetadata\":\"$46:props:pageMetadata\",\"mdxExtracts\":\"$46:props:children:props:children:props:value:mdxExtracts\",\"openApiReferenceData\":\"$undefined\",\"children\":[\"$\",\"$L4b\",null,{\"children\":[[\"$\",\"script\",null,{\"type\":\"application/ld+json\",\"dangerouslySetInnerHTML\":{\"__html\":\"$4c\"}}],\"$L4d\",\"$L4e\",\"$L4f\",\"$L50\",\"$L51\"]}]}]}]}]}]\n"])</script><script>self.__next_f.push([1,"52:I[228341,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cee6f6b26d68395d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/0eb894a8519f24ea.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/fb156bebf42da1e9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/2dd53f5a4cfe6dd5.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/e95beff806b7ab98.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8a30b6291cd9465f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/893b80a74cde24cd.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c0e7a98cd764702e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"PageModeUpdater\"]\n"])</script><script>self.__next_f.push([1,"53:I[575126,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cee6f6b26d68395d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/0eb894a8519f24ea.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/fb156bebf42da1e9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/2dd53f5a4cfe6dd5.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/e95beff806b7ab98.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8a30b6291cd9465f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/893b80a74cde24cd.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c0e7a98cd764702e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"Background\"]\n"])</script><script>self.__next_f.push([1,"55:I[36098,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cee6f6b26d68395d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/0eb894a8519f24ea.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/fb156bebf42da1e9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/2dd53f5a4cfe6dd5.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/e95beff806b7ab98.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8a30b6291cd9465f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/893b80a74cde24cd.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c0e7a98cd764702e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"CustomJsFiles\"]\n"])</script><script>self.__next_f.push([1,"58:I[530359,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cee6f6b26d68395d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/0eb894a8519f24ea.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/fb156bebf42da1e9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/2dd53f5a4cfe6dd5.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/e95beff806b7ab98.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8a30b6291cd9465f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/893b80a74cde24cd.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c0e7a98cd764702e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"MDXContentController\"]\n"])</script><script>self.__next_f.push([1,"59:I[448287,[\"/docs/_next/static/chunks/19ae1768f166fab9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b664fc8bb1e7ab0d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde316292f7266ae.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a5edc6734daa1561.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/b21970438ab9ed9e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/a919d558158c76f7.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/3c94b65e4dbefe6e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8778b596bb8e1fac.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/88f21573038cb19f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/ac99e94360bfbfe1.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/28bb5e6550ef2148.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cde9521bba917b79.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cc5fb492c7259b04.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/dff2877daee22ab8.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cfd727ba62f1c54c.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c7c9dfd26f25e785.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/be4c7ddebf16f15a.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/cee6f6b26d68395d.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/0eb894a8519f24ea.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/fb156bebf42da1e9.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/2dd53f5a4cfe6dd5.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/e95beff806b7ab98.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/8a30b6291cd9465f.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/893b80a74cde24cd.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\",\"/docs/_next/static/chunks/c0e7a98cd764702e.js?dpl=dpl_6TpKozpvfbf2eKSzPrrzWSvEC9fx\"],\"default\"]\n"])</script><script>self.__next_f.push([1,"4d:[[\"$\",\"script\",null,{\"dangerouslySetInnerHTML\":{\"__html\":\"document.documentElement.setAttribute('data-page-mode', \\\"none\\\");\"}}],[\"$\",\"$L52\",null,{\"pageMetadata\":\"$46:props:pageMetadata\"}]]\n4e:[\"$\",\"$L53\",null,{\"pageMetadata\":\"$46:props:pageMetadata\"}]\n54:T202d,"])</script><script>self.__next_f.push([1,"/*\n * OpenRouter Docs — Bauhaus theme overrides\n *\n * Custom CSS for Mintlify to align with the bauhaus design system.\n * Uses Mintlify's exposed ID/element selectors for targeted styling.\n *\n * Brand palette:\n *   Ink #03080A   Cloud #FCFCFE   Grape #7624F4\n *   Volt #C8FF00  Coral #FF6849   Royal #035ADE\n */\n\n/* ── Code font: Geist Mono ── */\n@import url('https://fonts.googleapis.com/css2?family=Geist+Mono:wght@400;500;600\u0026display=swap');\n\n/*\n * Inverse semantic pair mirrors packages/frontend/components/ui/theme.css.\n * Mintlify is a separate app, so its generated tooltip DOM uses the same\n * light Ink/Cloud and dark Cloud/Ink values through RGB channel variables.\n */\n:root {\n  --inverse: 3 8 10;\n  --inverse-foreground: 252 252 254;\n  --tooltip-background: var(--inverse);\n  --tooltip-foreground: var(--inverse-foreground);\n}\n\ncode,\npre,\npre code,\n.code-block code,\n[class*=\"code\"] code {\n  font-family: 'Geist Mono', ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;\n}\n\n/* ── Text selection: accent tint per DESIGN.md ── */\n::selection {\n  background: rgb(118 36 244 / 0.14);\n}\n\n.dark ::selection,\nhtml.dark ::selection {\n  background: rgb(200 255 0 / 0.14);\n  color: inherit;\n}\n\n/* ── Dark-mode accent swap: Volt (#C8FF00 = rgb(200 255 0)) per DESIGN.md ──\n * Mintlify + Tailwind use space-separated RGB: rgb(var(--primary-light) / alpha).\n * Override accent in dark mode from Grape to Volt. */\n.dark,\n[data-theme=\"dark\"],\nhtml.dark {\n  --primary: 200 255 0;\n  --primary-light: 200 255 0;\n  --primary-dark: 200 255 0;\n  --light-primary: 200 255 0;\n  --primary-foreground: 3 8 10;\n  --inverse: 252 252 254;\n  --inverse-foreground: 3 8 10;\n\n  /* ── Dark-mode border: Cloud at 14% per DESIGN.md ── */\n  --default-border-color: rgb(252 252 254 / 0.14);\n}\n\n/* ── Border radius: bauhaus 4/6/8px scale ── */\n#navbar {\n  border-radius: 0;\n}\n\n/* Sidebar active item */\n#sidebar a[aria-current=\"page\"],\nnav[aria-label=\"Pages\"] a[aria-current=\"page\"] {\n  border-radius: 8px;\n}\n\n/* Cards and code blocks */\n[data-component-part=\"code-block-root\"] {\n  border-radius: 8px;\n}\n\n/* ── Link styling per DESIGN.md ──\n * underline at 40% opacity of current color, full on hover, offset 2px */\na:not([class]) {\n  text-decoration-thickness: 1px;\n  text-underline-offset: 2px;\n  text-decoration-color: rgb(0 0 0 / 0.4);\n}\n\na:not([class]):hover {\n  text-decoration-color: currentColor;\n}\n\n.dark a:not([class]),\nhtml.dark a:not([class]) {\n  text-decoration-color: rgb(255 255 255 / 0.4);\n}\n\n.dark a:not([class]):hover,\nhtml.dark a:not([class]):hover {\n  text-decoration-color: currentColor;\n}\n\n/* ── Sidebar badges: outline style ── */\n.nav-tag-pill-text {\n  background: transparent !important;\n  color: rgb(0 0 0 / 0.5) !important;\n  border: 1px solid rgb(0 0 0 / 0.2) !important;\n}\n\n.dark .nav-tag-pill-text,\nhtml.dark .nav-tag-pill-text {\n  background: transparent !important;\n  color: rgb(252 252 254 / 0.5) !important;\n  border: 1px solid rgb(252 252 254 / 0.2) !important;\n}\n\n/* Match the home navbar logo height (h-6 / 1.5rem). */\n.nav-logo {\n  height: 1.5rem;\n}\n\n/* ── Sidebar expand chevrons: raise dark-mode contrast ──\n * Collapsible group toggles render a caret whose default dark tone\n * (gray-600 on Ink) is nearly invisible, so it isn't clear which items\n * have subsections. Derive the caret from Cloud via the DESIGN.md opacity\n * scale: muted-foreground (Cloud `a0`) at rest, full Cloud (foreground) on\n * hover — no custom hex outside the brand palette. */\n.dark nav[aria-label=\"Pages\"] button[aria-expanded] svg.transition-transform,\nhtml.dark nav[aria-label=\"Pages\"] button[aria-expanded] svg.transition-transform {\n  color: rgb(252 252 254 / 0.627);\n}\n\n.dark nav[aria-label=\"Pages\"] button[aria-expanded]:hover svg.transition-transform,\nhtml.dark nav[aria-label=\"Pages\"] button[aria-expanded]:hover svg.transition-transform {\n  color: rgb(252 252 254);\n}\n\n/* ── Sidebar expand chevrons: enlarge for legibility ──\n * The default caret (w-2 ≈ 8px) is easy to miss; bump its footprint so it\n * reads clearly as an expandable affordance. */\nnav[aria-label=\"Pages\"] button[aria-expanded] svg.transition-transform {\n  width: 0.625rem;\n  height: 0.625rem;\n}\n\n/* ── Tooltips: inverse surface pairing ──\n * Mintlify has a foreground variable for Radix tooltips but no matching\n * background variable, so both values are mirrored here from the inverse pair.\n * Radix opens tooltips as \"delayed-open\" on a normal hover but \"instant-open\"\n * when moving between triggers within its skip-delay window; cover both. */\n[data-radix-popper-content-wrapper]\n  \u003e div[data-state=\"delayed-open\"],\n[data-radix-popper-content-wrapper]\n  \u003e div[data-state=\"instant-open\"] {\n  background-color: rgb(var(--tooltip-background)) !important;\n  color: rgb(var(--tooltip-foreground)) !important;\n}\n\n/* ── Callout + code block alignment ──\n * A code block that is the only child of a callout body carries Mintlify's default\n * prose margins (mt-5 mb-8), which push the snippet down so it no longer lines\n * up with the top-aligned callout icon. Drop those margins so the snippet's\n * top edge aligns with the icon. */\n.callout [data-component-part=\"callout-content\"] \u003e .code-block:first-child {\n  margin-top: 0;\n}\n\n.callout [data-component-part=\"callout-content\"] \u003e .code-block:last-child {\n  margin-bottom: 0;\n}\n\n/* ── Floating code-block buttons: opaque background ──\n * Mintlify only backs the floating buttons (report / copy / ask) with\n * gray-100/gray-800 when the code block has no fade overlay\n * (group-[:not(:has([data-fade-overlay]))]). Collapsible/expandable blocks\n * always carry a fade overlay, so the buttons stay transparent and the code\n * text bleeds through behind them. Apply the same background unconditionally\n * so the buttons are legible on every code block. */\n[data-floating-buttons] button {\n  background-color: rgb(241 239 245);\n}\n\n.dark [data-floating-buttons] button,\nhtml.dark [data-floating-buttons] button {\n  background-color: rgb(40 38 44);\n}\n\n/* ── Changelog: Update tags as outline pills (matches sidebar badges) ── */\n[data-component-part=\"update-tag\"] {\n  border: 1px solid rgb(0 0 0 / 0.2);\n  border-radius: 9999px;\n  padding: 0.125rem 0.625rem;\n  font-size: 0.75rem;\n  line-height: 1.25rem;\n  color: rgb(0 0 0 / 0.6);\n}\n\n.dark [data-component-part=\"update-tag\"],\nhtml.dark [data-component-part=\"update-tag\"] {\n  border-color: rgb(252 252 254 / 0.2);\n  color: rgb(252 252 254 / 0.6);\n}\n\n/* ── Navbar CTA: drop the chevron, pair label and background per theme ──\n * Mintlify renders the primary CTA with a trailing chevron, a text-white\n * label, and a bg-primary-dark fill in both themes (primary-dark maps to\n * docs.json colors.dark = Volt). Per DESIGN.md the pairings are white on\n * Grape in light mode and Ink on Volt in dark mode, which is exactly what\n * --primary already resolves to (Grape from docs.json, Volt via the\n * dark-mode swap above). */\n#topbar-cta-button svg {\n  display: none;\n}\n\n/* Mintlify pads the CTA pl-3/pr-2 to hug the chevron; even it out. */\n#topbar-cta-button a {\n  padding-right: 0.75rem;\n}\n\n#topbar-cta-button .bg-primary-dark {\n  background-color: rgb(var(--primary));\n}\n\n.dark #topbar-cta-button .text-white,\nhtml.dark #topbar-cta-button .text-white {\n  color: rgb(3 8 10);\n}\n\n/* ── Changelog: selected filter pill readability ──\n * Mintlify renders the active filter as bg-primary + text-white/90. In dark\n * mode our primary is Volt (#C8FF00), so switch the text to Ink per DESIGN.md. */\n.dark #changelog-filters-content button.bg-primary,\nhtml.dark #changelog-filters-content button.bg-primary {\n  color: rgb(3 8 10 / 0.9) !important;\n}\n\n/* ── Changelog: separate inline status badges from bullet text ── */\n.changelog-status-badge {\n  margin-left: 0.5rem;\n}\n\n.changelog-status-badge[data-color=\"gray\"] {\n  border: 1px solid rgb(3 8 10 / 0.3) !important;\n}\n\n.dark .changelog-status-badge[data-color=\"gray\"],\nhtml.dark .changelog-status-badge[data-color=\"gray\"] {\n  border-color: rgb(252 252 254 / 0.4) !important;\n}\n\n/* ── Mermaid: center diagrams in the content column ── */\n.mermaid \u003e svg {\n  margin-inline: auto;\n}\n"])</script><script>self.__next_f.push([1,"4f:[[\"$\",\"style\",\"0\",{\"data-custom-css-index\":0,\"data-custom-css-path\":\"style.css\",\"dangerouslySetInnerHTML\":{\"__html\":\"$54\"}}]]\n56:T5b9,"])</script><script>self.__next_f.push([1,"/*\n * Deep links (e.g. #response-data-pricing-overrides) can land behind the\n * sticky navbar: the browser scrolls to the anchor before hydration and\n * font loading finish, and the subsequent layout shift moves the target\n * up underneath the header. Re-align the anchor once the page has fully\n * settled, unless the user has already scrolled on their own.\n */\nlet didUserScrollAway = false;\n\nfunction markUserScrollAway() {\n  didUserScrollAway = true;\n}\n\nfunction anchorIdFromHash() {\n  const rawId = window.location.hash.slice(1);\n  try {\n    return decodeURIComponent(rawId);\n  } catch {\n    return rawId;\n  }\n}\n\nfunction realignAnchor() {\n  if (didUserScrollAway) {\n    return;\n  }\n  const target = document.querySelector(`[id=\"${CSS.escape(anchorIdFromHash())}\"]`);\n  // scrollIntoView respects the target's CSS scroll-margin-top,\n  // which Mintlify sets to clear the sticky navbar.\n  target?.scrollIntoView();\n}\n\nasync function settleAnchorScroll() {\n  await (document.fonts?.ready ?? Promise.resolve());\n  setTimeout(realignAnchor, 150);\n}\n\nfunction initAnchorScrollFix() {\n  if (!window.location.hash) {\n    return;\n  }\n  for (const event of ['wheel', 'touchmove', 'keydown']) {\n    window.addEventListener(event, markUserScrollAway, { passive: true, once: true });\n  }\n  if (document.readyState === 'complete') {\n    settleAnchorScroll();\n  } else {\n    window.addEventListener('load', settleAnchorScroll, { once: true });\n  }\n}\n\ninitAnchorScrollFix();\n"])</script><script>self.__next_f.push([1,"57:T9bd,"])</script><script>self.__next_f.push([1,"/*\n * The navbar CTA in docs.json is a static \"Sign In\" button. The docs are\n * served same-origin under openrouter.ai, so Clerk's JS-readable\n * `__client_uat` cookie (a sign-in timestamp, `0` or absent when signed\n * out, possibly suffixed with a publishable-key hash) tells us whether\n * the reader is signed in.\n *\n * Signed out: keep \"Sign In\" but carry the current docs page as Clerk's\n * `redirect_url`, so signing in returns the reader to where they were.\n * Signed in: repoint the CTA to \"Home\", which — like the signed-in \"Home\"\n * link in the web app's own navbar — lands on the workspace list rather\n * than the marketing homepage.\n *\n * Mintlify's navbar is React-rendered, so a MutationObserver reapplies\n * the target whenever client-side navigation re-renders the button or\n * changes the page the sign-in should return to, and the cookie is\n * re-read when the tab regains focus so a sign-in or sign-out in another\n * tab is reflected without a reload.\n */\nconst SIGN_IN_HREF = 'https://openrouter.ai/sign-in';\n// Mirrors navbar.primary.label in docs.json.\nconst SIGN_IN_LABEL = 'Sign In';\nconst HOME_HREF = 'https://openrouter.ai/workspaces';\nconst HOME_LABEL = 'Home';\n\nfunction isSignedIn() {\n  return document.cookie.split('; ').some((cookie) =\u003e {\n    const [name, value] = cookie.split('=');\n    return name?.startsWith('__client_uat') \u0026\u0026 value !== undefined \u0026\u0026 value !== '' \u0026\u0026 value !== '0';\n  });\n}\n\nfunction signInHref() {\n  const url = new URL(SIGN_IN_HREF);\n  url.searchParams.set('redirect_url', window.location.href);\n  return url.href;\n}\n\nfunction setLabel(link, text) {\n  const label = [...link.querySelectorAll('*')].findLast(\n    (el) =\u003e !(el instanceof SVGElement) \u0026\u0026 el.childElementCount === 0,\n  );\n  (label ?? link).textContent = text;\n}\n\nfunction applyCta() {\n  const cta = document.querySelector('#topbar-cta-button');\n  if (!cta) {\n    return;\n  }\n  const link = cta.matches('a') ? cta : cta.querySelector('a');\n  if (!link) {\n    return;\n  }\n  const signedIn = isSignedIn();\n  const href = signedIn ? HOME_HREF : signInHref();\n  if (link.getAttribute('href') === href) {\n    return;\n  }\n  link.setAttribute('href', href);\n  setLabel(link, signedIn ? HOME_LABEL : SIGN_IN_LABEL);\n}\n\nfunction initAuthCta() {\n  applyCta();\n  new MutationObserver(applyCta).observe(document.body, {\n    childList: true,\n    subtree: true,\n  });\n  window.addEventListener('focus', applyCta);\n  document.addEventListener('visibilitychange', applyCta);\n}\n\ninitAuthCta();\n"])</script><script>self.__next_f.push([1,"50:[\"$\",\"$L55\",null,{\"customJsDisabled\":false,\"jsFiles\":[{\"_id\":\"6a58359481eda2c0540fae86\",\"filePath\":\"anchor-scroll-fix.js\",\"subdomain\":\"openrouter-d02e98a0\",\"__v\":0,\"content\":\"$56\"},{\"_id\":\"6a98b868be6327d3d8e10c83\",\"filePath\":\"auth-cta.js\",\"subdomain\":\"openrouter-d02e98a0\",\"__v\":0,\"content\":\"$57\"}]}]\n5a:T33153,"])</script><script>self.__next_f.push([1,"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];const Template=({children,data})=\u003e{const replace=s=\u003es.replace(/\\{\\{(\\w+)\\}\\}/g,(_,k)=\u003ek in data?data[k]:`{{${k}}}`);const leafText=node=\u003etypeof node===`string`?node:node?.$$typeof\u0026\u0026typeof node.props?.children===`string`?node.props.children:null;const collapseTokens=nodes=\u003e{const out=[];let i=0;while(i\u003cnodes.length){const ta=leafText(nodes[i]);const tb=leafText(nodes[i+1]);const tc=leafText(nodes[i+2]);if(ta!=null\u0026\u0026tb!=null\u0026\u0026tc!=null){const m=(ta+tb+tc).match(/^([\\s\\S]*)\\{\\{(\\w+)\\}\\}([\\s\\S]*)$/);if(m\u0026\u0026m[2]in data){out.push(m[1]+data[m[2]]+m[3]);i+=3;continue}}out.push(nodes[i]);i++}return out};const process=node=\u003e{if(typeof node===`string`)return replace(node);if(Array.isArray(node))return collapseTokens(node.map(process));if(node\u0026\u0026typeof node===`object`){if(node.$$typeof)return{...node,props:process(node.props)};return Object.fromEntries(Object.entries(node).map(([k,v])=\u003e[k,process(v)]))}return node};return _jsx(_Fragment,{children:process(children)})};const Model={GPT_4_Omni:`openai/gpt-4o`};const API_KEY_REF=`\u003cOPENROUTER_API_KEY\u003e`;function _createMdxContent(props){const _components={a:`a`,code:`code`,em:`em`,li:`li`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,ul:`ul`,..._provideComponents(),...props.components},{Accordion,CodeBlock,CodeGroup,Heading,Warning,_MdxComponentBoundary}=_components;if(!Accordion)_missingMdxReference(`Accordion`,true);if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!CodeGroup)_missingMdxReference(`CodeGroup`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Warning)_missingMdxReference(`Warning`,true);if(!_MdxComponentBoundary)_missingMdxReference(`_MdxComponentBoundary`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`The OpenRouter API allows streaming responses from `,_jsx(_components.em,{children:`any model`}),`. This is useful for building chat interfaces or other applications where the UI should update as the model generates the response.`]}),`\n`,_jsxs(_components.p,{children:[`To enable streaming, you can set the `,_jsx(_components.code,{children:`stream`}),` parameter to `,_jsx(_components.code,{children:`true`}),` in your request. The model will then stream the response to the client in chunks, rather than returning the entire response at once.`]}),`\n`,_jsx(_components.p,{children:`Here is an example of how to stream a response, and process it:`}),`\n`,_jsx(_MdxComponentBoundary,{name:`Template`,children:_jsx(Template,{data:{API_KEY_REF,MODEL:Model.GPT_4_Omni},children:_jsxs(CodeGroup,{children:[_jsx(CodeBlock,{filename:`TypeScript SDK`,lines:`true`,expandable:`true`,numberOfLines:`31`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`31`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`OpenRouter`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '@openrouter/sdk'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` openRouter`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` OpenRouter`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`  apiKey:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{{API_KEY_REF}}'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`});`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` question`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'How would you build the tallest building ever?'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` stream`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` openRouter`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`chat`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`send`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`  chatRequest:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    model:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{{MODEL}}'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    messages:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [{ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`role:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'user'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` question`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    stream:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`});`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`stream`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` instanceof`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#4EC9B0`},children:` ReadableStream`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  throw`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` Error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Expected a streaming response'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` chunk`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` of`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` stream`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`  const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` content`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` chunk`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`choices`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`?.[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]?.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`delta`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`?.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`  // Final chunk includes usage stats`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`chunk`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`usage`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Usage:'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`chunk`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`usage`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),_jsx(CodeBlock,{filename:`Python`,lines:`true`,expandable:`true`,numberOfLines:`50`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`50`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` requests`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` json`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`question `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"How would you build the tallest building ever?\"`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`url `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"https://openrouter.ai/api/v1/chat/completions\"`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`headers `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`  \"Authorization\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Bearer `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`{{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`API_KEY_REF`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`}}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`  \"Content-Type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"application/json\"`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`payload `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`  \"model\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`MODEL`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`  \"messages\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: question}],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`  \"stream\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`buffer `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"\"`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` requests.post(url, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`headers`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`headers, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`json`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`payload, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`stream`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` r:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` chunk `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` r.iter_content(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`chunk_size`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1024`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`decode_unicode`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    buffer `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`+=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` chunk`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    while`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`      try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`        # Find the next complete SSE line`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`        line_end `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` buffer.find(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`\\\\n`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` line_end `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`==`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` -`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`          break`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`        line `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` buffer[:line_end].strip()`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`        buffer `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` buffer[line_end `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`+`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:]`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`        # Skip SSE comments (lines starting with \":\"), e.g. the`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`        # \": OPENROUTER PROCESSING\" keep-alive — they are not JSON`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` line.startswith(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`':'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`          continue`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` line.startswith(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'data: '`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`          data `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` line[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`6`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:]`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`          if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` data `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`==`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '[DONE]'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`            break`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`          try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`            data_obj `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` json.loads(data)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`            content `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` data_obj[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"choices\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`][`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`][`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"delta\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`].get(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`            if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` content:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`              print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(content, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`end`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`flush`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`          except`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` json.JSONDecodeError:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`            pass`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`      except`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` Exception`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        break`})}),`\n`]})})}),_jsx(CodeBlock,{filename:`TypeScript (fetch)`,lines:`true`,expandable:`true`,numberOfLines:`61`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`61`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` question`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'How would you build the tallest building ever?'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` response`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` fetch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'https://openrouter.ai/api/v1/chat/completions'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`  method:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'POST'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`  headers:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    Authorization:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\" `Bearer \"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`API_KEY_REF`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`    'Content-Type'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'application/json'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  },`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`  body:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` JSON`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`stringify`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    model:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{{MODEL}}'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    messages:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [{ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`role:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'user'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` question`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    stream:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }),`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`});`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` reader`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` response`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`body`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`?.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`getReader`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`reader`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  throw`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` Error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Response body is not readable'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` decoder`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` TextDecoder`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`let`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` buffer`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` ''`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  while`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`    const`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`done`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`value`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` reader`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`read`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`done`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`break`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`    // Append new chunk to buffer`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    buffer`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` +=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` decoder`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`decode`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`value`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`stream:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` });`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`    // Process complete lines from buffer`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    while`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`      const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` lineEnd`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` buffer`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`indexOf`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`\\\\n`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`      if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`lineEnd`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ===`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` -`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`break`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`      const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` line`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` buffer`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`slice`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`lineEnd`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`).`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`trim`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      buffer`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` buffer`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`slice`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`lineEnd`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` +`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`      // Skip SSE comments (lines starting with \":\"), e.g. the`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`      // \": OPENROUTER PROCESSING\" keep-alive — they are not JSON`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`      if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`line`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`startsWith`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`':'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`continue`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`      if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`line`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`startsWith`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'data: '`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`        const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` data`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` line`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`slice`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`6`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`data`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ===`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '[DONE]'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`break`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`          const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` parsed`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` JSON`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`parse`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`data`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`          const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` content`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` parsed`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`choices`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`].`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`delta`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`          if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`            console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`          }`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`        } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`catch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`e`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`          // Ignore invalid JSON`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`        }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`      }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`} `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`finally`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`  reader`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`cancel`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})})]})})}),`\n`,_jsx(Heading,{level:`3`,id:`additional-information`,children:`Additional information`}),`\n`,_jsx(_components.p,{children:`For SSE (Server-Sent Events) streams, OpenRouter occasionally sends comments to prevent connection timeouts. These comments look like:`}),`\n`,_jsx(CodeBlock,{filename:``,lines:`true`,numberOfLines:`2`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`2`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`: OPENROUTER PROCESSING`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsxs(_components.p,{children:[`Comment payload can be safely ignored per the `,_jsx(_components.a,{href:`https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation`,children:`SSE specs`}),`. However, you can use it to improve UX as needed, e.g. by showing a dynamic loading indicator.`]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`If you parse the stream by hand, skip lines that start with `,_jsx(_components.code,{children:`:`}),` before\ncalling `,_jsx(_components.code,{children:`JSON.parse`}),`. Passing a comment line like `,_jsx(_components.code,{children:`: OPENROUTER PROCESSING`}),`\nto `,_jsx(_components.code,{children:`JSON.parse`}),` throws, and unhandled it will crash your stream loop. The\nsnippets above handle this.`]})}),`\n`,_jsxs(_components.p,{children:[`A spec-compliant parser such as `,_jsx(_components.a,{href:`https://github.com/rexxars/eventsource-parser`,children:`eventsource-parser`}),` handles comments, multi-line `,_jsx(_components.code,{children:`data:`}),` fields, and buffering for you:`]}),`\n`,_jsx(CodeBlock,{filename:`eventsource-parser`,lines:`true`,expandable:`true`,numberOfLines:`43`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`43`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`createParser`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'eventsource-parser'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` response`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` fetch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'https://openrouter.ai/api/v1/chat/completions'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`  method:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'POST'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`  headers:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    Authorization:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\" `Bearer \"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`process`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`env`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`OPENROUTER_API_KEY`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`    'Content-Type'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'application/json'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  },`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`  body:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` JSON`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`stringify`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    model:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'openai/gpt-4o'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    messages:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [{ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`role:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'user'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'Hello'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    stream:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }),`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`});`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Errors that occur before streaming starts are plain JSON, not SSE`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`response`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`ok`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`  const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` error`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` response`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`json`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  throw`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` Error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`message`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` parser`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` createParser`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`  onEvent`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`event`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`event`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`data`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ===`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '[DONE]'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`      const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` chunk`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` JSON`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`parse`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`event`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`data`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`      const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` content`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` chunk`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`choices`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`?.[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]?.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`delta`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`?.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`      if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`      }`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`catch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`      // Ignore invalid JSON`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`});`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` reader`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` response`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`body`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`getReader`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` decoder`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` TextDecoder`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`while`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`  const`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`done`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`value`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` reader`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`read`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`done`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`break`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`  parser`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`feed`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`decoder`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`decode`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`value`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`stream:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }));`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`A parser only handles the SSE framing. Errors that occur mid-generation still arrive as regular `,_jsx(_components.code,{children:`data:`}),` events with an `,_jsx(_components.code,{children:`error`}),` field. See `,_jsx(_components.a,{href:`#handling-errors-during-streaming`,children:`Handling Errors During Streaming`}),` below.`]}),`\n`,_jsxs(_components.p,{children:[`The generation ID is returned in the `,_jsx(_components.code,{children:`X-Generation-Id`}),` response header for all endpoints (chat completions, completions, responses, and messages), which can be useful for debugging and correlating requests.`]}),`\n`,_jsxs(_components.p,{children:[`Some SSE client implementations might not parse the payload according to spec, which leads to an uncaught error when you `,_jsx(_components.code,{children:`JSON.stringify`}),` the non-JSON payloads. We recommend the following clients:`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:_jsx(_components.a,{href:`https://github.com/rexxars/eventsource-parser`,children:`eventsource-parser`})}),`\n`,_jsx(_components.li,{children:_jsx(_components.a,{href:`https://www.npmjs.com/package/openai`,children:`OpenAI SDK`})}),`\n`,_jsx(_components.li,{children:_jsx(_components.a,{href:`https://www.npmjs.com/package/ai`,children:`Vercel AI SDK`})}),`\n`]}),`\n`,_jsx(Heading,{level:`3`,id:`the-final-usage-chunk-chat-completions`,children:`The final usage chunk (Chat Completions)`}),`\n`,_jsxs(_components.p,{children:[`On the Chat Completions endpoint (`,_jsx(_components.code,{children:`/api/v1/chat/completions`}),`), every stream ends with an extra chunk that carries the `,_jsx(_components.code,{children:`usage`}),` object for the request, sent just before the `,_jsx(_components.code,{children:`[DONE]`}),` message. OpenAI’s spec emits this chunk with an empty `,_jsx(_components.code,{children:`choices`}),` array, but many clients crash when accessing `,_jsx(_components.code,{children:`choices[0].delta`}),` on it, so OpenRouter intentionally deviates: the usage chunk contains one choice with a content-free `,_jsx(_components.code,{children:`delta`}),` that repeats the `,_jsx(_components.code,{children:`finish_reason`}),` (and `,_jsx(_components.code,{children:`native_finish_reason`}),`) of the stream.`]}),`\n`,_jsx(CodeBlock,{filename:``,lines:`true`,numberOfLines:`4`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`4`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`data: {\"id\":\"gen-abc123\",...,\"choices\":[{\"index\":0,\"delta\":{\"content\":\"\",\"role\":\"assistant\"},\"finish_reason\":\"stop\",\"native_finish_reason\":\"stop\"}]}`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`data: {\"id\":\"gen-abc123\",...,\"choices\":[{\"index\":0,\"delta\":{\"content\":\"\",\"role\":\"assistant\"},\"finish_reason\":\"stop\",\"native_finish_reason\":\"stop\"}],\"usage\":{...}}`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`data: [DONE]`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsxs(_components.p,{children:[`This means the terminal `,_jsx(_components.code,{children:`finish_reason`}),` appears twice: once on the last content-bearing chunk and again on the usage chunk. Clients that validate streams should treat the usage chunk as an accounting frame rather than a second terminal event.`]}),`\n`,_jsxs(_components.p,{children:[`This shape is specific to Chat Completions. Other endpoints follow their own specs: the Responses API (`,_jsx(_components.code,{children:`/api/v1/responses`}),`) reports usage in the `,_jsx(_components.code,{children:`response.completed`}),` event, and the Messages API (`,_jsx(_components.code,{children:`/api/v1/messages`}),`) reports it in the `,_jsx(_components.code,{children:`message_delta`}),` event before `,_jsx(_components.code,{children:`message_stop`}),`.`]}),`\n`,_jsx(Heading,{level:`3`,id:`stream-cancellation`,children:`Stream cancellation`}),`\n`,_jsx(_components.p,{children:`Streaming requests can be cancelled by aborting the connection. For supported providers, this immediately stops model processing and billing.`}),`\n`,_jsxs(Accordion,{title:`Provider Support`,id:`provider-support`,children:[_jsx(_components.p,{children:_jsx(_components.strong,{children:`Supported`})}),_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`OpenAI, Azure, Anthropic`}),`\n`,_jsx(_components.li,{children:`Fireworks, Mancer, Recursal`}),`\n`,_jsx(_components.li,{children:`AnyScale, Lepton, OctoAI`}),`\n`,_jsx(_components.li,{children:`Novita, DeepInfra, Together`}),`\n`,_jsx(_components.li,{children:`Cohere, Hyperbolic, Infermatic`}),`\n`,_jsx(_components.li,{children:`Avian, XAI, Cloudflare`}),`\n`,_jsx(_components.li,{children:`SFCompute, Nineteen, Liquid`}),`\n`,_jsx(_components.li,{children:`Friendli, Chutes, DeepSeek`}),`\n`]}),_jsx(_components.p,{children:_jsx(_components.strong,{children:`Not Currently Supported`})}),_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`AWS Bedrock, Groq, Modal`}),`\n`,_jsx(_components.li,{children:`Google, Google AI Studio, Minimax`}),`\n`,_jsx(_components.li,{children:`HuggingFace, Replicate, Perplexity`}),`\n`,_jsx(_components.li,{children:`Mistral, AI21, Featherless`}),`\n`,_jsx(_components.li,{children:`Lynn, Lambda, Reflection`}),`\n`,_jsx(_components.li,{children:`SambaNova, Inflection, ZeroOneAI`}),`\n`,_jsx(_components.li,{children:`AionLabs, Alibaba, Nebius`}),`\n`,_jsx(_components.li,{children:`Kluster, Targon, InferenceNet`}),`\n`]})]}),`\n`,_jsx(_components.p,{children:`To implement stream cancellation:`}),`\n`,_jsx(_MdxComponentBoundary,{name:`Template`,children:_jsx(Template,{data:{API_KEY_REF,MODEL:Model.GPT_4_Omni},children:_jsxs(CodeGroup,{children:[_jsx(CodeBlock,{filename:`TypeScript SDK`,lines:`true`,expandable:`true`,numberOfLines:`39`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`39`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`OpenRouter`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '@openrouter/sdk'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` openRouter`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` OpenRouter`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`  apiKey:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{{API_KEY_REF}}'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`});`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` controller`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` AbortController`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`  const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` stream`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` openRouter`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`chat`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`send`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    chatRequest:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      model:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{{MODEL}}'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      messages:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [{ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`role:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'user'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'Write a story'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      stream:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }, {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    signal:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` controller`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`signal`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  });`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`stream`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` instanceof`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#4EC9B0`},children:` ReadableStream`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    throw`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` Error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Expected a streaming response'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  for`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` chunk`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` of`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` stream`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`    const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` content`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` chunk`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`choices`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`?.[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]?.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`delta`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`?.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`} `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`catch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ===`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'AbortError'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Stream cancelled'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`else`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    throw`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// To cancel the stream:`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`controller`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`abort`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`]})})}),_jsx(CodeBlock,{filename:`Python`,lines:`true`,expandable:`true`,numberOfLines:`29`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`29`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` requests`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` threading `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Event, Thread`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` stream_with_cancellation`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`prompt`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`cancel_event`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: Event):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` requests.Session() `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` session:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`        response `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` session.post(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`            \"https://openrouter.ai/api/v1/chat/completions\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`            headers`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Authorization\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Bearer `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`{{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`API_KEY_REF`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`}}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`},`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`            json`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"model\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`MODEL`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"messages\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: prompt}], `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"stream\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`},`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`            stream`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`        )`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`            for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` line `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response.iter_lines():`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`                if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` cancel_event.is_set():`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`                    response.close()`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`                    return`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`                if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` line:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`                    print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(line.decode(), `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`end`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`flush`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        finally`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`            response.close()`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Example usage:`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`cancel_event `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Event()`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`stream_thread `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Thread(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`target`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`lambda`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: stream_with_cancellation(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Write a story\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, cancel_event))`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`stream_thread.start()`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# To cancel the stream:`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`cancel_event.set()`})}),`\n`]})})}),_jsx(CodeBlock,{filename:`TypeScript (fetch)`,lines:`true`,expandable:`true`,numberOfLines:`31`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`31`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` controller`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` AbortController`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`  const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` response`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` fetch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`    'https://openrouter.ai/api/v1/chat/completions'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      method:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'POST'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      headers:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        Authorization:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\" `Bearer \"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`API_KEY_REF`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`        'Content-Type'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'application/json'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`      },`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      body:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` JSON`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`stringify`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        model:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{{MODEL}}'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        messages:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [{ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`role:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'user'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'Write a story'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        stream:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`      }),`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      signal:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` controller`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`signal`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  );`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`  // Process the stream...`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`} `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`catch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ===`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'AbortError'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Stream cancelled'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`else`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    throw`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// To cancel the stream:`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`controller`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`abort`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`]})})})]})})}),`\n`,_jsx(Warning,{children:_jsx(_components.p,{children:`Cancellation only works for streaming requests with supported providers. For\nnon-streaming requests or unsupported providers, the model will continue\nprocessing and you will be billed for the complete response.`})}),`\n`,_jsx(Heading,{level:`3`,id:`handling-errors-during-streaming`,children:`Handling errors during streaming`}),`\n`,_jsx(_components.p,{children:`OpenRouter handles errors differently depending on when they occur during the streaming process:`}),`\n`,_jsx(Heading,{level:`4`,id:`errors-before-the-response-is-committed`,children:`Errors before the response is committed`}),`\n`,_jsx(_components.p,{children:`If an error occurs before OpenRouter has committed the response, you get a standard JSON error response with the appropriate HTTP status code. That covers failures raised before the request reaches a provider, and provider failures visible at connection time such as a connection error or a non-2xx upstream status.`}),`\n`,_jsx(CodeBlock,{filename:``,lines:`true`,numberOfLines:`6`,language:`json`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`json`,children:_jsxs(_components.code,{language:`json`,numberOfLines:`6`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:`  \"error\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:`    \"code\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`400`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:`    \"message\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Invalid model specified\"`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`Common HTTP status codes include:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`400`}),`: Bad Request (invalid parameters)`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`401`}),`: Unauthorized (invalid API key)`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`402`}),`: Payment Required (insufficient credits)`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`429`}),`: Too Many Requests (rate limited)`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`502`}),`: Bad Gateway (provider error)`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`503`}),`: Service Unavailable (no available providers)`]}),`\n`]}),`\n`,_jsx(Heading,{level:`4`,id:`errors-after-the-response-is-committed-mid-stream`,children:`Errors after the response is committed (mid-stream)`}),`\n`,_jsxs(_components.p,{children:[`Once the provider has returned response headers, the `,_jsx(_components.code,{children:`200 OK`}),` status is committed even if no token has been produced yet. Any error after that point arrives as an SSE event rather than as an HTTP status:`]}),`\n`,_jsx(CodeBlock,{filename:``,lines:`true`,numberOfLines:`2`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`2`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`data: {\"id\":\"cmpl-abc123\",\"object\":\"chat.completion.chunk\",\"created\":1234567890,\"model\":\"openai/gpt-4o\",\"provider\":\"openai\",\"error\":{\"code\":\"server_error\",\"message\":\"Provider disconnected unexpectedly\"},\"choices\":[{\"index\":0,\"delta\":{\"content\":\"\"},\"finish_reason\":\"error\"}]}`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsx(_components.p,{children:`Key characteristics of mid-stream errors:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`The error appears at the `,_jsx(_components.strong,{children:`top level`}),` alongside standard response fields (id, object, created, etc.)`]}),`\n`,_jsxs(_components.li,{children:[`A `,_jsx(_components.code,{children:`choices`}),` array is included with `,_jsx(_components.code,{children:`finish_reason: \"error\"`}),` to properly terminate the stream`]}),`\n`,_jsx(_components.li,{children:`The HTTP status remains 200 OK since headers were already sent`}),`\n`,_jsx(_components.li,{children:`The stream is terminated after this unified error event`}),`\n`,_jsxs(_components.li,{children:[`The error can be the first and only event in the stream, so treat a `,_jsx(_components.code,{children:`200`}),` carrying an `,_jsx(_components.code,{children:`error`}),` chunk with no content as a failure, not a success`]}),`\n`]}),`\n`,_jsx(Heading,{level:`4`,id:`code-examples`,children:`Code examples`}),`\n`,_jsx(_components.p,{children:`Here’s how to properly handle both types of errors in your streaming implementation:`}),`\n`,_jsx(_MdxComponentBoundary,{name:`Template`,children:_jsx(Template,{data:{API_KEY_REF,MODEL:Model.GPT_4_Omni},children:_jsxs(CodeGroup,{children:[_jsx(CodeBlock,{filename:`TypeScript SDK`,lines:`true`,expandable:`true`,numberOfLines:`41`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`41`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`OpenRouter`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '@openrouter/sdk'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` openRouter`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` OpenRouter`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`  apiKey:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{{API_KEY_REF}}'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`});`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`async`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` function`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` streamWithErrorHandling`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`prompt`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` string`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`    const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` stream`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` openRouter`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`chat`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`send`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      chatRequest:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        model:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{{MODEL}}'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        messages:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [{ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`role:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'user'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` prompt`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        stream:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`      },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    });`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`stream`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` instanceof`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#4EC9B0`},children:` ReadableStream`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`      throw`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` Error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Expected a streaming response'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    }`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    for`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` chunk`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` of`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` stream`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`      // Check for errors in chunk`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`      if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'error'`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` chunk`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`Stream error: \"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`chunk`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`message`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`chunk`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`choices`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`?.[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]?.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`finish_reason`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ===`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'error'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`          console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Stream terminated due to error'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`        }`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`      }`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`      // Process normal content`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`      const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` content`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` chunk`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`choices`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`?.[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]?.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`delta`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`?.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`      if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`      }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    }`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`catch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`    // Handle pre-stream errors`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`Error: \"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`message`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),_jsx(CodeBlock,{filename:`Python`,lines:`true`,expandable:`true`,numberOfLines:`48`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`48`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` requests`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` json`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`async`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` stream_with_error_handling`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`prompt`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    response `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` requests.post(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`        'https://openrouter.ai/api/v1/chat/completions'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`        headers`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Authorization'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Bearer `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`{{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`API_KEY_REF`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`}}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`},`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`        json`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`            'model'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`MODEL`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`            'messages'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'role'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'user'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'content'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: prompt}],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`            'stream'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`        },`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`        stream`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    )`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`    # Check initial HTTP status for pre-stream errors`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response.status_code `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 200`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`        error_data `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response.json()`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`        print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Error: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`error_data[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'error'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`][`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'message'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        return`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`    # Process stream and handle mid-stream errors`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` line `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response.iter_lines():`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` line:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`            line_text `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` line.decode(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'utf-8'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`            if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` line_text.startswith(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'data: '`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`                data `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` line_text[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`6`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:]`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`                if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` data `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`==`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '[DONE]'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`                    break`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`                try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`                    parsed `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` json.loads(data)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`                    # Check for mid-stream error`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`                    if`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'error'`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` parsed:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`                        print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Stream error: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`parsed[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'error'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`][`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'message'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`                        # Check finish_reason if needed`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`                        if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` parsed.get(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'choices'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, [{}])[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`].get(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'finish_reason'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`==`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'error'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`                            print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Stream terminated due to error\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`                        break`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`                    # Process normal content`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`                    content `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` parsed[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'choices'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`][`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`][`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'delta'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`].get(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'content'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`                    if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` content:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`                        print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(content, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`end`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`''`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`flush`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`                except`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` json.JSONDecodeError:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`                    pass`})}),`\n`]})})}),_jsx(CodeBlock,{filename:`TypeScript (fetch)`,lines:`true`,expandable:`true`,numberOfLines:`76`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`76`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`async`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` function`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` streamWithErrorHandling`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`prompt`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` string`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`  const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` response`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` fetch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`    'https://openrouter.ai/api/v1/chat/completions'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      method:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'POST'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      headers:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`        'Authorization'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\" `Bearer \"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`API_KEY_REF`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`        'Content-Type'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'application/json'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`      },`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      body:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` JSON`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`stringify`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        model:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{{MODEL}}'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        messages:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [{ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`role:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'user'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` prompt`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        stream:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`      }),`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  );`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`  // Check initial HTTP status for pre-stream errors`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`response`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`ok`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`    const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` error`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` response`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`json`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`Error: \"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`message`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`  const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` reader`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` response`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`body`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`?.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`getReader`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`reader`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`throw`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` Error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'No response body'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`  const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` decoder`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` TextDecoder`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`  let`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` buffer`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` ''`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    while`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`      const`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`done`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`value`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` reader`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`read`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`      if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`done`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`break`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      buffer`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` +=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` decoder`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`decode`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`value`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`stream:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` });`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`      while`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`        const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` lineEnd`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` buffer`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`indexOf`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`\\\\n`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`lineEnd`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ===`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` -`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`break`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`        const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` line`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` buffer`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`slice`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`lineEnd`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`).`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`trim`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        buffer`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` buffer`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`slice`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`lineEnd`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` +`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`line`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`startsWith`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'data: '`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`          const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` data`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` line`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`slice`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`6`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`          if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`data`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ===`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '[DONE]'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`          try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`            const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` parsed`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` JSON`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`parse`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`data`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`            // Check for mid-stream error`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`            if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`parsed`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`              console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`Stream error: \"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`parsed`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`message`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`              // Check finish_reason if needed`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`              if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`parsed`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`choices`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`?.[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]?.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`finish_reason`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ===`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'error'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`                console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Stream terminated due to error'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`              }`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`              return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`            }`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`            // Process normal content`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`            const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` content`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` parsed`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`choices`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`].`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`delta`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`            if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`              console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`            }`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`          } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`catch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`e`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`            // Ignore parsing errors`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`          }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`        }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`      }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    }`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`finally`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    reader`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`cancel`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})})]})})}),`\n`,_jsx(Heading,{level:`4`,id:`api-specific-behavior`,children:`API-specific behavior`}),`\n`,_jsx(_components.p,{children:`Different API endpoints may handle streaming errors slightly differently:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`OpenAI Chat Completions API`}),`: Returns `,_jsx(_components.code,{children:`ErrorResponse`}),` directly if no chunks were processed, or includes error information in the response if some chunks were processed`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`OpenAI Responses API`}),`: May transform certain error codes (like `,_jsx(_components.code,{children:`context_length_exceeded`}),`) into a successful response with `,_jsx(_components.code,{children:`finish_reason: \"length\"`}),` instead of treating them as errors`]}),`\n`]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{Template,Model,API_KEY_REF,default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}"])</script><script>self.__next_f.push([1,"5b:T32d06,"])</script><script>self.__next_f.push([1,"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];const Template=()=\u003enull;const Model=undefined;const API_KEY_REF=undefined;function _createMdxContent(props){const _components={a:`a`,code:`code`,em:`em`,li:`li`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,ul:`ul`,..._provideComponents(),...props.components},{Accordion,CodeBlock,CodeGroup,Heading,Warning,_MdxComponentBoundary}=_components;if(!Accordion)_missingMdxReference(`Accordion`,true);if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!CodeGroup)_missingMdxReference(`CodeGroup`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Warning)_missingMdxReference(`Warning`,true);if(!_MdxComponentBoundary)_missingMdxReference(`_MdxComponentBoundary`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`The OpenRouter API allows streaming responses from `,_jsx(_components.em,{children:`any model`}),`. This is useful for building chat interfaces or other applications where the UI should update as the model generates the response.`]}),`\n`,_jsxs(_components.p,{children:[`To enable streaming, you can set the `,_jsx(_components.code,{children:`stream`}),` parameter to `,_jsx(_components.code,{children:`true`}),` in your request. The model will then stream the response to the client in chunks, rather than returning the entire response at once.`]}),`\n`,_jsx(_components.p,{children:`Here is an example of how to stream a response, and process it:`}),`\n`,_jsx(_MdxComponentBoundary,{name:`Template`,children:_jsx(Template,{children:_jsxs(CodeGroup,{children:[_jsx(CodeBlock,{filename:`TypeScript SDK`,lines:`true`,expandable:`true`,numberOfLines:`31`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`31`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`OpenRouter`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '@openrouter/sdk'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` openRouter`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` OpenRouter`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`  apiKey:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{{API_KEY_REF}}'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`});`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` question`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'How would you build the tallest building ever?'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` stream`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` openRouter`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`chat`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`send`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`  chatRequest:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    model:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{{MODEL}}'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    messages:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [{ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`role:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'user'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` question`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    stream:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`});`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`stream`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` instanceof`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#4EC9B0`},children:` ReadableStream`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  throw`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` Error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Expected a streaming response'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` chunk`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` of`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` stream`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`  const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` content`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` chunk`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`choices`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`?.[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]?.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`delta`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`?.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`  // Final chunk includes usage stats`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`chunk`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`usage`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Usage:'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`chunk`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`usage`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),_jsx(CodeBlock,{filename:`Python`,lines:`true`,expandable:`true`,numberOfLines:`50`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`50`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` requests`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` json`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`question `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"How would you build the tallest building ever?\"`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`url `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"https://openrouter.ai/api/v1/chat/completions\"`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`headers `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`  \"Authorization\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Bearer `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`{{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`API_KEY_REF`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`}}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`  \"Content-Type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"application/json\"`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`payload `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`  \"model\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`MODEL`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`  \"messages\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: question}],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`  \"stream\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`buffer `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"\"`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` requests.post(url, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`headers`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`headers, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`json`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`payload, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`stream`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` r:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` chunk `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` r.iter_content(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`chunk_size`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1024`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`decode_unicode`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    buffer `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`+=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` chunk`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    while`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`      try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`        # Find the next complete SSE line`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`        line_end `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` buffer.find(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`\\\\n`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` line_end `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`==`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` -`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`          break`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`        line `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` buffer[:line_end].strip()`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`        buffer `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` buffer[line_end `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`+`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:]`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`        # Skip SSE comments (lines starting with \":\"), e.g. the`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`        # \": OPENROUTER PROCESSING\" keep-alive — they are not JSON`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` line.startswith(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`':'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`          continue`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` line.startswith(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'data: '`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`          data `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` line[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`6`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:]`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`          if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` data `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`==`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '[DONE]'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`            break`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`          try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`            data_obj `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` json.loads(data)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`            content `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` data_obj[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"choices\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`][`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`][`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"delta\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`].get(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`            if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` content:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`              print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(content, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`end`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`flush`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`          except`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` json.JSONDecodeError:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`            pass`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`      except`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` Exception`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        break`})}),`\n`]})})}),_jsx(CodeBlock,{filename:`TypeScript (fetch)`,lines:`true`,expandable:`true`,numberOfLines:`61`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`61`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` question`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'How would you build the tallest building ever?'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` response`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` fetch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'https://openrouter.ai/api/v1/chat/completions'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`  method:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'POST'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`  headers:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    Authorization:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\" `Bearer \"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`API_KEY_REF`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`    'Content-Type'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'application/json'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  },`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`  body:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` JSON`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`stringify`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    model:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{{MODEL}}'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    messages:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [{ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`role:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'user'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` question`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    stream:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }),`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`});`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` reader`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` response`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`body`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`?.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`getReader`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`reader`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  throw`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` Error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Response body is not readable'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` decoder`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` TextDecoder`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`let`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` buffer`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` ''`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  while`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`    const`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`done`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`value`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` reader`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`read`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`done`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`break`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`    // Append new chunk to buffer`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    buffer`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` +=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` decoder`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`decode`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`value`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`stream:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` });`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`    // Process complete lines from buffer`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    while`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`      const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` lineEnd`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` buffer`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`indexOf`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`\\\\n`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`      if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`lineEnd`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ===`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` -`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`break`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`      const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` line`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` buffer`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`slice`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`lineEnd`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`).`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`trim`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      buffer`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` buffer`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`slice`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`lineEnd`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` +`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`      // Skip SSE comments (lines starting with \":\"), e.g. the`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`      // \": OPENROUTER PROCESSING\" keep-alive — they are not JSON`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`      if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`line`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`startsWith`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`':'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`continue`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`      if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`line`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`startsWith`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'data: '`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`        const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` data`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` line`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`slice`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`6`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`data`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ===`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '[DONE]'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`break`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`          const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` parsed`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` JSON`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`parse`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`data`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`          const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` content`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` parsed`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`choices`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`].`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`delta`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`          if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`            console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`          }`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`        } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`catch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`e`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`          // Ignore invalid JSON`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`        }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`      }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`} `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`finally`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`  reader`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`cancel`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})})]})})}),`\n`,_jsx(Heading,{level:`3`,id:`additional-information`,children:`Additional information`}),`\n`,_jsx(_components.p,{children:`For SSE (Server-Sent Events) streams, OpenRouter occasionally sends comments to prevent connection timeouts. These comments look like:`}),`\n`,_jsx(CodeBlock,{filename:``,lines:`true`,numberOfLines:`2`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`2`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`: OPENROUTER PROCESSING`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsxs(_components.p,{children:[`Comment payload can be safely ignored per the `,_jsx(_components.a,{href:`https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation`,children:`SSE specs`}),`. However, you can use it to improve UX as needed, e.g. by showing a dynamic loading indicator.`]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`If you parse the stream by hand, skip lines that start with `,_jsx(_components.code,{children:`:`}),` before\ncalling `,_jsx(_components.code,{children:`JSON.parse`}),`. Passing a comment line like `,_jsx(_components.code,{children:`: OPENROUTER PROCESSING`}),`\nto `,_jsx(_components.code,{children:`JSON.parse`}),` throws, and unhandled it will crash your stream loop. The\nsnippets above handle this.`]})}),`\n`,_jsxs(_components.p,{children:[`A spec-compliant parser such as `,_jsx(_components.a,{href:`https://github.com/rexxars/eventsource-parser`,children:`eventsource-parser`}),` handles comments, multi-line `,_jsx(_components.code,{children:`data:`}),` fields, and buffering for you:`]}),`\n`,_jsx(CodeBlock,{filename:`eventsource-parser`,lines:`true`,expandable:`true`,numberOfLines:`43`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`43`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`createParser`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'eventsource-parser'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` response`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` fetch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'https://openrouter.ai/api/v1/chat/completions'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`  method:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'POST'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`  headers:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    Authorization:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\" `Bearer \"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`process`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`env`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`OPENROUTER_API_KEY`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`    'Content-Type'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'application/json'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  },`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`  body:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` JSON`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`stringify`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    model:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'openai/gpt-4o'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    messages:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [{ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`role:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'user'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'Hello'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    stream:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }),`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`});`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Errors that occur before streaming starts are plain JSON, not SSE`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`response`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`ok`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`  const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` error`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` response`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`json`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  throw`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` Error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`message`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` parser`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` createParser`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`  onEvent`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`event`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`event`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`data`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ===`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '[DONE]'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`      const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` chunk`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` JSON`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`parse`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`event`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`data`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`      const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` content`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` chunk`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`choices`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`?.[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]?.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`delta`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`?.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`      if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`      }`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`catch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`      // Ignore invalid JSON`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`});`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` reader`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` response`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`body`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`getReader`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` decoder`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` TextDecoder`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`while`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`  const`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`done`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`value`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` reader`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`read`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`done`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`break`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`  parser`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`feed`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`decoder`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`decode`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`value`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`stream:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }));`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`A parser only handles the SSE framing. Errors that occur mid-generation still arrive as regular `,_jsx(_components.code,{children:`data:`}),` events with an `,_jsx(_components.code,{children:`error`}),` field. See `,_jsx(_components.a,{href:`#handling-errors-during-streaming`,children:`Handling Errors During Streaming`}),` below.`]}),`\n`,_jsxs(_components.p,{children:[`The generation ID is returned in the `,_jsx(_components.code,{children:`X-Generation-Id`}),` response header for all endpoints (chat completions, completions, responses, and messages), which can be useful for debugging and correlating requests.`]}),`\n`,_jsxs(_components.p,{children:[`Some SSE client implementations might not parse the payload according to spec, which leads to an uncaught error when you `,_jsx(_components.code,{children:`JSON.stringify`}),` the non-JSON payloads. We recommend the following clients:`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:_jsx(_components.a,{href:`https://github.com/rexxars/eventsource-parser`,children:`eventsource-parser`})}),`\n`,_jsx(_components.li,{children:_jsx(_components.a,{href:`https://www.npmjs.com/package/openai`,children:`OpenAI SDK`})}),`\n`,_jsx(_components.li,{children:_jsx(_components.a,{href:`https://www.npmjs.com/package/ai`,children:`Vercel AI SDK`})}),`\n`]}),`\n`,_jsx(Heading,{level:`3`,id:`the-final-usage-chunk-chat-completions`,children:`The final usage chunk (Chat Completions)`}),`\n`,_jsxs(_components.p,{children:[`On the Chat Completions endpoint (`,_jsx(_components.code,{children:`/api/v1/chat/completions`}),`), every stream ends with an extra chunk that carries the `,_jsx(_components.code,{children:`usage`}),` object for the request, sent just before the `,_jsx(_components.code,{children:`[DONE]`}),` message. OpenAI’s spec emits this chunk with an empty `,_jsx(_components.code,{children:`choices`}),` array, but many clients crash when accessing `,_jsx(_components.code,{children:`choices[0].delta`}),` on it, so OpenRouter intentionally deviates: the usage chunk contains one choice with a content-free `,_jsx(_components.code,{children:`delta`}),` that repeats the `,_jsx(_components.code,{children:`finish_reason`}),` (and `,_jsx(_components.code,{children:`native_finish_reason`}),`) of the stream.`]}),`\n`,_jsx(CodeBlock,{filename:``,lines:`true`,numberOfLines:`4`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`4`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`data: {\"id\":\"gen-abc123\",...,\"choices\":[{\"index\":0,\"delta\":{\"content\":\"\",\"role\":\"assistant\"},\"finish_reason\":\"stop\",\"native_finish_reason\":\"stop\"}]}`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`data: {\"id\":\"gen-abc123\",...,\"choices\":[{\"index\":0,\"delta\":{\"content\":\"\",\"role\":\"assistant\"},\"finish_reason\":\"stop\",\"native_finish_reason\":\"stop\"}],\"usage\":{...}}`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`data: [DONE]`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsxs(_components.p,{children:[`This means the terminal `,_jsx(_components.code,{children:`finish_reason`}),` appears twice: once on the last content-bearing chunk and again on the usage chunk. Clients that validate streams should treat the usage chunk as an accounting frame rather than a second terminal event.`]}),`\n`,_jsxs(_components.p,{children:[`This shape is specific to Chat Completions. Other endpoints follow their own specs: the Responses API (`,_jsx(_components.code,{children:`/api/v1/responses`}),`) reports usage in the `,_jsx(_components.code,{children:`response.completed`}),` event, and the Messages API (`,_jsx(_components.code,{children:`/api/v1/messages`}),`) reports it in the `,_jsx(_components.code,{children:`message_delta`}),` event before `,_jsx(_components.code,{children:`message_stop`}),`.`]}),`\n`,_jsx(Heading,{level:`3`,id:`stream-cancellation`,children:`Stream cancellation`}),`\n`,_jsx(_components.p,{children:`Streaming requests can be cancelled by aborting the connection. For supported providers, this immediately stops model processing and billing.`}),`\n`,_jsxs(Accordion,{title:`Provider Support`,id:`provider-support`,children:[_jsx(_components.p,{children:_jsx(_components.strong,{children:`Supported`})}),_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`OpenAI, Azure, Anthropic`}),`\n`,_jsx(_components.li,{children:`Fireworks, Mancer, Recursal`}),`\n`,_jsx(_components.li,{children:`AnyScale, Lepton, OctoAI`}),`\n`,_jsx(_components.li,{children:`Novita, DeepInfra, Together`}),`\n`,_jsx(_components.li,{children:`Cohere, Hyperbolic, Infermatic`}),`\n`,_jsx(_components.li,{children:`Avian, XAI, Cloudflare`}),`\n`,_jsx(_components.li,{children:`SFCompute, Nineteen, Liquid`}),`\n`,_jsx(_components.li,{children:`Friendli, Chutes, DeepSeek`}),`\n`]}),_jsx(_components.p,{children:_jsx(_components.strong,{children:`Not Currently Supported`})}),_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`AWS Bedrock, Groq, Modal`}),`\n`,_jsx(_components.li,{children:`Google, Google AI Studio, Minimax`}),`\n`,_jsx(_components.li,{children:`HuggingFace, Replicate, Perplexity`}),`\n`,_jsx(_components.li,{children:`Mistral, AI21, Featherless`}),`\n`,_jsx(_components.li,{children:`Lynn, Lambda, Reflection`}),`\n`,_jsx(_components.li,{children:`SambaNova, Inflection, ZeroOneAI`}),`\n`,_jsx(_components.li,{children:`AionLabs, Alibaba, Nebius`}),`\n`,_jsx(_components.li,{children:`Kluster, Targon, InferenceNet`}),`\n`]})]}),`\n`,_jsx(_components.p,{children:`To implement stream cancellation:`}),`\n`,_jsx(_MdxComponentBoundary,{name:`Template`,children:_jsx(Template,{children:_jsxs(CodeGroup,{children:[_jsx(CodeBlock,{filename:`TypeScript SDK`,lines:`true`,expandable:`true`,numberOfLines:`39`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`39`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`OpenRouter`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '@openrouter/sdk'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` openRouter`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` OpenRouter`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`  apiKey:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{{API_KEY_REF}}'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`});`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` controller`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` AbortController`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`  const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` stream`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` openRouter`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`chat`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`send`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    chatRequest:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      model:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{{MODEL}}'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      messages:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [{ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`role:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'user'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'Write a story'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      stream:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }, {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    signal:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` controller`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`signal`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  });`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`stream`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` instanceof`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#4EC9B0`},children:` ReadableStream`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    throw`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` Error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Expected a streaming response'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  for`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` chunk`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` of`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` stream`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`    const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` content`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` chunk`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`choices`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`?.[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]?.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`delta`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`?.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`} `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`catch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ===`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'AbortError'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Stream cancelled'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`else`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    throw`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// To cancel the stream:`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`controller`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`abort`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`]})})}),_jsx(CodeBlock,{filename:`Python`,lines:`true`,expandable:`true`,numberOfLines:`29`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`29`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` requests`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` threading `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Event, Thread`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` stream_with_cancellation`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`prompt`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`cancel_event`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: Event):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` requests.Session() `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` session:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`        response `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` session.post(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`            \"https://openrouter.ai/api/v1/chat/completions\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`            headers`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Authorization\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Bearer `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`{{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`API_KEY_REF`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`}}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`},`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`            json`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"model\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`MODEL`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"messages\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: prompt}], `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"stream\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`},`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`            stream`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`        )`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`            for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` line `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response.iter_lines():`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`                if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` cancel_event.is_set():`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`                    response.close()`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`                    return`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`                if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` line:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`                    print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(line.decode(), `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`end`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`flush`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        finally`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`            response.close()`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Example usage:`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`cancel_event `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Event()`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`stream_thread `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Thread(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`target`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`lambda`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: stream_with_cancellation(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Write a story\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, cancel_event))`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`stream_thread.start()`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# To cancel the stream:`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`cancel_event.set()`})}),`\n`]})})}),_jsx(CodeBlock,{filename:`TypeScript (fetch)`,lines:`true`,expandable:`true`,numberOfLines:`31`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`31`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` controller`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` AbortController`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`  const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` response`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` fetch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`    'https://openrouter.ai/api/v1/chat/completions'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      method:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'POST'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      headers:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        Authorization:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\" `Bearer \"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`API_KEY_REF`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`        'Content-Type'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'application/json'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`      },`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      body:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` JSON`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`stringify`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        model:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{{MODEL}}'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        messages:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [{ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`role:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'user'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'Write a story'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        stream:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`      }),`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      signal:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` controller`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`signal`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  );`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`  // Process the stream...`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`} `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`catch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ===`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'AbortError'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Stream cancelled'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`else`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    throw`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// To cancel the stream:`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`controller`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`abort`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`]})})})]})})}),`\n`,_jsx(Warning,{children:_jsx(_components.p,{children:`Cancellation only works for streaming requests with supported providers. For\nnon-streaming requests or unsupported providers, the model will continue\nprocessing and you will be billed for the complete response.`})}),`\n`,_jsx(Heading,{level:`3`,id:`handling-errors-during-streaming`,children:`Handling errors during streaming`}),`\n`,_jsx(_components.p,{children:`OpenRouter handles errors differently depending on when they occur during the streaming process:`}),`\n`,_jsx(Heading,{level:`4`,id:`errors-before-the-response-is-committed`,children:`Errors before the response is committed`}),`\n`,_jsx(_components.p,{children:`If an error occurs before OpenRouter has committed the response, you get a standard JSON error response with the appropriate HTTP status code. That covers failures raised before the request reaches a provider, and provider failures visible at connection time such as a connection error or a non-2xx upstream status.`}),`\n`,_jsx(CodeBlock,{filename:``,lines:`true`,numberOfLines:`6`,language:`json`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`json`,children:_jsxs(_components.code,{language:`json`,numberOfLines:`6`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:`  \"error\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:`    \"code\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`400`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:`    \"message\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Invalid model specified\"`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`Common HTTP status codes include:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`400`}),`: Bad Request (invalid parameters)`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`401`}),`: Unauthorized (invalid API key)`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`402`}),`: Payment Required (insufficient credits)`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`429`}),`: Too Many Requests (rate limited)`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`502`}),`: Bad Gateway (provider error)`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`503`}),`: Service Unavailable (no available providers)`]}),`\n`]}),`\n`,_jsx(Heading,{level:`4`,id:`errors-after-the-response-is-committed-mid-stream`,children:`Errors after the response is committed (mid-stream)`}),`\n`,_jsxs(_components.p,{children:[`Once the provider has returned response headers, the `,_jsx(_components.code,{children:`200 OK`}),` status is committed even if no token has been produced yet. Any error after that point arrives as an SSE event rather than as an HTTP status:`]}),`\n`,_jsx(CodeBlock,{filename:``,lines:`true`,numberOfLines:`2`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`2`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`data: {\"id\":\"cmpl-abc123\",\"object\":\"chat.completion.chunk\",\"created\":1234567890,\"model\":\"openai/gpt-4o\",\"provider\":\"openai\",\"error\":{\"code\":\"server_error\",\"message\":\"Provider disconnected unexpectedly\"},\"choices\":[{\"index\":0,\"delta\":{\"content\":\"\"},\"finish_reason\":\"error\"}]}`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsx(_components.p,{children:`Key characteristics of mid-stream errors:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`The error appears at the `,_jsx(_components.strong,{children:`top level`}),` alongside standard response fields (id, object, created, etc.)`]}),`\n`,_jsxs(_components.li,{children:[`A `,_jsx(_components.code,{children:`choices`}),` array is included with `,_jsx(_components.code,{children:`finish_reason: \"error\"`}),` to properly terminate the stream`]}),`\n`,_jsx(_components.li,{children:`The HTTP status remains 200 OK since headers were already sent`}),`\n`,_jsx(_components.li,{children:`The stream is terminated after this unified error event`}),`\n`,_jsxs(_components.li,{children:[`The error can be the first and only event in the stream, so treat a `,_jsx(_components.code,{children:`200`}),` carrying an `,_jsx(_components.code,{children:`error`}),` chunk with no content as a failure, not a success`]}),`\n`]}),`\n`,_jsx(Heading,{level:`4`,id:`code-examples`,children:`Code examples`}),`\n`,_jsx(_components.p,{children:`Here’s how to properly handle both types of errors in your streaming implementation:`}),`\n`,_jsx(_MdxComponentBoundary,{name:`Template`,children:_jsx(Template,{children:_jsxs(CodeGroup,{children:[_jsx(CodeBlock,{filename:`TypeScript SDK`,lines:`true`,expandable:`true`,numberOfLines:`41`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`41`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`OpenRouter`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '@openrouter/sdk'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` openRouter`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` OpenRouter`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`  apiKey:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{{API_KEY_REF}}'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`});`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`async`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` function`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` streamWithErrorHandling`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`prompt`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` string`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`    const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` stream`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` openRouter`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`chat`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`send`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      chatRequest:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        model:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{{MODEL}}'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        messages:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [{ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`role:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'user'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` prompt`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        stream:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`      },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    });`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`stream`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` instanceof`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#4EC9B0`},children:` ReadableStream`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`      throw`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` Error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Expected a streaming response'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    }`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    for`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` chunk`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` of`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` stream`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`      // Check for errors in chunk`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`      if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'error'`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` chunk`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`Stream error: \"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`chunk`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`message`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`chunk`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`choices`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`?.[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]?.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`finish_reason`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ===`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'error'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`          console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Stream terminated due to error'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`        }`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`      }`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`      // Process normal content`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`      const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` content`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` chunk`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`choices`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`?.[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]?.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`delta`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`?.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`      if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`      }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    }`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`catch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`    // Handle pre-stream errors`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`Error: \"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`message`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),_jsx(CodeBlock,{filename:`Python`,lines:`true`,expandable:`true`,numberOfLines:`48`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`48`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` requests`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` json`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`async`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` stream_with_error_handling`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`prompt`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    response `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` requests.post(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`        'https://openrouter.ai/api/v1/chat/completions'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`        headers`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Authorization'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Bearer `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`{{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`API_KEY_REF`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`}}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`},`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`        json`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`            'model'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`MODEL`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`            'messages'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'role'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'user'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'content'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: prompt}],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`            'stream'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`        },`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`        stream`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    )`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`    # Check initial HTTP status for pre-stream errors`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response.status_code `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 200`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`        error_data `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response.json()`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`        print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Error: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`error_data[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'error'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`][`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'message'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        return`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`    # Process stream and handle mid-stream errors`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` line `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response.iter_lines():`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` line:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`            line_text `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` line.decode(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'utf-8'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`            if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` line_text.startswith(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'data: '`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`                data `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` line_text[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`6`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:]`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`                if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` data `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`==`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '[DONE]'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`                    break`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`                try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`                    parsed `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` json.loads(data)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`                    # Check for mid-stream error`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`                    if`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'error'`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` parsed:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`                        print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Stream error: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`parsed[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'error'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`][`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'message'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`                        # Check finish_reason if needed`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`                        if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` parsed.get(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'choices'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, [{}])[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`].get(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'finish_reason'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`==`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'error'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`                            print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Stream terminated due to error\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`                        break`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`                    # Process normal content`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`                    content `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` parsed[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'choices'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`][`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`][`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'delta'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`].get(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'content'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`                    if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` content:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`                        print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(content, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`end`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`''`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`flush`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`                except`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` json.JSONDecodeError:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`                    pass`})}),`\n`]})})}),_jsx(CodeBlock,{filename:`TypeScript (fetch)`,lines:`true`,expandable:`true`,numberOfLines:`76`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`76`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`async`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` function`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` streamWithErrorHandling`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`prompt`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` string`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`  const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` response`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` fetch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`    'https://openrouter.ai/api/v1/chat/completions'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      method:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'POST'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      headers:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`        'Authorization'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\" `Bearer \"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`API_KEY_REF`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`        'Content-Type'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'application/json'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`      },`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      body:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` JSON`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`stringify`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        model:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{{MODEL}}'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        messages:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [{ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`role:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'user'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` prompt`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        stream:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`      }),`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  );`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`  // Check initial HTTP status for pre-stream errors`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`response`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`ok`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`    const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` error`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` response`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`json`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`Error: \"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`message`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`  const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` reader`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` response`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`body`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`?.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`getReader`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`reader`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`throw`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` Error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'No response body'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`  const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` decoder`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` TextDecoder`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`  let`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` buffer`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` ''`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`  try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`    while`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`      const`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`done`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`value`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` reader`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`read`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`      if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`done`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`break`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`      buffer`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` +=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` decoder`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`decode`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`value`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`stream:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` });`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`      while`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`        const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` lineEnd`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` buffer`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`indexOf`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`\\\\n`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`lineEnd`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ===`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` -`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`break`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`        const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` line`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` buffer`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`slice`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`lineEnd`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`).`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`trim`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`        buffer`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` buffer`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`slice`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`lineEnd`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` +`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`        if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`line`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`startsWith`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'data: '`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`          const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` data`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` line`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`slice`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`6`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`          if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`data`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ===`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '[DONE]'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`          try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`            const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` parsed`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` JSON`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`parse`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`data`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`            // Check for mid-stream error`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`            if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`parsed`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`              console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`Stream error: \"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`parsed`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`message`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`              // Check finish_reason if needed`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`              if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`parsed`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`choices`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`?.[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]?.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`finish_reason`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ===`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'error'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`                console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Stream terminated due to error'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`              }`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`              return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`            }`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`            // Process normal content`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`            const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` content`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` parsed`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`choices`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`].`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`delta`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`            if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`              console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`            }`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`          } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`catch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`e`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`            // Ignore parsing errors`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`          }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`        }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`      }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`    }`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`finally`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`    reader`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`cancel`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`  }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})})]})})}),`\n`,_jsx(Heading,{level:`4`,id:`api-specific-behavior`,children:`API-specific behavior`}),`\n`,_jsx(_components.p,{children:`Different API endpoints may handle streaming errors slightly differently:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`OpenAI Chat Completions API`}),`: Returns `,_jsx(_components.code,{children:`ErrorResponse`}),` directly if no chunks were processed, or includes error information in the response if some chunks were processed`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`OpenAI Responses API`}),`: May transform certain error codes (like `,_jsx(_components.code,{children:`context_length_exceeded`}),`) into a successful response with `,_jsx(_components.code,{children:`finish_reason: \"length\"`}),` instead of treating them as errors`]}),`\n`]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{Template,Model,API_KEY_REF,default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}"])</script><script>self.__next_f.push([1,"51:[\"$\",\"$L58\",null,{\"slug\":\"api_reference/streaming\",\"pageMetadata\":\"$46:props:pageMetadata\",\"theme\":\"mint\",\"children\":[\"$\",\"$L59\",null,{\"mdxSource\":{\"compiledSource\":\"$5a\",\"frontmatter\":{},\"scope\":{\"config\":{},\"pageMetadata\":{\"title\":\"Streaming\",\"seoTitle\":\"API Streaming | Real-time Model Responses in OpenRouter\",\"og:site_name\":\"OpenRouter Documentation\",\"og:title\":\"API Streaming - Real-time Model Response Integration\",\"og:description\":\"Learn how to implement streaming responses with OpenRouter's API. Complete guide to Server-Sent Events (SSE) and real-time model outputs.\",\"og:image\":\"https://openrouter.ai/dynamic-og?title=API%20Streaming\u0026description=Real-time%20model%20response%20streaming\",\"og:image:width\":1200,\"og:image:height\":630,\"twitter:card\":\"summary_large_image\",\"twitter:site\":\"@OpenRouter\",\"noindex\":false,\"nofollow\":false,\"icon\":\"bars-staggered\",\"description\":null,\"href\":\"/api_reference/streaming\"}}},\"mdxSourceWithNoJs\":{\"compiledSource\":\"$5b\",\"frontmatter\":{},\"scope\":{\"config\":{},\"pageMetadata\":{\"title\":\"Streaming\",\"seoTitle\":\"API Streaming | Real-time Model Responses in OpenRouter\",\"og:site_name\":\"OpenRouter Documentation\",\"og:title\":\"API Streaming - Real-time Model Response Integration\",\"og:description\":\"Learn how to implement streaming responses with OpenRouter's API. Complete guide to Server-Sent Events (SSE) and real-time model outputs.\",\"og:image\":\"https://openrouter.ai/dynamic-og?title=API%20Streaming\u0026description=Real-time%20model%20response%20streaming\",\"og:image:width\":1200,\"og:image:height\":630,\"twitter:card\":\"summary_large_image\",\"twitter:site\":\"@OpenRouter\",\"noindex\":false,\"nofollow\":false,\"icon\":\"bars-staggered\",\"description\":null,\"href\":\"/api_reference/streaming\"}}},\"displayDomain\":\"openrouter.ai/docs\"}]}]\n"])</script><script type="module" src="https://static.cloudflareinsights.com/beacon.min.js/v31edd6df95cf4e85bb4c19e7a9bdbcba1788362987495" integrity="sha512-iIg7k2xntmwu6/uSb5tpc/hySgZc4eoL31yB29W6tJFo2akwjPWcEqnCEdJvGexCL0KEQwVYv5BlowfhVz26hg==" data-cf-beacon='{"version":"2024.11.0","token":"805cc649ceeb4d638e3690a3ff168bfe","spa":2}' crossorigin="anonymous"></script>
<script>(function(){function c(){var b=a.contentDocument||(a.contentWindow&&a.contentWindow.document);if(b){var d=b.createElement('script');d.innerHTML="window.__CF$cv$params={r:'a363b4e8af082d6a',t:'MTc4ODU5NTI5Mw=='};var a=document.createElement('script');a.src='/cdn-cgi/challenge-platform/scripts/jsd/main.js';document.getElementsByTagName('head')[0].appendChild(a);";b.getElementsByTagName('head')[0].appendChild(d)}}if(document.body){var a=document.createElement('iframe');a.height=1;a.width=1;a.style.position='absolute';a.style.top=0;a.style.left=0;a.style.border='none';a.style.visibility='hidden';document.body.appendChild(a);if('loading'!==document.readyState)c();else if(window.addEventListener)document.addEventListener('DOMContentLoaded',c);else{var e=document.onreadystatechange||function(){};document.onreadystatechange=function(b){e(b);'loading'!==document.readyState&&(document.onreadystatechange=e,c())}}}})();</script></body></html>