Skip to content

feat(router): add OpenAI-compatible /v1/files API - #1465

Open
katara-Jayprakash wants to merge 4 commits into
volcano-sh:mainfrom
katara-Jayprakash:feat/support-openapI-compatible-api
Open

feat(router): add OpenAI-compatible /v1/files API#1465
katara-Jayprakash wants to merge 4 commits into
volcano-sh:mainfrom
katara-Jayprakash:feat/support-openapI-compatible-api

Conversation

@katara-Jayprakash

@katara-Jayprakash katara-Jayprakash commented Jul 31, 2026

Copy link
Copy Markdown
Member

What type of PR is this?

/kind feature

What this PR does / why we need it:

Adds OpenAI-compatible /v1/files support in kthena-router as the foundation for Batch API workloads.

  • Upload / list / get / content / delete for files with purpose=batch
  • Local filesystem store behind a pluggable FileStore interface
  • Wired early in the router handler path (same pattern as /v1/models), before model request parsing
  • Enabled when KTHENA_BATCH_FILES_DIR is set; optional KTHENA_BATCH_MAX_FILE_BYTES (default 200MiB) and KTHENA_BATCH_FILE_TTL (default 30d)

This unlocks offline batch input/output file management inside the router (no separate service) and prepares for the follow-up /v1/batches + worker PR.

Which issue(s) this PR fixes:
Fixes #

Bug evidence (required for bug-related PRs):
N/A

Special notes for your reviewer:

  • Feature is opt-in via KTHENA_BATCH_FILES_DIR; with it unset, /v1/files is not enabled
  • Storage is local-disk only in this PR (S3/SQL deferred)
  • Upload limited to purpose=batch
  • Unit tests cover store + HTTP handlers + router routing
  • Follow-up PR: /v1/batches API and in-router async worker

Does this PR introduce a user-facing change?:

Add OpenAI-compatible /v1/files API in kthena-router for batch file upload, list, get, content, and delete (enabled via KTHENA_BATCH_FILES_DIR).

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

Enable batch file upload/list/get/delete in kthena-router.

Signed-off-by: katara-Jayprakash <katarajayprakash@icloud.com>
@katara-Jayprakash

Copy link
Copy Markdown
Member Author

/cc @FAUST-BENCHOU @LiZhenCheng9527 @YaoZengzeng @hzxuzhonghu ptal as this is foundational pr for adding the feat/openai-compatible files apis.

Signed-off-by: katara-Jayprakash <katarajayprakash@icloud.com>
@katara-Jayprakash
katara-Jayprakash force-pushed the feat/support-openapI-compatible-api branch from 9374de7 to c578ff1 Compare July 31, 2026 20:51
connectorFactory *connectors.Factory

// OpenAI-compatible Files API (batch control plane). Nil store disables it.
filesHandler *batch.Handler

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why should file storage and asynchronous tasks belong to the Router?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This PR only adds the /v1/files endpoint. The worker is not included yet.I put it in the router because clients already use the router for the OpenAI APIs like /v1/chat/completions and /v1/models. Since the Files is part of the same API, it felt better to keep it there so auth and logging work the same way.
The main reason is in the next PR. The batch worker will send each JSONL line through the existing routing (doLoadbalance / scheduler) and If the Files and Batches were in a separate service, we'd have to build the same routing logic again, and it wouldn't share the same backend load information. and the storage is behind a FileStore interface, so later we can change from local disk to shared storage without moving the API out of the router.

batchTTL time.Duration

mu sync.RWMutex
files map[string]*storedFile

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The current implementation writes file contents to the local disk of each Router Pod, while metadata is stored in the process's own in-memory map. This approach may cause issues with multi-replica routers.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

and all records will lost after restart

}

now := time.Now().Unix()
expiresAt := now + int64(s.batchTTL.Seconds())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

seems not used

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

same fixed it in next commit


// Environment variable keys for batch file storage configuration.
const (
EnvFilesDir = "KTHENA_BATCH_FILES_DIR"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

may also need to change the helm

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed done in the latest commit.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not familiar with these compatible api,do we also need e2e test?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

no i don't think so, as i already added unittest this would going to be more then enough

Honor expires_at on get/list/open and expose opt-in router env/volume
settings so operators can enable /v1/files via the chart.

Signed-off-by: katara-Jayprakash <katarajayprakash@icloud.com>
Signed-off-by: katara-Jayprakash <katarajayprakash@icloud.com>
@volcano-sh-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign lizhencheng9527 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@LiZhenCheng9527 LiZhenCheng9527 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This file is stored in the memory of the router. If there are multiple router replicas, whether the requests before and after the request are forwarded by the same router pod. Otherwise, the file fails to be obtained.

@aeron-gh aeron-gh mentioned this pull request Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants