Commit Graph

88 Commits

Author SHA1 Message Date
CaIon
c1b05d3b5a refactor: clean up unused code and improve error logging in adaptor and mjp modules 2026-02-22 22:11:05 +08:00
CaIon
06fe03e34c feat(task): add model redirection, per-call billing, and multipart retry fix for async tasks
1. Async task model redirection (aligned with sync tasks):
   - Integrate ModelMappedHelper in RelayTaskSubmit after model name
     determination, populating OriginModelName / UpstreamModelName on RelayInfo.
   - All task adaptors now send UpstreamModelName to upstream providers:
     - Gemini & Vertex: BuildRequestURL uses UpstreamModelName.
     - Doubao & Ali: BuildRequestBody conditionally overwrites body.Model.
     - Vidu, Kling, Hailuo, Jimeng: convertToRequestPayload accepts RelayInfo
       and unconditionally uses info.UpstreamModelName.
     - Sora: BuildRequestBody parses JSON and multipart bodies to replace
       the "model" field with UpstreamModelName.
   - Frontend log visibility: LogTaskConsumption and taskBillingOther now
     emit is_model_mapped / upstream_model_name in the "other" JSON field.
   - Billing safety: RecalculateTaskQuotaByTokens reads model name from
     BillingContext.OriginModelName (via taskModelName) instead of
     task.Data["model"], preventing billing leaks from upstream model names.

2. Per-call billing (TaskPricePatches lifecycle):
   - Rename TaskBillingContext.ModelName → OriginModelName; add PerCallBilling
     bool field, populated from TaskPricePatches at submission time.
   - settleTaskBillingOnComplete short-circuits when PerCallBilling is true,
     skipping both adaptor adjustments and token-based recalculation.
   - Remove ModelName from TaskSubmitResult; use relayInfo.OriginModelName
     consistently in controller/relay.go for billing context and logging.

3. Multipart retry boundary mismatch fix:
   - Root cause: after Sora (or OpenAI audio) rebuilds a multipart body with a
     new boundary and overwrites c.Request.Header["Content-Type"], subsequent
     calls to ParseMultipartFormReusable on retry would parse the cached
     original body with the wrong boundary, causing "NextPart: EOF".
   - Fix: ParseMultipartFormReusable now caches the original Content-Type in
     gin context key "_original_multipart_ct" on first call and reuses it for
     all subsequent parses, making multipart parsing retry-safe globally.
   - Sora adaptor reverted to the standard pattern (direct header set/get),
     which is now safe thanks to the root fix.

4. Tests:
   - task_billing_test.go: update makeTask to use OriginModelName; add
     PerCallBilling settlement tests (skip adaptor adjust, skip token recalc);
     add non-per-call adaptor adjustment test with refund verification.
2026-02-22 16:33:00 +08:00
CaIon
7d5fc3ff51 refactor(relay): rename RelayTask to RelayTaskFetch and update routing
- Renamed RelayTask function to RelayTaskFetch for clarity.
- Updated routing in relay-router.go and video-router.go to use RelayTaskFetch for fetch operations.
- Enhanced error handling in RelayTaskFetch function.
- Adjusted task data conversion in TaskAdaptor to include task ID.
2026-02-22 16:01:19 +08:00
CaIon
8374a83084 feat(task): add adaptor billing interface and async settlement framework
Add three billing lifecycle methods to the TaskAdaptor interface:
- EstimateBilling: compute OtherRatios from user request before pricing
- AdjustBillingOnSubmit: adjust ratios from upstream submit response
- AdjustBillingOnComplete: determine final quota at task terminal state

Introduce BaseBilling as embeddable no-op default for adaptors without
custom billing. Move Sora/Ali OtherRatios logic from shared validation
into per-adaptor EstimateBilling implementations.

Add TaskBillingContext to persist pricing params (model_price, group_ratio,
other_ratios) in task private data for async polling settlement.

Extract RecalculateTaskQuota as a general-purpose delta settlement
function and unify polling billing via settleTaskBillingOnComplete
(adaptor-first, then token-based fallback).
2026-02-22 16:00:27 +08:00
CaIon
ba25ba88fe refactor(task): extract billing and polling logic from controller to service layer
Restructure the task relay system for better separation of concerns:
- Extract task billing into service/task_billing.go with unified settlement flow
- Move task polling loop from controller to service/task_polling.go (supports Suno + video platforms)
- Split RelayTask into fetch/submit paths with dedicated retry logic (taskSubmitWithRetry)
- Add TaskDto, TaskResponse generics, and FetchReq to dto/task.go
- Add taskcommon/helpers.go for shared task adaptor utilities
- Remove controller/task_video.go (logic consolidated into service layer)
- Update all task adaptors (ali, doubao, gemini, hailuo, jimeng, kling, sora, suno, vertex, vidu)
- Simplify frontend task logs to use new TaskDto response format
2026-02-22 16:00:27 +08:00
CaIon
29d48e262e feat: refactor request body handling to use BodyStorage for improved efficiency 2026-02-12 01:51:27 +08:00
feitianbubu
0823c16f97 feat: doubao add first and last image to video 2026-01-27 17:33:00 +08:00
feitianbubu
d95f334c63 fix: jimeng i2v support multi image by metadata 2026-01-19 11:34:46 +08:00
feitianbubu
c7ebd4408a feat: add doubao video 1.5 2026-01-10 22:23:31 +08:00
Seefs
b2e52260e1 Merge pull request #2532 from feitianbubu/pr/620211e02bd55545f0fa4568f3d55c3b4d7f3305 2026-01-03 09:36:17 +08:00
CaIon
62020d00a4 feat(adaptor): update resolution handling for wan2.6 model 2025-12-31 00:44:06 +08:00
Seefs
5423d6ed8c feat: Add "wan2.6-i2v" video ratio configuration to Ali adaptor. 2025-12-29 14:13:33 +08:00
feitianbubu
d014e0b471 fix: kling correct fail reason 2025-12-26 16:35:46 +08:00
t0ng7u
c2ed76ddfd 🛡️ fix: prevent OOM on large/decompressed requests; skip heavy prompt meta when token count is disabled
Clamp request body size (including post-decompression) to avoid memory exhaustion caused by huge payloads/zip bombs, especially with large-context Claude requests. Add a configurable `MAX_REQUEST_BODY_MB` (default `32`) and document it.

- Enforce max request body size after gzip/br decompression via `http.MaxBytesReader`
- Add a secondary size guard in `common.GetRequestBody` and cache-safe handling
- Return **413 Request Entity Too Large** on oversized bodies in relay entry
- Avoid building large `TokenCountMeta.CombineText` when both token counting and sensitive check are disabled (use lightweight meta for pricing)
- Update READMEs (CN/EN/FR/JA) with `MAX_REQUEST_BODY_MB`
- Fix a handful of vet/formatting issues encountered during the change
- `go test ./...` passes
2025-12-16 17:00:19 +08:00
Seefs
ee53a7b6bf Merge pull request #2412 from seefs001/pr-2372
feat: add openai video remix endpoint
2025-12-11 23:35:23 +08:00
Seefs
920e005048 fix: Use channel proxy settings for task query scenarios 2025-12-09 11:15:27 +08:00
CaIon
d4fbe1cee9 fix(vertex): ensure sampleCount is a positive integer and update OtherRatios 2025-11-30 19:05:33 +08:00
Seefs
b18704c320 Revert "Gemini Veo3.1[AI Studio]增加图生视频支持" 2025-11-30 18:45:37 +08:00
feitianbubu
70d74d74a4 feat: gemini video veo3.1 add task fail check 2025-11-26 21:56:14 +08:00
feitianbubu
ff19082c84 feat: gemini video veo3.1 add i2v 2025-11-26 21:56:13 +08:00
feitianbubu
aa2f027dea feat: add hailuo i2v fl2v r2v 2025-11-14 11:55:43 +08:00
feitianbubu
c297f42c1a feat: get hailuo video url 2025-11-14 11:55:43 +08:00
feitianbubu
b242d4c754 feat: add MiniMax Hailuo video 2025-11-14 11:55:43 +08:00
feitianbubu
29c719279a feat: vidu reference2video only viduq2 2025-11-10 16:37:27 +08:00
feitianbubu
d0f13fab1c feat: vidu specify reference2video via metadata action 2025-11-10 16:37:26 +08:00
Seefs
06260228d4 Merge pull request #2168 from feitianbubu/pr/fix-jimeng-1080p-image
fix: trim suffix p for jimeng image model
2025-11-06 19:54:02 +08:00
CaIon
942a4311ab feat: enhance Ali video request processing with resolution mapping and size validation 2025-11-05 16:02:39 +08:00
feitianbubu
894ddc06ab fix: trim suffix p for jimeng image model 2025-11-04 20:21:33 +08:00
feitianbubu
9893287f22 feat: jimeng_v30_pro only jimeng_ti2v_v30_pro model 2025-11-04 18:29:53 +08:00
CaIon
cfb39a85e3 fix: improve error handling and validation in Ali video request conversion 2025-10-31 22:39:35 +08:00
CaIon
e705cff403 feat: enhance Ali video request handling and validation 2025-10-31 22:26:56 +08:00
Seefs
a98e207ef7 feat: add ali wan video (#2141)
* feat: add ali wan video

* refactor: use same UnmarshalBodyReusable

* feat: enhance request body metadata

* feat: opt wan convertToOpenAIVideo

* feat: add wan support other param via json metadata

* refactor: remove unused code

* fix ali

---------

Co-authored-by: feitianbubu <feitianbubu@qq.com>
2025-10-31 16:51:05 +08:00
Seefs
36b712437d fix veo3 (#2140) 2025-10-31 15:29:17 +08:00
Seefs
26a21bd209 Merge pull request #2075 from feitianbubu/pr/add-gemini-veo-video
Gemini渠道支持veo视频生成
2025-10-31 13:57:59 +08:00
Sh1n3zZ
0dee868589 feat: vertex veo sora-compatible video output 2025-10-25 02:00:35 +08:00
IcedTangerine
8a9f4ac1aa Add type assertion for task_request in adaptor.go 2025-10-18 23:07:50 +08:00
feitianbubu
2f5d43fa61 feat: gemini veo req to struct 2025-10-18 21:55:25 +08:00
feitianbubu
18615abb55 feat: veo video url use proxy download 2025-10-18 21:55:25 +08:00
feitianbubu
8dfc987a87 feat: add gemini veo3.1 2025-10-18 21:55:25 +08:00
CaIon
5069482d22 refactor: update ConvertToOpenAIVideo method to return byte array and improve error handling 2025-10-14 23:03:17 +08:00
skynono
7c543a9e19 feat: jimeng images base64 limit (#2032) 2025-10-13 15:17:23 +08:00
Seefs
0dfd8f2743 Merge pull request #2029 from feitianbubu/pr/jimeng-support-oai-files
feat: jimeng use openai sdk input_reference i2v
2025-10-13 14:14:43 +08:00
feitianbubu
61f388bf84 feat: jimeng use openai sdk input_reference i2v 2025-10-13 13:06:03 +08:00
Xyfacai
b7a07e1ef7 refactor: Openai video model 移动到 dto 2025-10-13 11:45:45 +08:00
feitianbubu
7f9309ee17 feat: add vidu use openai sdk 2025-10-11 17:11:44 +08:00
feitianbubu
d733803c8a fix: kling create video via openai sdk 2025-10-11 17:11:44 +08:00
feitianbubu
d724f25db4 refactor: add openaiVideo and method 2025-10-11 17:05:36 +08:00
feitianbubu
7c7313a937 feat: add jimeng use openai sdk 2025-10-11 17:05:33 +08:00
Seefs
5010f2d004 format: package name -> github.com/QuantumNous/new-api (#2017) 2025-10-11 15:30:09 +08:00
feitianbubu
c0859c056f feat: add openai sdk for kling 2025-10-11 02:43:56 +08:00