Skip to content

feat: implement Rust proxy gateway for vLLM Responses API - #24

Merged
maralbahari merged 9 commits into
vllm-project:mainfrom
leseb:building-the-agentic-api-in-rust-after-project-mig
May 26, 2026
Merged

maralbahari merged 9 commits into
vllm-project:mainfrom
leseb:building-the-agentic-api-in-rust-after-project-mig

Conversation

@leseb

@leseb leseb commented May 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Implements the full Rust proxy gateway for the vLLM Responses API, replacing the Python gateway stub
  • Supports both streaming (SSE) and non-streaming proxy modes with proper hop-by-hop header filtering
  • Includes API key injection from environment, comprehensive error mapping (502 for connection errors, 504 for timeouts), and CORS support
  • Adds CLI with two modes: standalone (--llm-api-base) and integrated (serve <model> spawning vLLM as a subprocess)
  • Modular architecture: config, proxy, app, server modules with a clean separation of concerns

Test Plan

  • 11 tests covering: non-stream passthrough, stream passthrough, hop-by-hop header stripping, auth injection, client auth precedence, upstream HTTP error passthrough, mid-stream failure handling, connection error → 502, timeout → 504
  • All tests pass: cargo test (11/11 green)
  • Clippy clean: cargo clippy --all-targets -- -D warnings
  • Formatting clean: cargo fmt -- --check

🤖 Generated with Claude Code

Replaces the Python gateway stub with a full Rust implementation
using axum, reqwest, and tokio. Supports both streaming (SSE) and
non-streaming proxy modes, hop-by-hop header filtering, API key
injection, and comprehensive error mapping (502/504).

Includes 11 tests covering passthrough, auth, streaming, error
propagation, mid-stream failure, connection errors, and timeouts.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Signed-off-by: Sébastien Han <[email protected]>
Comment thread src/main.rs Resolved
Comment thread src/config.rs Resolved
Derive clap::Args on RuntimeConfig directly and use #[arg(skip)] for
llm_api_base, eliminating the duplicate GatewayOpts struct and the
manual build_config mapping function.

Addresses review feedback from @maralbahari.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Signed-off-by: Sébastien Han <[email protected]>
@maralbahari

Copy link
Copy Markdown
Collaborator

@leseb I was wondering if we should validate that the library choices are optimal and verify stateless proxy throughput/latency against the Python baseline. When I was working on translating Python to Rust, I noticed some performance regression compared to the Python baseline, so I thought it would be best to try and avoid such regressions from the start.

Introduces a proper Error enum via thiserror, replacing
Box<dyn std::error::Error> across the library. ProxyState::new now
returns Result instead of panicking on HTTP client build failure.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Signed-off-by: Sébastien Han <[email protected]>
@leseb

leseb commented May 13, 2026

Copy link
Copy Markdown
Collaborator Author

@leseb I was wondering if we should validate that the library choices are optimal and verify stateless proxy throughput/latency against the Python baseline. When I was working on translating Python to Rust, I noticed some performance regression compared to the Python baseline, so I thought it would be best to try and avoid such regressions from the start.

Can you share more? I'll add a criterion benchmarks

Measures proxy latency overhead by comparing direct upstream requests
against proxied requests for both non-streaming and streaming (SSE)
paths. Establishes a baseline for regression detection.

Results on Apple M-series:
  non_stream/direct:  ~65 µs
  non_stream/proxied: ~133 µs  (68 µs overhead)
  stream/direct:      ~91 µs
  stream/proxied:     ~462 µs  (371 µs overhead)

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Signed-off-by: Sébastien Han <[email protected]>
@leseb
leseb marked this pull request as ready for review May 13, 2026 14:42
leseb and others added 3 commits May 13, 2026 16:49
Replaces generic "upstream" terminology with "vllm" to make it
clear what the gateway is proxying to. Affects config fields,
error variants, function names, variables, and test helpers.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Signed-off-by: Sébastien Han <[email protected]>
@leseb

leseb commented May 19, 2026

Copy link
Copy Markdown
Collaborator Author

@maralbahari any thoughts here?

leseb added a commit to leseb/agentic-api that referenced this pull request May 19, 2026
Captures the three-layer crate design (core library, axum server,
thin gateway adapters) and key architectural decisions:

- Agentic loop as explicit state machine, not proxy filters
- No Python (OGX) in core request paths
- Praxis routes to agentic-api as a backend service
- Standalone mode is first-class
- Gateway adapters are thin (one filter per gateway)

Shapes PR vllm-project#24 as the foundation for agentic-core/agentic-server.
Supersedes PR vllm-project#27's filter-based decomposition approach.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Signed-off-by: Sébastien Han <[email protected]>
@leseb
leseb force-pushed the building-the-agentic-api-in-rust-after-project-mig branch from 1cff48f to a1ebe54 Compare May 19, 2026 09:54
leseb added a commit to leseb/agentic-api that referenced this pull request May 19, 2026
- Add note about superseding ADR-01 language decision (D3)
- Remove axum from Layer 3 diagram (it belongs in Layer 2)
- Soften PR vllm-project#27 language to "if accepted"
- Clarify PR vllm-project#24 relationship as forward-looking

Signed-off-by: Sébastien Han <[email protected]>
Comment thread tests/common/mod.rs Outdated
use agentic_api::config::RuntimeConfig;
use agentic_api::proxy::ProxyState;

pub fn test_config(vllm_url: &str) -> RuntimeConfig {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after reading the official rust documentation examples. The isolated unit tests that are verifying a single module in this case the RuntimeConfig struct in config we should implement the test into the same file as source code in src/config.rs so the test_config_no_key() and test_config cases should move there. you can look at the example here from documentation.

while the tests/ folder is used for integration tests where you would need to test multiple modules relying on each other for an integration case. and test/common/mod.rs use to keep the common setup in this file
like make_runtime_config() make_response_handler(). but I think for this proxy feature we don't need a integration tests as proxy is the single module.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair point, i'll remove the integration tests since it's too much of mocking anyways and not using a real vllm server, i'll add more unit tests

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in a408086

leseb and others added 2 commits May 26, 2026 10:46
Replaces the integration test harness (fake axum servers, TCP
listeners, full HTTP round-trips) with direct unit tests on the
proxy functions: header filtering, auth injection, SSE detection.

Tests the same logic without the overhead of spawning servers
and making real HTTP calls against mocks.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Signed-off-by: Sébastien Han <[email protected]>
@leseb

leseb commented May 26, 2026

Copy link
Copy Markdown
Collaborator Author

Test plan:

Run vLLM:

podman run -d --name vllm \
    -p 8000:8000 \
    -v ~/.cache:/root/.cache \
    -e VLLM_CPU_KVCACHE_SPACE=2 \
    public.ecr.aws/q9t5s3a7/vllm-arm64-cpu-release-repo:latest \
    --host 0.0.0.0 \
    --model Qwen/Qwen3-0.6B \
    --max-model-len 4096 \
    --served-model-name Qwen/Qwen3-0.6B \
    --enable-auto-tool-choice \
    --tool-call-parser hermes

Check it's healthy:

curl -s http://localhost:8000/health 2>&1

Check status code:

curl -s -o /dev/null -w '%{http_code}' http://localhost:8000/health 2>&1
200

Build the project:

cargo build --release

Run it:

./target/release/agentic-api --llm-api-base http://localhost:8000
2026-05-26T09:35:20.424460Z  INFO agentic_api::server: vLLM ready: http://localhost:8000
2026-05-26T09:35:20.425334Z  INFO agentic_api::server: gateway listening on 0.0.0.0:9000

Test a request:

curl -s http://localhost:9000/v1/responses \
  -H "Content-Type: application/json" \
  -d '{"model": "Qwen/Qwen3-0.6B", "input": [{"role": "user", "content": "Count to 3"}], "stream": false}'

{"id":"resp_be8ba46fc00a1a27","created_at":1779788351,"incomplete_details":null,"instructions":null,"metadata":null,"model":"Qwen/Qwen3-0.6B","object":"response","output":[{"id":"msg_9cc874b6892a835a","content":[{"annotations":[],"text":"<think>\nOkay, the user is asking to count to 3. Let me think about how to approach this. First, I need to make sure I understand the request correctly. Counting to 3 is straightforward, but maybe the user is looking for a specific method or a visual representation. Since the user hasn't specified any additional context, I should provide a simple and clear answer.\n\nI should start by explaining what counting to 3 means. It's the sequence 1, 2, 3. Then, I can list the numbers in order. It's important to confirm that the answer is direct and doesn't require any extra information. Also, maybe mention that counting helps in developing number sense. But since the user's query is very direct, keeping it concise is better. Let me check if there's any possible misunderstanding. No, counting to 3 is just 1, 2, 3. So the answer should be straightforward.\n</think>\n\nCount to 3: 1, 2, 3.","type":"output_text","logprobs":null}],"role":"assistant","status":"completed","type":"message"}],"parallel_tool_calls":true,"temperature":0.6,"tool_choice":"auto","tools":[],"top_p":0.95,"background":false,"max_output_tokens":4084,"max_tool_calls":null,"previous_response_id":null,"prompt":null,"reasoning":null,"service_tier":"auto","status":"completed","text":null,"top_logprobs":null,"truncation":"disabled","usage":{"input_tokens":12,"input_tokens_details":{"cached_tokens":0,"input_tokens_per_turn":[],"cached_tokens_per_turn":[]},"output_tokens":210,"output_tokens_details":{"reasoning_tokens":0,"tool_output_tokens":0,"output_tokens_per_turn":[],"tool_output_tokens_per_turn":[]},"total_tokens":222},"user":null,"input_messages":null,"output_messages":null}%

@maralbahari
maralbahari merged commit 1b76182 into vllm-project:main May 26, 2026
3 checks passed
@leseb
leseb deleted the building-the-agentic-api-in-rust-after-project-mig branch May 27, 2026 07:18
franciscojavierarceo pushed a commit that referenced this pull request May 28, 2026
## Summary

Restructures the flat single-crate layout into a Cargo workspace with
three crates per ADR-03:

- **agentic-core**: framework-agnostic library — proxy logic, config,
error types, LLM readiness. No axum/clap/tower dependencies. Exposes
`proxy_request()` as a composable building block.
- **agentic-server**: standalone axum binary — thin handler adapter, CLI
(`clap`), server lifecycle, vLLM subprocess management.
- **agentic-praxis**: stub for future Praxis gateway adapter.

Built on top of PR #24's proxy gateway code (cherry-picked with full
commit history). Renames `vllm_*` identifiers to `llm_*` for
gateway-agnostic naming. Includes improvements to error logging,
multi-value header forwarding, and CLI arg deduplication.

## Test Plan

- `cargo test --workspace` — 16 tests pass (7 unit in agentic-core + 9
integration in agentic-server)
- `cargo clippy --workspace --all-targets -- -D warnings` — clean
- `cargo fmt -- --check` — clean
- `cargo bench -p agentic-server --no-run` — benchmarks compile

---------

Signed-off-by: Sébastien Han <[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.

3 participants