<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Model Routing on KnightLi Blog</title>
        <link>https://knightli.com/en/tags/model-routing/</link>
        <description>Recent content in Model Routing on KnightLi Blog</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>en</language>
        <lastBuildDate>Sat, 11 Jul 2026 11:00:00 +0800</lastBuildDate><atom:link href="https://knightli.com/en/tags/model-routing/index.xml" rel="self" type="application/rss+xml" /><item>
        <title>9Router Claude Code Setup: API Base URL, Model Routing, and Common Errors</title>
        <link>https://knightli.com/en/2026/07/11/9router-claude-code-api-base-url-routing-errors/</link>
        <pubDate>Sat, 11 Jul 2026 11:00:00 +0800</pubDate>
        
        <guid>https://knightli.com/en/2026/07/11/9router-claude-code-api-base-url-routing-errors/</guid>
        <description>&lt;p&gt;Connecting Claude Code to 9Router is not just a matter of pasting a configuration snippet. The client, 9Router Provider, and target model names must agree. When you see a 401, 404, or “model unavailable” error, isolate the layer first instead of repeatedly changing API keys.&lt;/p&gt;
&lt;h2 id=&#34;confirm-three-things-before-configuring&#34;&gt;Confirm three things before configuring
&lt;/h2&gt;&lt;ol&gt;
&lt;li&gt;The 9Router service is running and its local management UI opens.&lt;/li&gt;
&lt;li&gt;A Provider has been added in 9Router, with a working key and connectivity.&lt;/li&gt;
&lt;li&gt;You have the OpenAI-compatible Base URL, API key, and available model or Combo names exposed by 9Router.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Claude Code should call only 9Router’s Base URL. 9Router should decide the Provider and model through its routing rules. For installation and background, see the &lt;a class=&#34;link&#34; href=&#34;https://knightli.com/en/2026/05/08/9router-ai-coding-router-token-saver/&#34; &gt;9Router guide&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;recommended-connection-order&#34;&gt;Recommended connection order
&lt;/h2&gt;&lt;p&gt;Create a test route in 9Router with one Provider only, then point Claude Code at it. After a simple conversation works, add fallback, multiple accounts, or local models.&lt;/p&gt;
&lt;p&gt;Check these details:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The Base URL is 9Router’s OpenAI-compatible endpoint, not an upstream vendor URL.&lt;/li&gt;
&lt;li&gt;The API key was issued by the current 9Router instance.&lt;/li&gt;
&lt;li&gt;The model name in Claude Code exactly matches a model or Combo exposed by 9Router.&lt;/li&gt;
&lt;li&gt;Terminals and Claude Code have been restarted after changing environment variables or configuration.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Do not scatter upstream Provider keys across project configurations. Keep them in 9Router and let Claude Code store only the minimum credentials needed for the local router; revocation and migration become easier.&lt;/p&gt;
&lt;h2 id=&#34;troubleshooting-common-errors&#34;&gt;Troubleshooting common errors
&lt;/h2&gt;&lt;h3 id=&#34;401-or-unauthorized&#34;&gt;401 or Unauthorized
&lt;/h3&gt;&lt;p&gt;First verify that the request reaches local 9Router, then check the API key. If the management UI works but the client still gets a 401, the client is often using the wrong key or pointing at another instance.&lt;/p&gt;
&lt;h3 id=&#34;404-or-endpoint-not-found&#34;&gt;404 or endpoint not found
&lt;/h3&gt;&lt;p&gt;This usually means the Base URL has an extra or missing path segment. Do not guess whether to append &lt;code&gt;/v1&lt;/code&gt;; use the OpenAI-compatible address currently shown by 9Router and verify it with the simplest possible request.&lt;/p&gt;
&lt;h3 id=&#34;model-not-found&#34;&gt;model not found
&lt;/h3&gt;&lt;p&gt;Check the model list in 9Router. An upstream model name, a custom alias, and a Combo name may all differ. Claude Code must use the name exposed by the router.&lt;/p&gt;
&lt;h3 id=&#34;requests-work-but-always-fall-back&#34;&gt;Requests work but always fall back
&lt;/h3&gt;&lt;p&gt;Check the first-choice Provider’s status, balance or quota, model permission, and request logs. Fallback is a safety net, not a replacement for fixing why the preferred model fails.&lt;/p&gt;
&lt;h2 id=&#34;keep-a-minimal-test-configuration&#34;&gt;Keep a minimal test configuration
&lt;/h2&gt;&lt;p&gt;Before deploying complex routing, keep a baseline with one Provider, one model, and no fallback. When something breaks, return to it first: a working baseline points to routing rules; a failing baseline points to networking, credentials, or the Provider.&lt;/p&gt;
&lt;p&gt;For Claude Code installation, permissions, or project-environment issues, see &lt;a class=&#34;link&#34; href=&#34;https://knightli.com/en/2026/07/08/claude-code-multi-project-memory-team-workflow/&#34; &gt;Claude Code project memory and Hooks&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;summary&#34;&gt;Summary
&lt;/h2&gt;&lt;p&gt;The core setup is simple: point the Base URL at the router, match the router’s model name, and keep upstream logic in the router. Check connectivity, authentication, model name, and routing rules in that order.&lt;/p&gt;
&lt;h2 id=&#34;a-configuration-model-that-is-easy-to-debug&#34;&gt;A configuration model that is easy to debug
&lt;/h2&gt;&lt;p&gt;Think of the request chain as four layers: &lt;code&gt;Claude Code → 9Router endpoint → Provider → actual model&lt;/code&gt;. Each layer answers one question: did the client reach the router, did the router accept credentials, did a rule select a Provider, and can that Provider call the model? Keep tests and logs separated by these layers.&lt;/p&gt;
&lt;p&gt;For example, begin with one fixed model name in Claude Code and map it to a single Provider in 9Router. Once that is stable, turn the name into a Combo and add a second Provider. Avoid exposing many upstream names directly to Claude Code, or every project will accumulate its own hard-to-maintain configuration.&lt;/p&gt;
&lt;h2 id=&#34;validate-with-a-minimal-request-not-a-long-task&#34;&gt;Validate with a minimal request, not a long task
&lt;/h2&gt;&lt;p&gt;After each layer is configured, run a low-cost test:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Use 9Router health information or its management UI to confirm the service is listening.&lt;/li&gt;
&lt;li&gt;Send a simple request without tool calls to verify the API key and model name.&lt;/li&gt;
&lt;li&gt;Ask Claude Code to explain a small piece of text in the current directory.&lt;/li&gt;
&lt;li&gt;Only then test file access, test execution, long contexts, or parallel Agents.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Long tasks add networking, tool permissions, context, and retry variables. Save a minimal request in your troubleshooting notes so it can be reused after an upgrade or on another machine.&lt;/p&gt;
&lt;h2 id=&#34;designing-stable-routing-rules&#34;&gt;Designing stable routing rules
&lt;/h2&gt;&lt;p&gt;Separate a default model from a high-cost model. Use the default for routine questions, formatting, and low-risk changes; explicitly choose the stronger model for complex reasoning, code review, or long context. This makes spending easier to understand and shows which work actually merits an upgrade.&lt;/p&gt;
&lt;p&gt;Be conservative about fallback triggers. Network errors, explicit quota errors, and Provider outages can justify a switch; an unsatisfying answer should not automatically retry several Providers. That multiplies token use and makes output hard to reproduce.&lt;/p&gt;
&lt;h2 id=&#34;deployment-and-credential-security-checklist&#34;&gt;Deployment and credential security checklist
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;Do not expose 9Router on a public address without access controls.&lt;/li&gt;
&lt;li&gt;Treat &lt;code&gt;DATA_DIR&lt;/code&gt;, backups, and logs as sensitive because they may contain Provider information.&lt;/li&gt;
&lt;li&gt;Never put upstream keys in repositories, screenshots, or Claude Code project instructions.&lt;/li&gt;
&lt;li&gt;Back up before upgrading; test with a minimal request before restoring production routes.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;faq-do-i-need-to-configure-9router-in-every-project&#34;&gt;FAQ: Do I need to configure 9Router in every project?
&lt;/h3&gt;&lt;p&gt;Usually no. A client-level environment variable or management tool can reuse one endpoint across projects. Project-level configuration is useful only when a repository truly requires a dedicated model, permissions, or billing isolation.&lt;/p&gt;
&lt;h3 id=&#34;faq-why-does-a-local-model-fall-back-so-often&#34;&gt;FAQ: Why does a local model fall back so often?
&lt;/h3&gt;&lt;p&gt;Check service logs for out-of-memory conditions, context limits, concurrency queues, or a model-name mismatch. Validate a local model repeatedly with real task lengths before making it the primary route.&lt;/p&gt;
</description>
        </item>
        
    </channel>
</rss>
