Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/forge/proxy/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
)

# Body fields forge owns and reasons about — never go into passthrough.
_FORGE_OWNED = frozenset({"messages", "tools", "stream", "system"})
_FORGE_OWNED = frozenset({"messages", "tools", "stream", "stream_options", "system"})


def _extract_sampling(body: dict[str, Any]) -> dict[str, Any] | None:
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/test_proxy_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,27 @@ async def test_passthrough_carries_unknown_body_fields(self):
}


@pytest.mark.asyncio
async def test_stream_options_excluded_from_passthrough(self):
"""stream_options must not leak into passthrough.

Forge controls streaming independently — when it makes non-streaming
calls to the backend, a leaked stream_options causes validation
errors on strict backends (e.g. vLLM rejects stream_options when
stream is not True).
"""
client = _mock_client(TextResponse(content="ok"))
body = _body(messages=[{"role": "user", "content": "hi"}])
body["stream"] = True
body["stream_options"] = {"include_usage": True}
body["max_tokens"] = 256

await handle_chat_completions(body, client, _context_manager(), max_retries=1)

passthrough = client.send.call_args.kwargs["passthrough"]
assert "stream_options" not in passthrough
assert passthrough == {"model": "test", "max_tokens": 256}

# ── Anthropic protocol routing ───────────────────────────────


Expand Down
Loading