Skip to content

feat: first-class /v1/files + /v1/batches + /v1/fine_tuning endpoints (openai-family + azure) with batch cost attribution #720

Description

@jarvis9443

Summary

Add first-class OpenAI-compatible Batch, Files, and Fine-tuning endpoints to the data plane. Today these are only reachable through the opaque /passthrough/:provider/* tunnel (no token/cost attribution, no unified surface), which the competitive matrix (api7/AISIX-Cloud#873 section ⑤) marks as a headline ❌ vs LiteLLM / Portkey / Kong.

Scope (LiteLLM-baseline aligned)

Routes:

  • POST /v1/files (multipart upload), GET /v1/files, GET /v1/files/{id}, GET /v1/files/{id}/content, DELETE /v1/files/{id}
  • POST /v1/batches, GET /v1/batches/{id}, GET /v1/batches, POST /v1/batches/{id}/cancel
  • POST /v1/fine_tuning/jobs, GET /v1/fine_tuning/jobs, GET /v1/fine_tuning/jobs/{id}, POST /v1/fine_tuning/jobs/{id}/cancel

Provider routing (the model is not in the request body for batch create):

  • File upload accepts an explicit model (form field / query / header); the returned file id is re-encoded to embed the routing model (LiteLLM's file-id encoding scheme, decode_model_from_file_id / encode_file_id_with_model in litellm/proxy/openai_files_endpoints/common_utils.py), so subsequent POST /v1/batches with that input_file_id routes automatically.
  • Explicit model / provider override on each endpoint as fallback.
  • Provider coverage v1: openai family (incl. any OpenAI-compatible api_base) + Azure OpenAI — matching LiteLLM's OPENAI_COMPATIBLE_BATCH_AND_FILES_PROVIDERS core. Vertex (GCS-based) / Bedrock (S3-based) / Anthropic native /v1/messages/batches are different wire+storage flows → separate follow-ups.

Usage/cost attribution (LiteLLM parity, per user decision — no deferral):

  • On batch retrieve reaching status=completed, download the output file JSONL, aggregate per-line usage, emit UsageEvent(s) with real token counts (once per batch id, dedup-guarded).

Auth/governance: reuse the existing caller-key auth envelope, model ACL, quota, and usage-event pipeline (same treatment as /passthrough).

Tests

  • DP standalone e2e (vitest + mock upstream): upload→batch→retrieve→content round-trip, provider routing via encoded file id, cancel, fine-tuning job lifecycle, usage emission on completion.

Part of the section-⑤ gap closure for api7/AISIX-Cloud#873.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions