Guillaume Salou commited on
feat: route Claude via Bedrock inference profile (#82)
Browse filesSwitch the Claude endpoint IDs from the direct Anthropic API to the US
cross-region inference profile. Extend the model-provider substring
check so both prefixes keep hitting the HF-org gate, the daily Claude
quota, and prompt caching.
Files changed (7)
23 unmodified lines242526272829303123 unmodified lines# ":cheapest" / ":preferred" / ":<provider>" to override the default# routing policy (auto = fastest with failover).SUGGESTED_MODELS = [{"id": "anthropic/claude-opus-4-7", "label": "Claude Opus 4.7"},{"id": "anthropic/claude-opus-4-6", "label": "Claude Opus 4.6"},{"id": "MiniMaxAI/MiniMax-M2.7", "label": "MiniMax M2.7"},{"id": "moonshotai/Kimi-K2.6", "label": "Kimi K2.6"},{"id": "zai-org/GLM-5.1", "label": "GLM 5.1"},23 unmodified lines242526272829303123 unmodified lines# ":cheapest" / ":preferred" / ":<provider>" to override the default# routing policy (auto = fastest with failover).SUGGESTED_MODELS = [{"id": "bedrock/us.anthropic.claude-opus-4-7", "label": "Claude Opus 4.7"},{"id": "bedrock/us.anthropic.claude-opus-4-6-v1", "label": "Claude Opus 4.6"},{"id": "MiniMaxAI/MiniMax-M2.7", "label": "MiniMax M2.7"},{"id": "moonshotai/Kimi-K2.6", "label": "Kimi K2.6"},{"id": "zai-org/GLM-5.1", "label": "GLM 5.1"},
27 unmodified lines2829303132333427 unmodified linesthat share the underlying ``ContextManager.items`` list don't see theirpersisted history rewritten."""if not model_name or not model_name.startswith("anthropic/"):return messages, toolsif tools:27 unmodified lines2829303132333427 unmodified linesthat share the underlying ``ContextManager.items`` list don't see theirpersisted history rewritten."""if not model_name or "anthropic" not in model_name:return messages, toolsif tools:
94 unmodified lines959697989910010194 unmodified linesself.event_queue = event_queueself.session_id = str(uuid.uuid4())self.config = config or Config(model_name="anthropic/claude-sonnet-4-5-20250929",)self.is_running = Trueself._cancelled = asyncio.Event()94 unmodified lines959697989910010194 unmodified linesself.event_queue = event_queueself.session_id = str(uuid.uuid4())self.config = config or Config(model_name="bedrock/us.anthropic.claude-sonnet-4-5-20250929-v1:0",)self.is_running = Trueself._cancelled = asyncio.Event()
215 unmodified lines216217218219220221222223215 unmodified linesdef _get_research_model(main_model: str) -> str:"""Pick a cheaper model for research based on the main model."""if "anthropic/" in main_model:return "anthropic/claude-sonnet-4-6"# For non-Anthropic models (HF router etc.), use the same modelreturn main_model215 unmodified lines216217218219220221222223215 unmodified linesdef _get_research_model(main_model: str) -> str:"""Pick a cheaper model for research based on the main model."""if "anthropic" in main_model:return "bedrock/us.anthropic.claude-sonnet-4-6"# For non-Anthropic models (HF router etc.), use the same modelreturn main_model
98 unmodified lines9910010110210310410598 unmodified lines_console.file.write("\033[2J\033[H")_console.file.flush()model_label = model or "anthropic/claude-opus-4-6"user_label = hf_user or "not logged in"# Warm gold palette matching the shimmer highlight (255, 200, 80)98 unmodified lines9910010110210310410598 unmodified lines_console.file.write("\033[2J\033[H")_console.file.flush()model_label = model or "bedrock/us.anthropic.claude-opus-4-6-v1"user_label = hf_user or "not logged in"# Warm gold palette matching the shimmer highlight (255, 200, 80)
46 unmodified lines4748495051525314 unmodified lines686970717273747576777879808182838425 unmodified lines11011111211311411511646 unmodified lines"recommended": True,},{"id": "anthropic/claude-opus-4-6","label": "Claude Opus 4.6","provider": "anthropic","tier": "pro",14 unmodified lines]async def _require_hf_for_anthropic(request: Request, model_id: str) -> None:"""403 if a non-``huggingface``-org user tries to select an Anthropic model.Anthropic models are billed to the Space's ``ANTHROPIC_API_KEY``; everyother model in ``AVAILABLE_MODELS`` is routed through HF Router andbilled via ``X-HF-Bill-To``. The gate only fires for ``anthropic/*`` sonon-HF users can still freely switch between the free models.Pattern: https://github.com/huggingface/ml-intern/pull/63"""if not model_id.startswith("anthropic/"):returnif not await require_huggingface_org_member(request):raise HTTPException(25 unmodified linesif agent_session.claude_counted:returnmodel_name = agent_session.session.config.model_nameif not model_name.startswith("anthropic/"):returnuser_id = user["user_id"]used = await user_quotas.get_claude_used_today(user_id)46 unmodified lines4748495051525314 unmodified lines68697071727374757677787980818283848586878825 unmodified lines11411511611711811912046 unmodified lines"recommended": True,},{"id": "bedrock/us.anthropic.claude-opus-4-6-v1","label": "Claude Opus 4.6","provider": "anthropic","tier": "pro",14 unmodified lines]def _is_anthropic_model(model_id: str) -> bool:return "anthropic" in model_idasync def _require_hf_for_anthropic(request: Request, model_id: str) -> None:"""403 if a non-``huggingface``-org user tries to select an Anthropic model.Anthropic models are billed to the Space's ``ANTHROPIC_API_KEY``; everyother model in ``AVAILABLE_MODELS`` is routed through HF Router andbilled via ``X-HF-Bill-To``. The gate only fires for Anthropic sonon-HF users can still freely switch between the free models.Pattern: https://github.com/huggingface/ml-intern/pull/63"""if not _is_anthropic_model(model_id):returnif not await require_huggingface_org_member(request):raise HTTPException(25 unmodified linesif agent_session.claude_counted:returnmodel_name = agent_session.session.config.model_nameif not _is_anthropic_model(model_name):returnuser_id = user["user_id"]used = await user_quotas.get_claude_used_today(user_id)
12345{"model_name": "anthropic/claude-opus-4-6","save_sessions": true,"session_dataset_repo": "akseljoonas/hf-agent-sessions","yolo_mode": false,12345{"model_name": "bedrock/us.anthropic.claude-opus-4-6-v1","save_sessions": true,"session_dataset_repo": "akseljoonas/hf-agent-sessions","yolo_mode": false,
agent/core/model_switcher.py+2-2
agent/core/prompt_caching.py+1-1
agent/core/session.py+1-1
agent/tools/research_tool.py+2-2
agent/utils/terminal_display.py+1-1
backend/routes/agent.py+8-4
configs/main_agent_config.json+1-1