feat: allow OpenRouter pricing API through proxy#61
Conversation
OpenClaw's gateway fetches model pricing from openrouter.ai/api/v1/models to power cost estimation in the UI. The proxy was blocking this because openrouter.ai wasn't in the route allowlist unless the user explicitly configured an OpenRouter credential. - Add builtinPassthroughDomains list with openrouter.ai as a none route - Skip builtin route when user credential already covers the domain - Add TestBuiltinPassthroughDomains with deduplication test - Refactor proxy tests to use findRouteByDomain helper Signed-off-by: Alexey Kazakov <alkazako@redhat.com> Made-with: Cursor
WalkthroughAdds a built-in passthrough domain list (including "openrouter.ai") and ensures those domains are inserted as exact-match proxy routes with Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/controller/claw_proxy_test.go (1)
412-415: Prefer domain lookup over index in empty-credentials builtin test.
cfg.Routes[0]is still order-coupled. UsingfindRouteByDomain(t, cfg.Routes, "openrouter.ai")here would keep this test stable if more builtin domains are added later.As per coding guidelines, "Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/controller/claw_proxy_test.go` around lines 412 - 415, The test currently asserts on cfg.Routes[0] which couples the test to route ordering; replace the index-based checks with a lookup using findRouteByDomain(t, cfg.Routes, "openrouter.ai") to locate the route and then assert that its Domain equals "openrouter.ai" and Injector equals "none" (i.e., use the found route object instead of cfg.Routes[0]); update the two assertions to reference the route returned by findRouteByDomain to make the test stable if builtin domains are reordered or new ones are added.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@internal/controller/claw_proxy_test.go`:
- Around line 412-415: The test currently asserts on cfg.Routes[0] which couples
the test to route ordering; replace the index-based checks with a lookup using
findRouteByDomain(t, cfg.Routes, "openrouter.ai") to locate the route and then
assert that its Domain equals "openrouter.ai" and Injector equals "none" (i.e.,
use the found route object instead of cfg.Routes[0]); update the two assertions
to reference the route returned by findRouteByDomain to make the test stable if
builtin domains are reordered or new ones are added.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 2911f727-ad7f-46c3-a235-f05bba80b29f
📒 Files selected for processing (3)
internal/controller/claw_configmap_test.gointernal/controller/claw_proxy.gointernal/controller/claw_proxy_test.go
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/controller/claw_proxy_test.go (1)
406-415: Consolidate overlapping builtin passthrough assertions.Both subtests validate the same no-credentials
openrouter.ai -> injector nonebehavior. Keeping this in one focused place (TestBuiltinPassthroughDomains) would reduce maintenance noise without losing coverage.As per coding guidelines, "Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity."
Also applies to: 503-512
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/controller/claw_proxy_test.go` around lines 406 - 415, Duplicate subtest asserting the same no-credentials builtin passthrough behavior should be removed and consolidated into the existing TestBuiltinPassthroughDomains test; delete the t.Run block that calls generateProxyConfig(nil) and asserts openrouter.ai injector == "none" (the subtest shown) and instead ensure TestBuiltinPassthroughDomains includes an assertion that, for generateProxyConfig(nil) (or equivalent no-credentials path), the route for "openrouter.ai" returned by findRouteByDomain has Injector == "none" so coverage remains while avoiding duplicate tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@internal/controller/claw_proxy_test.go`:
- Around line 406-415: Duplicate subtest asserting the same no-credentials
builtin passthrough behavior should be removed and consolidated into the
existing TestBuiltinPassthroughDomains test; delete the t.Run block that calls
generateProxyConfig(nil) and asserts openrouter.ai injector == "none" (the
subtest shown) and instead ensure TestBuiltinPassthroughDomains includes an
assertion that, for generateProxyConfig(nil) (or equivalent no-credentials
path), the route for "openrouter.ai" returned by findRouteByDomain has Injector
== "none" so coverage remains while avoiding duplicate tests.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: aae588aa-08a1-4304-bb65-e7b3378b8f7e
📒 Files selected for processing (1)
internal/controller/claw_proxy_test.go
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/controller/claw_proxy_test.go (1)
298-301: Avoid hard-coding global route count/order in non-builtin-focused tests.These assertions are brittle if more built-in passthrough domains are added later. Prefer checking presence and relative ordering constraints only.
♻️ Proposed refactor
@@ - require.Len(t, cfg.Routes, 3) - assert.Equal(t, "api.example.com", cfg.Routes[0].Domain, "exact match should come first") - assert.Equal(t, "openrouter.ai", cfg.Routes[1].Domain, "builtin exact should come before suffix") - assert.Equal(t, ".example.com", cfg.Routes[2].Domain, "suffix match should come last") + domainIndex := map[string]int{} + for i, r := range cfg.Routes { + domainIndex[r.Domain] = i + } + require.Contains(t, domainIndex, "api.example.com") + require.Contains(t, domainIndex, "openrouter.ai") + require.Contains(t, domainIndex, ".example.com") + assert.Less(t, domainIndex["api.example.com"], domainIndex[".example.com"], "exact match should come before suffix") + assert.Less(t, domainIndex["openrouter.ai"], domainIndex[".example.com"], "builtin exact should come before suffix") @@ - require.Len(t, cfg.Routes, 3, "2 credential routes + 1 builtin passthrough") + assert.GreaterOrEqual(t, len(cfg.Routes), 3, "should include credential routes plus builtin passthrough routes") + _ = findRouteByDomain(t, cfg.Routes, "internal.example.com") + _ = findRouteByDomain(t, cfg.Routes, "api.example.com") + _ = findRouteByDomain(t, cfg.Routes, "openrouter.ai")As per coding guidelines, “Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity.”
Also applies to: 403-403
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/controller/claw_proxy_test.go` around lines 298 - 301, The test is brittle due to hard-coding the total route count and exact ordering; instead remove the require.Len(t, cfg.Routes, 3) and replace the exact equality checks with presence and relative-order assertions: verify that "api.example.com", "openrouter.ai" and the suffix ".example.com" appear in cfg.Routes (check cfg.Routes[i].Domain), then assert that the index of "api.example.com" is less than the index of ".example.com" and that the index of "openrouter.ai" is less than the index of ".example.com" (use a small helper to find indexes or loop through cfg.Routes to compare positions). This preserves relative ordering without relying on a fixed total or exact positions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@internal/controller/claw_proxy_test.go`:
- Around line 298-301: The test is brittle due to hard-coding the total route
count and exact ordering; instead remove the require.Len(t, cfg.Routes, 3) and
replace the exact equality checks with presence and relative-order assertions:
verify that "api.example.com", "openrouter.ai" and the suffix ".example.com"
appear in cfg.Routes (check cfg.Routes[i].Domain), then assert that the index of
"api.example.com" is less than the index of ".example.com" and that the index of
"openrouter.ai" is less than the index of ".example.com" (use a small helper to
find indexes or loop through cfg.Routes to compare positions). This preserves
relative ordering without relying on a fixed total or exact positions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 969b4eb9-9a15-402d-9ebc-051972669eba
📒 Files selected for processing (1)
internal/controller/claw_proxy_test.go
OpenClaw's gateway fetches model pricing from openrouter.ai/api/v1/models to power cost estimation in the UI. The proxy was blocking this because openrouter.ai wasn't in the route allowlist unless the user explicitly configured an OpenRouter credential.
Summary by CodeRabbit
New Features
Tests