Repository navigation
feat: support for OpenAI Batch API with single backend - #2883
Open
sivanantha321 wants to merge 34 commits into
Open
sivanantha321 wants to merge 34 commits into
sivanantha321 wants to merge 34 commits into
Conversation
Add support for the OpenAI-compatible Files API (/v1/files upload, list, retrieve, content, delete) without backend-sticky routing. - Gateway-issued, encrypted file ids (internal/idcodec) encode the owning backend and the routing model, so follow-up requests route by the recorded model and ids stay stable if multi-backend routing is added. - Files requests are rejected when the matched route rule has more than one backend, or when a file id belongs to a different backend than the one serving the route. - Upload routes by the multipart model field; list routes by ?model= (or the model carried in the after id). Routing-only fields are stripped before forwarding upstream. - Only the OpenAI schema is supported; other schemas fail closed. Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
…ngle-backend Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
…ngle-backend Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
Upstream errors and Envoy local replies (e.g. upstream connect errors) carry no file object, so re-encoding them produced a misleading 502 "no backend route found". Return them to the client unchanged. Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
File ids were encrypted with the MCP session crypto, which uses a random salt and nonce per call, so the same file got a different id in every response. Replace the AES-GCM codec and pluggable Crypto with a single codec using deterministic AES-GCM (HMAC-derived synthetic nonce), keys derived once at startup, and an optional fallback seed for rotation. Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
- Drop unused nativeID and redundant uploadModel fields. - Replace backendNamespace/backendName/backendKnown with a single backend *backendKey, set only by SetBackend so a known backend always has a resolved translator. - Factor shared response re-encode prelude into translatedResponseBody. - Add routeByModel, requestHeadersResponse and newRequestHeaderMutation helpers; originalPathHeader is now set in one place. - Merge stripQueryParam and rewriteAfterParam into setQueryParam. No client-visible behaviour change. Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
…ngle-backend Brings in "extproc: redact sensitive information in logs from immediate responses" (theagentrouter#2852). Also tidies filesProcessor comments: the backend field doc no longer claims a translator invariant, and "gateway ids" is reworded to "file ids". Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
…ngle-backend Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
Add TestServer_ProcessorForPath_Prefix for RegisterPrefix and the prefix fallback in processorForPath: prefix and nested paths, query stripping, exact-over-prefix and longest-prefix precedence, segment-boundary matching, and upstream lookup via the original path header. Also drop the redundant internaljson import alias in files_processor_test.go. Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
…Helm Previously --fileIDEncryptionSeed was only defined on extproc, so every deployment used the public default seed. The controller now accepts fileIDEncryption seed/iteration/fallback flags and passes them to every extproc sidecar (independent of MCP), including them in the drift hash. The Helm chart generates a random seed in a <fullname>-file-id-encryption Secret (reused on upgrade), supports existingSecret, and exposes a fallback seed for rotation. Extproc warns when the default seed is used. Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
…d Files docs Document the Helm controller.fileIDEncryption values, the forge risk of the well-known default seed, seed stability/rotation, and the 502 re-encode error. Remove stale multi-backend claims (stitched lists, fallback/load balancing) and the incorrect 501 status from supported-endpoints. Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
Call translator.RequestBody at the upstream filter once the backend is known, passing an OpenAI-shaped FilesRequest and the model-stripped upload body kept by the router filter; apply returned header/body mutations (CONTINUE_AND_REPLACE when a body is returned). Also call ResponseHeaders, ResponseError for non-2xx upstream responses, and ResponseBody for content downloads. OpenAI translators remain no-ops, so OpenAI behaviour is unchanged. This lets non-OpenAI providers (e.g. GCP) translate Files requests and responses. Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
Rename parent to routeProcessor and filesRequest to filesRequestMetadata, and shorten the comments added with the files translator wiring. Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
✅ Deploy Preview for theagentrouter ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…ration Move the comment describing the Files API prefix registration to sit directly above RegisterPrefix, and drop a stray comma in the default seed warning. Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
Name the codec implementation file after the deterministic AES-GCM scheme it implements; idcodec.go keeps the package API. Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
…ngle-backend Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
sivanantha321
force-pushed
the
openai-batch-api-single-backend
branch
from
October 22, 2026 11:07
9df1d7f to
ba29b97
Compare
…or reference Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
…ngle-backend Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
…ssor Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
… in data-plane tests Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
…date endpoint per provider Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
sivanantha321
force-pushed
the
openai-batch-api-single-backend
branch
from
October 23, 2026 13:54
ba29b97 to
b8a9b77
Compare
…ngle-backend Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
…Batch API seed configuration The Files/Batch API id encryption seed is now delivered through the filter config rather than extproc flags. Test that the Batches processor prefers the filter config codec, and update the Batch API guide to point at the Helm values / AIGW_FILE_ID_ENCRYPTION_SEED instead of --fileIDEncryptionSeed. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
sivanantha321
marked this pull request as ready for review
November 5, 2026 12:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This adds the OpenAI-compatible Batch API (
/v1/batches) on top of the Files API, with the samesingle-backend design. Clients can create, retrieve, list, and cancel batches through the gateway,
and download batch results through the existing Files API.
Like a file, a batch lives on one upstream backend: the backend that holds its input file. The
gateway keeps no state. It encrypts the owning backend and the routing model into each batch id it
returns, using the same codec and
fileIDEncryptionSeedas file ids, so no new configuration isneeded.
Routing:
POST /v1/batches) takes nomodel. It is routed by the backend and model recorded inthe gateway
input_file_id, which is replaced by the provider's own file id before forwarding.GET /v1/batches/{id}) and cancel (POST /v1/batches/{id}/cancel) are routed by themodel recorded in the batch id, and the path is rewritten to the provider's id.
GET /v1/batches) is routed by?model=, or by the model in a gatewayaftercursor, soSDK auto-pagination works after the first page.
modelis not forwarded upstream.Responses:
id,first_id, andlast_idbecome gateway batch ids.input_file_id,output_file_id, anderror_file_idbecome gateway file ids for the samebackend and model, so
GET /v1/files/{output_file_id}/contentworks unchanged.usage) passthrough. Upstream error responses pass through unchanged. A successful response whose ids cannot
be re-encoded becomes a 502 rather than leaking provider ids.
As with Files, each route rule must have exactly one backend, the id must belong to the backend
serving the request, and only the OpenAI schema has translators today.
Every request goes through the Batch translator in the upstream filter, as the Files processor
does, so a future provider translator can rewrite requests.
Related PRs
Special notes for reviewers (if applicable)
modelinside the JSONLinput file, and token-usage metering. Batch work runs asynchronously on the provider, so the
gateway does not record token usage for it.