← Back to Pull requests

feat: Pass through /v1/embeddings and serve GET /v1/models/{model}. #430

Merged
Mohammad-nassar10 merged 13 files (545 lines) on Oct 10, 2026 10:58 UTC
View on GitHub
Mohammad-nassar10 Mohammad-nassar10 commented on Oct 10, 2026 00:09 UTC
Author

Summary

First part of #404, the audio routes follow in a separate PR.

  • POST /v1/embeddings is forwarded to the upstream unchanged, through the same pass-through helper as Chat Completions (moved to handler/common.rs so the routes share it).

  • GET /v1/models/{model} returns the matching entry from the upstream /v1/models list. vLLM has no per-model route, so a plain forward would always return 404 (happy to switch if you prefer). Unlisted models get 404 model_not_found, upstream errors are returned unchanged, and IDs containing / work encoded or not.

  • Both routes use the same auth and body-size limit as the other /v1/* routes. README and API docs updated.
  • Test Plan

  • New embeddings_passthrough_test.rs; retrieval tests added to models_test.rs; unit tests for the model lookup.

  • cargo fmt -- --check, cargo clippy --all-targets -- -D warnings and cargo test -p agentic-server pass.
  • Refs #404.

    Diff: 545 lines (+480 / -65) across 13 files Reviewer: franciscojavierarceo Review duration: 648m
    All Vouch review confidence checks passed
    Residual risk 0.09 = Change Risk (0.63) × (1 − Review Confidence (0.86)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.63 · 545 lines diff across 13 files
    0.63
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.81 · 4 substantive comment(s)
    0.81
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    86%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.377
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    7 items
    Copilot Copilot commented on code on Oct 10, 2026 00:15 UTC
    Code Review
    crates/agentic-server/src/handler/http/models.rs:1
    @@ -369,32 +403,87 @@ pub async fn models(State(state): State<AppState>, headers: HeaderMap, Query(par
             return convert_response(upstream);
         }
     
    +    let upstream_bytes = match model_list_body(upstream) {
    +        Ok(bytes) => bytes,
    +        Err(response) => return response,
    +    };
    +
    +    match build_codex_models_response(&upstream_bytes, &state.model_capabilities) {
    +        Ok(response) => axum::Json(response).into_response(),
    +        Err(error) => invalid_model_list(&error),
    +    }
    +}
    +
    +/// GET /v1/models/{model} — one entry of the upstream model list.
    +///
    +/// vLLM serves no per-model route, so the gateway answers from the upstream `/v1/models`
    +/// list instead of forwarding the request: the matching entry is returned unchanged, a model
    +/// the upstream does not list is a 404, and an upstream error is forwarded as is.
    +#[cfg_attr(feature = "openapi", utoipa::path(
    +    get,
    +    path = "/v1/models/{model}",
    +    params(
    +        ("model" = String, Path, description = "Model ID; may contain `/`, encoded or not"),
    +    ),
    +    responses(
    +        (status = 200, description = "The upstream's entry for this model, unchanged"),
    +        (status = 404, description = "The upstream does not list this model", body = crate::openapi::ApiErrorResponse),
    +        (status = 502, description = "Upstream unavailable", body = crate::openapi::ApiErrorResponse),
    +    ),
    +    security(("bearer_auth" = [])),
    +    tag = "models",
    +))]
    +pub async fn retrieve_model(State(state): State<AppState>, headers: HeaderMap, Path(model): Path<String>) -> Response {
    +    let upstream = proxy_get("/v1/models", &headers, &state.proxy_state).await;
    +    let upstream_bytes = match model_list_body(upstream) {
    +        Ok(bytes) => bytes,
    +        Err(response) => return response,
    +    };
    +
    +    match find_upstream_model(&upstream_bytes, &model) {
    +        Ok(Some(entry)) => {
    +            let content_type = [(http::header::CONTENT_TYPE, "application/json")];
    +            (content_type, entry.get().to_owned()).into_response()
    +        }
    +        Ok(None) => convert_response(error_response(
    +            StatusCode::NOT_FOUND,
    +            "model_not_found",
    +            &format!("The model `{model}` does not exist"),
    +        )),
    +        Err(error) => invalid_model_list(&error),
    +    }
    +}

    The successful lookup drops every header from the upstream /v1/models response, including request IDs and rate-limit metadata for the request the gateway just made. This repository’s transformed-response contract preserves those headers while removing stale representation headers (crates/agentic-server-core/src/proxy.rs:181-192). Retain the upstream header map here, remove content-length/content-encoding, and replace content-type for the extracted object.

    Copilot Copilot commented on code on Oct 10, 2026 00:15 UTC
    Code Review
    crates/agentic-server/src/handler/http/models.rs:1
    @@ -369,32 +403,87 @@ pub async fn models(State(state): State<AppState>, headers: HeaderMap, Query(par
             return convert_response(upstream);
         }
     
    +    let upstream_bytes = match model_list_body(upstream) {
    +        Ok(bytes) => bytes,
    +        Err(response) => return response,
    +    };
    +
    +    match build_codex_models_response(&upstream_bytes, &state.model_capabilities) {
    +        Ok(response) => axum::Json(response).into_response(),
    +        Err(error) => invalid_model_list(&error),
    +    }
    +}
    +
    +/// GET /v1/models/{model} — one entry of the upstream model list.
    +///
    +/// vLLM serves no per-model route, so the gateway answers from the upstream `/v1/models`
    +/// list instead of forwarding the request: the matching entry is returned unchanged, a model
    +/// the upstream does not list is a 404, and an upstream error is forwarded as is.
    +#[cfg_attr(feature = "openapi", utoipa::path(
    +    get,
    +    path = "/v1/models/{model}",
    +    params(
    +        ("model" = String, Path, description = "Model ID; may contain `/`, encoded or not"),
    +    ),
    +    responses(
    +        (status = 200, description = "The upstream's entry for this model, unchanged"),

    The new OpenAPI operation declares a description but no 200 response body/content, so generated clients model successful retrieval as an empty response even though the handler returns a model object. Declare the existing ModelObject schema here (and ideally assert this path’s response schema in the OpenAPI test).

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Oct 10, 2026 00:15 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🟡 Changes recommended

    Model retrieval drops upstream metadata headers and its OpenAPI success response lacks a body schema.

    <details open>
    <summary><strong>2 open findings</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Preserve upstream headers in transformed model responses · New

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.png" alt="Low severity" width="62" height="18" align="texttop"></picture> Declare the successful response schema in the OpenAPI operation · New

  • </details>

    <details>
    <summary><strong>What changed in this PR</strong></summary>

    Adds embeddings passthrough and single-model retrieval to the HTTP gateway.

    Changes:

  • Proxies POST /v1/embeddings.

  • Serves GET /v1/models/{model} from the upstream model list.

  • Adds documentation, OpenAPI registration, authentication checks, and integration tests.
  • | File | Description |
    | ---- | ----------- |
    | README.md | Lists the new endpoints. |
    | docs/​api/​index.md | Documents passthrough and model retrieval behavior. |
    | crates/​agentic-server/​tests/​oidc_auth_test.rs | Verifies endpoint authentication. |
    | crates/​agentic-server/​tests/​models_test.rs | Tests model lookup and errors. |
    | crates/​agentic-server/​tests/​embeddings_passthrough_test.rs | Tests embeddings passthrough and limits. |
    | crates/​agentic-server/​src/​openapi.rs | Registers the new OpenAPI paths. |
    | crates/​agentic-server/​src/​handler/​mod.rs | Re-exports new handlers. |
    | crates/​agentic-server/​src/​handler/​http/​models.rs | Implements model retrieval. |
    | crates/​agentic-server/​src/​handler/​http/​mod.rs | Registers HTTP handler modules. |
    | crates/​agentic-server/​src/​handler/​http/​embeddings.rs | Implements embeddings passthrough. |
    | crates/​agentic-server/​src/​handler/​http/​chat_completions.rs | Reuses the shared passthrough helper. |
    | crates/​agentic-server/​src/​handler/​common.rs | Centralizes passthrough behavior. |
    | crates/​agentic-server/​src/​app.rs | Adds routes to the protected router. |
    </details>

    🧠 Review effort: Balanced

    ---

    💡 <a href="/vllm-project/agentic-api/new/main?filename=.github/skills/code-review/SKILL.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add a code-review agent skill</a> or configure MCP servers for context-aware, tailored reviews. <a href="https://docs.github.com/copilot/how-tos/use-copilot-agents/request-a-code-review/use-code-review?tool=webui#mcp-servers-and-agent-skills" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn more in the docs.</a>

    Mohammad-nassar10 Mohammad-nassar10 commented on code on Oct 10, 2026 01:08 UTC
    Code Review
    crates/agentic-server/src/handler/http/models.rs:1
    @@ -369,32 +403,87 @@ pub async fn models(State(state): State<AppState>, headers: HeaderMap, Query(par
             return convert_response(upstream);
         }
     
    +    let upstream_bytes = match model_list_body(upstream) {
    +        Ok(bytes) => bytes,
    +        Err(response) => return response,
    +    };
    +
    +    match build_codex_models_response(&upstream_bytes, &state.model_capabilities) {
    +        Ok(response) => axum::Json(response).into_response(),
    +        Err(error) => invalid_model_list(&error),
    +    }
    +}
    +
    +/// GET /v1/models/{model} — one entry of the upstream model list.
    +///
    +/// vLLM serves no per-model route, so the gateway answers from the upstream `/v1/models`
    +/// list instead of forwarding the request: the matching entry is returned unchanged, a model
    +/// the upstream does not list is a 404, and an upstream error is forwarded as is.
    +#[cfg_attr(feature = "openapi", utoipa::path(
    +    get,
    +    path = "/v1/models/{model}",
    +    params(
    +        ("model" = String, Path, description = "Model ID; may contain `/`, encoded or not"),
    +    ),
    +    responses(
    +        (status = 200, description = "The upstream's entry for this model, unchanged"),
    +        (status = 404, description = "The upstream does not list this model", body = crate::openapi::ApiErrorResponse),
    +        (status = 502, description = "Upstream unavailable", body = crate::openapi::ApiErrorResponse),
    +    ),
    +    security(("bearer_auth" = [])),
    +    tag = "models",
    +))]
    +pub async fn retrieve_model(State(state): State<AppState>, headers: HeaderMap, Path(model): Path<String>) -> Response {
    +    let upstream = proxy_get("/v1/models", &headers, &state.proxy_state).await;
    +    let upstream_bytes = match model_list_body(upstream) {
    +        Ok(bytes) => bytes,
    +        Err(response) => return response,
    +    };
    +
    +    match find_upstream_model(&upstream_bytes, &model) {
    +        Ok(Some(entry)) => {
    +            let content_type = [(http::header::CONTENT_TYPE, "application/json")];
    +            (content_type, entry.get().to_owned()).into_response()
    +        }
    +        Ok(None) => convert_response(error_response(
    +            StatusCode::NOT_FOUND,
    +            "model_not_found",
    +            &format!("The model `{model}` does not exist"),
    +        )),
    +        Err(error) => invalid_model_list(&error),
    +    }
    +}

    Fixed, Applied with processed_response_headers instead of removing the headers by hand.

    Mohammad-nassar10 Mohammad-nassar10 commented on code on Oct 10, 2026 01:09 UTC
    Code Review
    crates/agentic-server/src/handler/http/models.rs:1
    @@ -369,32 +403,87 @@ pub async fn models(State(state): State<AppState>, headers: HeaderMap, Query(par
             return convert_response(upstream);
         }
     
    +    let upstream_bytes = match model_list_body(upstream) {
    +        Ok(bytes) => bytes,
    +        Err(response) => return response,
    +    };
    +
    +    match build_codex_models_response(&upstream_bytes, &state.model_capabilities) {
    +        Ok(response) => axum::Json(response).into_response(),
    +        Err(error) => invalid_model_list(&error),
    +    }
    +}
    +
    +/// GET /v1/models/{model} — one entry of the upstream model list.
    +///
    +/// vLLM serves no per-model route, so the gateway answers from the upstream `/v1/models`
    +/// list instead of forwarding the request: the matching entry is returned unchanged, a model
    +/// the upstream does not list is a 404, and an upstream error is forwarded as is.
    +#[cfg_attr(feature = "openapi", utoipa::path(
    +    get,
    +    path = "/v1/models/{model}",
    +    params(
    +        ("model" = String, Path, description = "Model ID; may contain `/`, encoded or not"),
    +    ),
    +    responses(
    +        (status = 200, description = "The upstream's entry for this model, unchanged"),

    Fixed.

    franciscojavierarceo franciscojavierarceo approved these changes on Oct 10, 2026 10:57 UTC
    Approved Reviewer

    Approved these changes.

    Assignees
    Mohammad-nassar10 Mohammad-nassar10
    Labels
    risk: low confidence: 86.1% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 63.3% (MEDIUM) · Higher = larger blast radius
    63.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 86.1% · Lower = rushed or shallow review
    86.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 8.8% · Safe to merge
    8.8%