Skip to content

fix: added claude haiku support in backend rust#7188

Open
shodown96 wants to merge 2 commits intoBasedHardware:mainfrom
shodown96:add-haiku-model-support
Open

fix: added claude haiku support in backend rust#7188
shodown96 wants to merge 2 commits intoBasedHardware:mainfrom
shodown96:add-haiku-model-support

Conversation

@shodown96
Copy link
Copy Markdown

@shodown96 shodown96 commented May 6, 2026

Add claude-haiku-4-5-20251001 support to desktop Rust backend

The Swift desktop app sends claude-haiku-4-5-20251001 to /v2/chat/completions, but the model was absent from MODEL_ROUTES, causing resolve_model() to return None and the proxy to reject every request with a 400 Bad Request. The backend log shows:

chat_completions: unknown model 'claude-haiku-4-5-20251001' from user <uid>

Changes

  • desktop/Backend-Rust/src/models/chat_completions.rs - added omi-haiku and claude-haiku-4-5-20251001 entries to MODEL_ROUTES
  • desktop/Backend-Rust/src/routes/chat_completions.rs - added Haiku pricing to model_cost(), added a dedicated test_resolve_model_haiku test (matching the pattern of test_resolve_model_sonnet and test_resolve_model_opus), and removed omi-haiku from test_resolve_model_unknown where it didn't belong

Note on the test changes

test_resolve_model_unknown previously included assert!(resolve_model("omi-haiku").is_none()). Rather than flipping that assertion to is_some() (which would be semantically wrong in a test called unknown), I removed it from that test entirely and added a proper dedicated test with full public_model, upstream_model, and provider assertions. My read is the omi-haiku line was added there simply because Haiku wasn't implemented yet, if it was deliberately excluded, I'd be happy to revert.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 6, 2026

Greptile Summary

This PR fixes a 400 Bad Request error on /v2/chat/completions by registering claude-haiku-4-5-20251001 (and the omi-haiku alias) in MODEL_ROUTES and adding the corresponding per-token pricing to model_cost().

  • models/chat_completions.rs — two new ModelRoute entries (omi-haikuclaude-haiku-4-5-20251001 and the direct pass-through); remaining diff is formatting-only.
  • routes/chat_completions.rs — Haiku pricing added ($0.80/$4.00/$0.08/$1.00 per MTok for input/output/cache-read/cache-write); test_resolve_model_unknown updated to assert omi-haiku now resolves to Some, but the assertion is misplaced — it belongs in a dedicated known-model test with a stronger upstream-model check.

Confidence Score: 4/5

Safe to merge — the core fix (model routing and pricing) is correct and the only concern is a test assertion placed in the wrong test function.

The model route entries and pricing values look correct. The one rough edge is that the omi-haiku assertion was dropped into test_resolve_model_unknown rather than a dedicated test, and it does not verify the upstream_model value the way every other route test does — so a future regression would go undetected.

The test block in desktop/Backend-Rust/src/routes/chat_completions.rs around test_resolve_model_unknown deserves a second look to verify the assertion is moved and strengthened before merging.

Important Files Changed

Filename Overview
desktop/Backend-Rust/src/models/chat_completions.rs Adds omi-haiku and claude-haiku-4-5-20251001 entries to MODEL_ROUTES; remaining diff is pure formatting (brace-on-same-line and line-wrap cleanup) with no logic change.
desktop/Backend-Rust/src/routes/chat_completions.rs Adds Haiku pricing to model_cost() (correct per-token values) and moves an omi-haiku assertion into the wrong test (test_resolve_model_unknown), where it contradicts the test's purpose.

Sequence Diagram

sequenceDiagram
    participant App as Swift Desktop App
    participant Proxy as Rust Proxy /v2/chat/completions
    participant Resolver as resolve_model()
    participant Cost as model_cost()
    participant Anthropic as Anthropic API

    App->>Proxy: POST /v2/chat/completions {model: "claude-haiku-4-5-20251001"}
    Proxy->>Resolver: resolve_model("claude-haiku-4-5-20251001")
    note over Resolver: Scans MODEL_ROUTES (new entry added by this PR)
    Resolver-->>Proxy: Some(ModelRoute { upstream: "claude-haiku-4-5-20251001" })
    Proxy->>Anthropic: Forward request with upstream model
    Anthropic-->>Proxy: Response + usage tokens
    Proxy->>Cost: model_cost("claude-haiku-4-5-20251001")
    note over Cost: $0.80/$4.00/$0.08/$1.00 per MTok
    Cost-->>Proxy: ModelCost
    Proxy-->>App: OpenAI-format response
Loading

Comments Outside Diff (1)

  1. desktop/Backend-Rust/src/routes/chat_completions.rs, line 953-958 (link)

    P2 The is_some() assertion for omi-haiku is misplaced inside test_resolve_model_unknown, which is designed exclusively to verify that unrecognised model strings return None. Placing a known-model assertion here makes the test name actively misleading. The haiku assertion should also mirror how other model tests are written — verifying the concrete upstream_model value rather than just checking that resolution succeeds. The existing test_resolve_model_known_models or a new dedicated test is a better home for this.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Reviews (1): Last reviewed commit: "fix: added claude haiku support in backe..." | Re-trigger Greptile

@shodown96
Copy link
Copy Markdown
Author

Updated the PR in response to Greptile's concerns

Changes

  • desktop/Backend-Rust/src/models/chat_completions.rs - added omi-haiku and claude-haiku-4-5-20251001 entries to MODEL_ROUTES
  • desktop/Backend-Rust/src/routes/chat_completions.rs - added Haiku pricing to model_cost(), added a dedicated test_resolve_model_haiku test (matching the pattern of test_resolve_model_sonnet and test_resolve_model_opus), and removed omi-haiku from test_resolve_model_unknown where it didn't belong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant