feat: add support for llm gateways#189
Open
nivye wants to merge 2 commits into
Open
Conversation
8a9e650 to
3847dfc
Compare
# Conflicts: # docs/pages/deploying-in-production.mdx # services/api/api/tool_manager.py # services/api/tests/test_tool_manager.py
|
We could make use of this PR. Question though, can we allow http to a local litellm? We can do some sort of TLS termination between ironproxy and litellm if we must, but it needs custom self signed CA certs etc. and idk if its meaningfully more secure in a local context. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds opt-in support for routing harness LLM traffic through an LLM gateway (e.g. LiteLLM, Portkey, self-hosted) instead of directly to provider APIs. Activated by a single environment variable — when unset, behavior is unchanged.
The gateway is expected to be Anthropic- and/or OpenAI-API-compatible (LiteLLM, Portkey, custom). Operators put the gateway's API key under the existing
ANTHROPIC_API_KEY/OPENAI_API_KEYsecret slot — iron-proxy still injects it into the same headers (X-Api-Key/Authorization), it just does so for the gateway host instead of the provider host. No new secret types, no new injection paths.Motivation
Enterprises routinely standardize on an LLM gateway for centralized cost accounting, audit logging, key rotation, model fallback, and policy enforcement. For those environments, any service that calls
api.openai.comorapi.anthropic.comdirectly is a blocker on installation. Today the host allowlist that iron-proxy uses for credential injection is hardcoded in_INFRA_SECRETS(services/api/api/tool_manager.py), so there is no supported way to point Centaur at a gateway.Approach
ToolManager._INFRA_SECRETSwas aClassVarliteral. This PR converts it to a method,_infra_secrets(), that readsCENTAUR_LLM_GATEWAY_HOSTand substitutes it into the host tuple forANTHROPIC_API_KEYandOPENAI_API_KEYwhen set. Everything else (other provider keys, GitHub, Slack) is unchanged.collect_secrets()— the single call site — now invokes the method. The downstreamproxy_config.pyrendering and iron-proxysecretstransform are untouched.The env var is read with
os.getenv(...)inline, matching how other config knobs are read elsewhere in the same file (TOOL_BINARY_INLINE_MAX_BYTES,TOOL_CALL_TIMEOUT_S, etc.).Replacement, not addition
When
CENTAUR_LLM_GATEWAY_HOSTis set the provider host is replaced rather than appended. Rationale: if an operator has explicitly configured a gateway, they almost certainly want all LLM traffic to route through it — not "also allow direct calls". Replacement also narrows the surface where the gateway key gets injected, which is the safer default.Testing
services/api/tests/test_tool_manager.py:test_infra_secrets_default_to_provider_hosts— env var unset → original behavior preserved.test_infra_secrets_route_llm_keys_through_gateway_host— env var set → Anthropic + OpenAI keys route to the gateway host.CENTAUR_LLM_GATEWAY_HOST=<gateway-host>on the API container, setANTHROPIC_BASE_URL=https://<gateway-host>on the sandbox viasandbox.extraEnv, store the LiteLLM key in theANTHROPIC_API_KEYsecret slot."Reply with PONG".POST /v1/messagesto the gateway host, status 200,secrets.swapped: ANTHROPIC_API_KEY in header X-Api-Key. Result text:"PONG".Compatibility
CENTAUR_LLM_GATEWAY_HOSTis unset,_infra_secrets()returns the exact same list_INFRA_SECRETSdid. Any deployment that doesn't opt in sees no behavior change.HttpSecret), injection mechanism, and iron-proxy config rendering are untouched.Files changed
services/api/api/tool_manager.py_INFRA_SECRETSClassVar →_infra_secrets()method; readsCENTAUR_LLM_GATEWAY_HOST; removed now-unusedClassVarimport.services/api/tests/test_tool_manager.pydocs/pages/deploying-in-production.mdx