Skip to content

Accept an OpenRouter key wherever an OpenAI key is required - #477

Merged
gregorybchris merged 10 commits into
mainfrom
chrisg/openrouter-support
Oct 17, 2026
Merged

gregorybchris merged 10 commits into
mainfrom
chrisg/openrouter-support

Conversation

@gregorybchris

@gregorybchris gregorybchris commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Ai2 no longer issues OpenAI API keys. With this change, anything that needs OPENAI_API_KEY also accepts an OpenRouter key in OPENROUTER_API_KEY or OPEN_ROUTER_KEY. When only an OpenRouter key is set, requests go to OpenRouter's OpenAI-compatible endpoint, and OpenAI model names are sent as OpenRouter slugs (gpt-4o becomes openai/gpt-4o). If an OpenAI key is also set, it is used, so existing setups behave the same.

What changed

  • New common/openai_credentials.py. It resolves which key to use and maps model names to OpenRouter slugs. OpenRouter rejects gpt-4-0613 and gpt-5.5-2026-04-23, so these map to the undated slug of the same snapshot (openai/gpt-4, openai/gpt-5.5). o3-mini-2025-01-31 maps to openai/o3-mini the same way.
  • In-process judges. build_openai_judge_fn covers SimpleQA, rubric, safety, HLE, FrontierScience, ResearchQA and citation judges. The vision judges (MathVista, CharXiv, dense caption) use the same helper. Judge caches are still keyed by the OpenAI model name, so existing caches keep working.
  • LiteLLM registry models (gpt-4o, gpt-4o-mini, gpt-4-turbo, o3-mini-…). These are sent as openrouter/openai/<model>, with the key passed explicitly. This applies to both generation and loglikelihood requests. The provider's reported model_name does not change.
    • LiteLLM drops parameters OpenAI rejects only when calling OpenAI's own endpoint, not when calling OpenRouter. On OpenRouter routes, the provider now filters the request against LiteLLM's OpenAI model data.
    • Generation requests always drop logprobs when the model doesn't support them. o3-mini rejects them with a 400. Other parameters are dropped only when drop_params is set.
    • Loglikelihood requests need logprobs, so for such models they fail with a clear error instead of scoring every continuation as zero.
  • Judged tasks added since this PR opened (HLE, MultiChallenge, MT-Bench and Arena-Hard v2.0, all built on JudgedTask) create their judge through build_openai_judge_fn, so they route through OpenRouter with no task-specific changes. MT-Bench's default judge gpt-5.5-2026-04-23 maps to openai/gpt-5.5, MultiChallenge's gpt-4o-2024-08-06 is served under its dated slug, and Arena-Hard's gpt-4.1-2025-04-14 resolves to openai/gpt-4.1.
  • Agent harnesses. get_openai_client() returns an OpenRouter client when the provider routes there, and the openai-agents and OpenHands scaffolds send the mapped model name.
    • The openai-agents harness compacts long histories through OpenAI's responses.compact endpoint. OpenRouter doesn't serve it: a live call returned 404 for both gpt-4.1 and openai/gpt-4.1, while /responses worked with the same key. OpenRouter's docs list only POST /responses. With only an OpenRouter key, the harness now skips compaction and logs a warning. Before, the run failed once compaction triggered.
  • Beaker secrets. A task that requires OPENAI_API_KEY uses {user}_OPENROUTER_API_KEY when {user}_OPENAI_API_KEY does not exist. When neither exists, the error suggests a beaker secret write command for each. ProviderConfig and HarnessConfig secret validation accept the OpenRouter key too, and missing-secret messages and olmo-eval info name both keys.
  • External evals. The sandbox gets the OpenRouter key as both OPENROUTER_API_KEY and OPENAI_API_KEY, and OPENAI_BASE_URL is set to OpenRouter. The OpenAI model names olmo-eval passes in are rewritten: tau2's agent and user LLM, DeepScholar's model under test and judge, and Asta's model under test. DeepScholar's model under test uses the plain slug (openai/gpt-4), because upstream's agentic search passes it to a raw OpenAI client as well as to LiteLLM.
  • 402 responses, which OpenRouter returns when a key is out of credits, are no longer retried. This covers the shared retry helper (LiteLLM models and the HLE and MultiChallenge judges) and CharXiv grading, which before burned every retry and recorded a dummy score.
  • Tests. A test fixture clears OpenRouter keys so a developer's key cannot send unit tests to the live API.
  • README. New section "OpenAI models through OpenRouter".

Live verification against OpenRouter

These runs had only OPEN_ROUTER_KEY set and no OpenAI key.

Path Model sent Result
SimpleQA / safety judge openai/gpt-4o-mini ✓
Default attributed-QA judge openai/gpt-5.5 (medium reasoning) ✓
FrontierScience judge gpt-5.5-2026-04-23 → openai/gpt-5.5 ✓
HLE judge openai/gpt-6-luna ✓
MathVista extraction gpt-4-0613 → openai/gpt-4 ✓
CharXiv grader (JSON mode) openai/gpt-4o-2024-05-13 ✓
Registry gpt-4o-mini, gpt-4o, gpt-4-turbo openrouter/openai/… ✓, logprobs returned
Registry o3-mini-2025-01-31-medium openrouter/openai/o3-mini ✓, logprobs dropped
tau2 / DeepScholar sandbox env (LiteLLM) openrouter/openai/gpt-4o-mini ✓
Plain OpenAI SDK via sandbox OPENAI_BASE_URL (Asta-style) bare gpt-4o-mini ✓

A second round of live checks covered the review fixes:

Path Model sent Result
Harness client from LiteLLMProvider.get_openai_client() openai/gpt-4 (from gpt-4-0613) ✓
DeepScholar model under test via LiteLLM with the sandbox env openai/gpt-4 ✓
DeepScholar model under test via a raw OpenAI client (agentic search) openai/gpt-4 ✓
Top-level reasoning_effort on o3-mini low vs high ✓ 192 vs 1,920 reasoning tokens, so OpenRouter honors it
MultiChallenge default judge openai/gpt-4o-2024-08-06 ✓ served under the exact dated slug, no alias needed
responses.compact (agent compaction) gpt-4.1, openai/gpt-4.1 ✗ 404, so compaction is skipped with only an OpenRouter key

End to end, olmo-eval run -m gpt-4o-mini -t simpleqa:judge -o limit=3 completed 3/3. Both the model and the judge ran through OpenRouter. As a positive control, the SimpleQA judge graded a correct answer 1.0 and a wrong answer 0.0.

Limitations

  • AstaBench hardcodes its scorer models, so olmo-eval cannot rewrite their names. Bare OpenAI names resolve on OpenRouter, but dated snapshots it doesn't list (such as gpt-4-0613) do not. Asta also still requires Anthropic and Google keys.
  • --secret-env overrides still do not satisfy the required-secret check. That was already the case before this PR.

Beaker verification

After the review fixes and merges, one job reran at commit 21f0b34d on 2026-10-16 in the same workspace, again mounting only the OpenRouter secret:

Experiment Setup Result
openrouter-r3-api-models-gpt-4o-mini gpt-4o-mini (LiteLLM) on simpleqa:judge and xstest:openai_judge, 20 each ✓ SimpleQA 0.15, XSTest 0.90. 40 judge calls to OpenRouter, all 200.

The o3-mini and vLLM jobs were not rerun: nothing they exercise changed after the first round, and their judge path is the one the job above covers.

The first round of jobs ran in ai2/olmo-eval-debug at commit 4cb6d4cb on 2026-10-14. The workspace has a chrisg_OPENROUTER_API_KEY secret and no chrisg_OPENAI_API_KEY, so the launcher had to fall back to OpenRouter. Each job mounted only the OpenRouter secret. Every judge request in the logs went to openrouter.ai and returned 200, with no failed requests.

Experiment Setup Result
openrouter-api-models-gpt-4o-mini gpt-4o-mini (LiteLLM) on simpleqa:judge and xstest:openai_judge, 20 each ✓ SimpleQA 0.15, XSTest 0.85. 40 judge calls to OpenRouter.
openrouter-api-models-o3-mini-2025-01-31-medium o3-mini-2025-01-31-medium on the same tasks ✓ SimpleQA 0.15, XSTest 0.95. No logprobs errors.
openrouter-vllm-judges llama3.1-8b-instruct on vLLM (H100), same tasks ✓ SimpleQA 0.05, XSTest 0.90. 40 judge calls to OpenRouter.
openrouter-tau2 tau2_bench airline, 3 tasks, llama3.1-8b-instruct, user LLM gpt-4o-mini ✗ Unrelated to this PR, see below.

The tau2 job failed before tau2 started. The sandbox container exited while bootstrapping SWE-ReX (An executable named swe-rex is not provided by package swe-rex). tau2 uses the default sandbox config without inject_swerex, unlike DeepScholar and SciCode, so it hits the runtime install path that no longer works. This PR doesn't change that code, so tau2 fails the same way on main. As a result, the tau2 and DeepScholar OpenRouter path has only been checked locally (sandbox env and LiteLLM model names, see above).

Not yet tested

  • Full tau2, DeepScholar or Asta runs. tau2 is blocked by the sandbox issue above. DeepScholar needs an OPENALEX_API_KEY secret.
  • The openai-agents and OpenHands harnesses end to end. Their client and model name are covered by unit tests and a live call.

Testing

🤖 Generated with Claude Code

Ai2 no longer issues OpenAI API keys. Anything that needs OPENAI_API_KEY now
also accepts OPENROUTER_API_KEY. When only the OpenRouter key is set, requests
go to OpenRouter's OpenAI-compatible endpoint and OpenAI model names are sent as
OpenRouter slugs. An OpenAI key still wins when both are set.

- Add common/openai_credentials.py to resolve credentials and model names.
- Route the LLM judges, vision judges, and LiteLLM registry models through it.
- Let a {user}_OPENROUTER_API_KEY Beaker secret satisfy an OPENAI_API_KEY
  requirement, and accept it in provider and harness secret validation.
- Export the OpenRouter key to external-eval sandboxes and rewrite the tau2
  and DeepScholar OpenAI model names.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@gregorybchris
gregorybchris requested a review from a team as a code owner October 14, 2026 20:55
- Accept OPEN_ROUTER_KEY as another name for the OpenRouter key.
- Pass the OpenRouter key to LiteLLM explicitly, since LiteLLM only reads
  OPENROUTER_API_KEY from the environment.
- When routing an OpenAI model through OpenRouter, drop request params that
  LiteLLM's OpenAI model data marks unsupported. Logprobs are always dropped
  when unsupported (o3-mini rejects them); other params only with drop_params.
  LiteLLM does this for OpenAI's own endpoint but not for OpenRouter.
- Clear OpenRouter keys in tests so a developer's key cannot reach the live API.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Comment thread src/olmo_eval/launch/beaker/secrets.py Resolved
gregorybchris and others added 8 commits October 15, 2026 14:44
- Apply the OpenRouter overrides and parameter filtering to LiteLLM
  loglikelihood requests, matching the generate path.
- Map DeepScholar's model under test with litellm_model_name so dated
  OpenAI snapshots resolve on OpenRouter.
- Suggest the OpenRouter secret alongside the OpenAI one when a required
  Beaker secret is missing.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
- LiteLLMProvider.get_openai_client returns an OpenRouter client when
  requests are routed there, and the agents and OpenHands scaffolds send
  the mapped model name.
- DeepScholar's model under test uses the OpenRouter slug, which both
  litellm and upstream's raw OpenAI client accept in agentic search.
- Asta passes Inspect an openrouter/<slug> model.
- Loglikelihood requests fail clearly for models without logprobs instead
  of scoring every continuation as zero.
- CharXiv stops retrying on 402, which OpenRouter returns when a key is
  out of credits.
- Missing-secret messages, eval info and docstrings name the OpenRouter
  key alongside the OpenAI key.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…port

# Conflicts:
#	src/olmo_eval/inference/providers/litellm.py
- The openai_agents harness compacts history through OpenAI's
  responses.compact endpoint, which OpenRouter does not serve (it returns
  404). With only an OpenRouter key, the harness now skips compaction and
  logs a warning instead of failing once compaction triggers.
- Treat HTTP 402, which OpenRouter returns when a key is out of credits,
  as non-retryable.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@gregorybchris
gregorybchris merged commit b2ef76d into main Oct 17, 2026
8 checks passed
@gregorybchris
gregorybchris deleted the chrisg/openrouter-support branch October 17, 2026 04:15
gregorybchris added a commit that referenced this pull request Oct 17, 2026
alogprobs now reads _openai_params (added in #477), which __init__ sets.
These tests build the provider with __new__, so set it explicitly.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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.

2 participants