feat: Add anthropic messages api support as a responses_api_model.
What does this PR do ?
Adds a native anthropic_model Responses API model server that translates NeMo Gym requests to Anthropic /v1/messages and maps Anthropic responses back to NeMo Gym Responses API objects.
Issues
Closes #1146
Usage
- Configure
anthropic_modelwith an Anthropic base URL, API key, model name, and max token limit:
ng_run "+config_paths=[responses_api_models/anthropic_model/configs/anthropic_model.yaml,<resources_server_config>.yaml]" \
+policy_base_url=https://api.anthropic.com/v1 \
+policy_api_key="$ANTHROPIC_API_KEY" \
+policy_model_name=claude-opus-4-8
Once the servers are up, direct model-server smoke test:
curl -s http://127.0.0.1:<policy_model_port>/v1/responses \
-H 'Content-Type: application/json' \
-d '{
"input": "Say hello in one short sentence.",
"max_output_tokens": 64
}' | python -m json.tool
Minimal end-to-end smoke test with the example single-tool-call environment:
ng_run "+config_paths=[resources_servers/example_single_tool_call/configs/example_single_tool_call.yaml,responses_api_models/anthropic_model/configs/anthropic_model.yaml]" \
+policy_base_url="$ANTHROPIC_BASE_URL" \
+policy_api_key="$ANTHROPIC_API_KEY" \
+policy_model_name="$ANTHROPIC_MODEL_NAME"
Collect one rollout through the simple agent:
mkdir -p results
ng_collect_rollouts \
+agent_name=example_single_tool_call_simple_agent \
+input_jsonl_fpath=resources_servers/example_single_tool_call/data/example.jsonl \
+output_jsonl_fpath=results/claude_example_single_tool_call_rollouts.jsonl \
+limit=1 \
+num_repeats=1
Additional Information
- Uses raw aiohttp transport through
nemo_gym.server_utils.request()instead of the Anthropic Python SDK. - Supports Responses API text messages, base64 image inputs, system/developer prompt extraction, function tool schemas, previous tool calls/results, Anthropic thinking blocks, usage mapping, and request concurrency limiting.
- Serializes system prompts as Anthropic text blocks, supports typed adaptive thinking config, and keeps
extra_bodyfor less common Anthropic pass-through fields. - Maps Responses
input_imagedata URLs to Anthropicimageblocks forimage/jpeg,image/png,image/gif, andimage/webp; remote image URLs and invalid base64 are rejected with clear 400 errors. - Maps Anthropic stop reasons to Responses-compatible
incomplete_details:max_tokensandmodel_context_window_exceededbecomemax_output_tokens;refusalbecomescontent_filter. - Fails fast for Claude Opus 4.7/4.8 sampling restrictions when
temperature,top_p, ortop_kare explicitly configured. - Adds mocked tests for Anthropic request shape, response conversion, tool use round trips, image conversion/validation, thinking/reasoning mapping, refusal/stop-reason mapping, sampling validation, and semaphore behavior.
- Verified with:
uv run ruff format responses_api_models/anthropic_modeluv run ruff check responses_api_models/anthropic_modeluv run pytest responses_api_models/anthropic_model/tests/test_app.py -q
This pull request requires additional validation before any workflows can run on NVIDIA's runners.
Pull request vetters can view their responsibilities here.
Contributors can view more details about this message here.
did you test with claude_code_agent and would you mind updating that agent instructions to use this if so?
So, this PR only implements the ResponsesAPI <--> Anthropic Messages. I think what you mean by this question is the other direction of translation that would allow Anthropic Messages <--> ResponsesAPI could be handled in a different Issue and PR.
:herb: Preview your docs: https://nvidia-preview-ffrujeri-claude-model-support.docs.buildwithfern.com/nemo/gym
Here are the markdown pages you've updated: