Skip to content

refactor(native): separate request data from execution context - #39941

Closed
yujonglee-berri wants to merge 6 commits into
litellm_native_dispatch_error_fixesfrom
litellm_native_request_context
Closed

yujonglee-berri wants to merge 6 commits into
litellm_native_dispatch_error_fixesfrom
litellm_native_request_context

Conversation

@yujonglee-berri

@yujonglee-berri yujonglee-berri commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Requests mixed payloads with incomplete execution context

How it solves it:

  • Separate typed request, options, and context

User Flow

Before: the SDK request can violate this layer contract.

  1. They send a traced SDK request with route-specific options.
  2. Some identity or capability facts are unavailable downstream.

After: the same request follows one predictable contract.

  1. They send the same traced SDK request.
  2. Call ID, trace ID, model, attribution, mode, and capabilities survive.

Relevant issues

Linear ticket

Pre-Submission checklist

  • I have added meaningful tests
  • Focused tests covering this change pass locally
  • All required CI/CD checks pass
  • This PR is isolated to one stack responsibility
  • Greptile Confidence Score is at least 4/5

Stack

39928 -> 39913 -> 39923 -> 39941 -> 39939 -> 39484 -> 39986 -> 40054 -> 40055 -> 40056 -> 39765

Layer 4 of 11.

Screenshots / Proof of Fix

After (c46fd72df65801f31265abc978dab5fc6142c33f)

  1. Focused request-context and marshaling tests: passed
  2. UV_PYTHON=3.12 make check: passed
  3. Final stack Rust workspace and strict Clippy: passed

No paid-provider calls were used for deterministic validation.

Type

Refactoring

Caveats (if any)

Medium

  • Opaque input consumption lands in later stack layers.

Final Attestation

  • Tests cover this layer intended contracts and edge cases

@github-actions

github-actions Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

LiteLLM Rust workflow

Workflow completed successfully for 905c5cb7bb4cd818114defa987a8864ea789603b

View workflow run

@codspeed

codspeed Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_native_request_context (12c02dd) with litellm_native_dispatch_error_fixes (7ed2207)

Open in CodSpeed

@yujonglee-berri
yujonglee-berri force-pushed the litellm_native_request_context branch from c5cc1bd to a8966bc Compare September 5, 2026 20:31
@codecov

codecov Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.15205% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...tellm/llms/bedrock/audio_transcription/__init__.py 61.53% 5 Missing ⚠️
litellm/rust_bridge/ocr.py 58.33% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

@yujonglee-berri
yujonglee-berri force-pushed the litellm_native_request_context branch from a8966bc to e9d4c7e Compare September 5, 2026 21:19
@yujonglee-berri
yujonglee-berri force-pushed the litellm_native_request_context branch from e9d4c7e to 1c9679b Compare September 6, 2026 00:37
@yujonglee-berri
yujonglee-berri force-pushed the litellm_native_request_context branch 2 times, most recently from cd9ac16 to 8278ae7 Compare September 6, 2026 01:49
@yujonglee-berri
yujonglee-berri force-pushed the litellm_native_request_context branch from 8278ae7 to 2d27354 Compare September 6, 2026 04:35
@yujonglee-berri
yujonglee-berri force-pushed the litellm_native_request_context branch from 2d27354 to 290616d Compare September 6, 2026 06:05
@yujonglee-berri
yujonglee-berri force-pushed the litellm_native_request_context branch 3 times, most recently from 81832ee to 629e796 Compare September 6, 2026 08:18
@yujonglee-berri
yujonglee-berri marked this pull request as ready for review September 6, 2026 14:14
@yujonglee-berri
yujonglee-berri requested a review from a team September 6, 2026 14:21
@greptile-apps

greptile-apps Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR separates endpoint payloads, execution options, request identity, attribution, and capability facts across the Python-to-Rust native boundary.

  • Introduces typed Python and Rust request context/options structures.
  • Migrates chat completions, messages, OCR, transcription, and Responses WebSocket adapters to the new boundary.
  • Moves Bedrock and Vertex execution settings into provider-specific typed options.
  • Updates bridge marshaling and context-preservation tests.
  • Leaves the server-enabled Rust messages route using the old combined request shape, causing a compilation failure.

Confidence Score: 4/5

The PR is not safe to merge until the server-enabled Rust gateway messages route is updated to the new three-argument API and compiles.

One build-blocking API migration error remains: the gateway constructs a nonexistent MessagesRequest.options field and fails to pass RequestOptions separately to either messages entrypoint.

Files Needing Attention: litellm-rust/crates/ai-gateway/src/routes/messages/service.rs, litellm-rust/README.md

Important Files Changed

Filename Overview
litellm-rust/crates/ai-gateway/src/routes/messages/service.rs Migrates the gateway messages call incorrectly; the server feature cannot compile because options are embedded in MessagesRequest and omitted from entrypoint arguments.
litellm-rust/crates/core/src/messages/mod.rs Changes messages entrypoints to receive request options and execution context as separate arguments.
litellm-rust/crates/core/src/request_context.rs Adds typed call identity, attribution, and execution-capability context.
litellm-rust/crates/core/src/request_options.rs Adds shared execution options with typed Bedrock, Anthropic, and Vertex configuration.
litellm-rust/crates/python-bridge/src/marshal.rs Marshals the new Python request options and context records into Rust types.
litellm/rust_bridge/request.py Defines immutable Python request, options, context, and provider-option records used by native calls.
litellm-rust/README.md Documents the new native boundary but shows the same invalid MessagesRequest.options shape as the broken gateway call site.

Reviews (1): Last reviewed commit: "feat(native): preserve request identity ..." | Re-trigger Greptile

Comment on lines 54 to +84
let request = MessagesRequest {
model: provider_model,
body,
api_key: deployment.litellm_params.api_key.as_deref(),
api_base: deployment.litellm_params.api_base.as_deref(),
custom_llm_provider,
extra_headers,
timeout: None,
options: RequestOptions {
api_key: (deployment.litellm_params.api_key.as_deref()).map(|value| value.to_string()),
api_base: (deployment.litellm_params.api_base.as_deref())
.map(|value| value.to_string()),
custom_llm_provider: (custom_llm_provider).map(|value| value.to_string()),
extra_headers,
timeout: None,
..Default::default()
},
};
if request.body.get("stream").and_then(Value::as_bool) == Some(true) {
return messages_stream(request).await.map(MessagesResponse::Stream);
return messages_stream(
request,
&LiteLlmRequestContext {
..Default::default()
},
)
.await
.map(MessagesResponse::Stream);
}

let response = messages(request).await?;
let response = messages(
request,
&LiteLlmRequestContext {
..Default::default()
},
)
.await?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Messages route fails compilation

The server-enabled gateway constructs MessagesRequest with an options field, but that type only contains model and body. The messages and messages_stream functions also require RequestOptions as a separate argument. As a result, building litellm-ai-gateway with the server feature fails with E0560 and E0061. The README example uses the same invalid request shape and should be corrected as well.

Suggested change
let request = MessagesRequest {
model: provider_model,
body,
api_key: deployment.litellm_params.api_key.as_deref(),
api_base: deployment.litellm_params.api_base.as_deref(),
custom_llm_provider,
extra_headers,
timeout: None,
options: RequestOptions {
api_key: (deployment.litellm_params.api_key.as_deref()).map(|value| value.to_string()),
api_base: (deployment.litellm_params.api_base.as_deref())
.map(|value| value.to_string()),
custom_llm_provider: (custom_llm_provider).map(|value| value.to_string()),
extra_headers,
timeout: None,
..Default::default()
},
};
if request.body.get("stream").and_then(Value::as_bool) == Some(true) {
return messages_stream(request).await.map(MessagesResponse::Stream);
return messages_stream(
request,
&LiteLlmRequestContext {
..Default::default()
},
)
.await
.map(MessagesResponse::Stream);
}
let response = messages(request).await?;
let response = messages(
request,
&LiteLlmRequestContext {
..Default::default()
},
)
.await?;
let options = RequestOptions {
api_key: (deployment.litellm_params.api_key.as_deref()).map(|value| value.to_string()),
api_base: (deployment.litellm_params.api_base.as_deref()).map(|value| value.to_string()),
custom_llm_provider: (custom_llm_provider).map(|value| value.to_string()),
extra_headers,
timeout: None,
..Default::default()
};
let request = MessagesRequest {
model: provider_model,
body,
};
if request.body.get("stream").and_then(Value::as_bool) == Some(true) {
return messages_stream(
request,
&options,
&LiteLlmRequestContext {
..Default::default()
},
)
.await
.map(MessagesResponse::Stream);
}
let response = messages(
request,
&options,
&LiteLlmRequestContext {
..Default::default()
},
)
.await?;

@yujonglee-berri
yujonglee-berri force-pushed the litellm_native_request_context branch from c46fd72 to 905c5cb Compare September 6, 2026 15:23
@yujonglee-berri
yujonglee-berri force-pushed the litellm_native_request_context branch from 905c5cb to 12c02dd Compare September 7, 2026 17:43
@yujonglee-berri

Copy link
Copy Markdown
Contributor Author

Closing; stack is being cleaned up.

@yujonglee-berri
yujonglee-berri deleted the litellm_native_request_context branch September 16, 2026 18:05
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.

1 participant