Skip to content

feat: implement dynamic model mapping for Claude background models via configuration overrides #4

Merged
fajarhide merged 2 commits into
mainfrom
fix/invalid-model
Apr 1, 2026
Merged

feat: implement dynamic model mapping for Claude background models via configuration overrides #4
fajarhide merged 2 commits into
mainfrom
fix/invalid-model

Conversation

@fajarhide

@fajarhide fajarhide commented Apr 1, 2026

Copy link
Copy Markdown
Owner

PR Auto Describe

🚀 Summary

Adds configurable per-model mapping for Claude Haiku / Sonnet / Opus requests. Allows users to route Claude Code's hardcoded background calls to cheaper / supported upstream models instead of failing on unrecognised model names. Fully backwards compatible, no changes required for existing deployments.


🔑 Key Changes

✅ 3 new optional environment variables for model alias mapping
✅ Graceful fallback logic preserves existing behaviour
✅ All supporting docs, config, docker and tests updated
✅ Zero breaking changes for existing users


📋 Detailed Breakdown

Build & Ignore

  • Added compiled binary outputs server, heimsense, heimsense_* to .gitignore

Documentation & Config Templates

  • Updated README environment variable table, clarified default model description
  • Added commented example mappings with explanation to env.example
  • Added model mapping template to auto-generated .env on first run
  • Exposed new env vars to container runtime in docker-compose.yaml

Core Implementation

  • Added ModelMapHaiku, ModelMapSonnet, ModelMapOpus fields to root Config struct
  • Implemented normalizeModel() resolution function with strict precedence:
    1. Force model override always takes priority
    2. Match requested model name against haiku/sonnet/opus substrings
    3. Fallback to default custom model if mapping not configured
    4. Final fallback: pass original requested model unmodified
  • Updated ToOpenAIRequest() signature to accept config and return resolution errors
  • Updated all existing unit tests for modified function interface
  • Added proper error handling in request handler, returns clean 400 error for model resolution failures

🧠 Notes

Resolves the very common pain point where Claude Code hardcodes Haiku for background operations, causing 400 errors or unexpected costs for users running against non-Anthropic upstream providers.


⚠️ Breaking Changes

None. All new functionality is optional. All existing configurations and behaviour remain completely unchanged.

@fajarhide fajarhide merged commit cf2c7d6 into main Apr 1, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant