Skip to content

feat(preset): add Anthropic batch jobs - #43

Open
tasoo-oos wants to merge 22 commits into
PocketRisu:developfrom
tasoo-oos:feat-preset-anthropic-batch-jobs
Open

feat(preset): add Anthropic batch jobs#43
tasoo-oos wants to merge 22 commits into
PocketRisu:developfrom
tasoo-oos:feat-preset-anthropic-batch-jobs

Conversation

@tasoo-oos

@tasoo-oos tasoo-oos commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

PR Checklist

  • Required Checks
    • Have you added type definitions?
    • Have you tested your changes?
    • Have you checked that it won't break any existing features?
  • If your PR uses models1, check the following:
    • Have you checked if it works normally in all models / providers?
  • If your PR is highly AI generated2, check the following:
    • Have you understood what the code does?
    • Have you cleaned up any unnecessary or redundant code?
    • Is it not a huge change?

Summary

Adds Anthropic Messages batch support for Model Presets. Anthropic presets can now submit a long-running batch job, poll for completion, parse the final JSONL result, and surface progress through request status.

Related Issues

None.

Changes

Behavior changes:

  • Anthropic Model Presets use /v1/messages/batches when preset service_tier is set to batch.
  • Preview body now shows the batch request envelope when the request would use batch mode.
  • Main chat, emotion, translation, memory, scripting, triggers, suggestions, MCP AI access, and playground callers can wait for provider job results.
  • Request status toasts show a waiting phase and Anthropic batch badges for submitted/running/cancel/completed/failed states.
  • Canceling a batch requests provider cancellation, but still accepts a late successful batch result if Anthropic finishes before cancellation is final.
  • Batch fetch logs are limited to submission and final result fetches, avoiding noisy poll logs.
  • Banned-character-set auto-regeneration is not available for batch jobs because final results can arrive much later.
    • It is now documented as so in the Advanced Settings UI.

Anthropic batch architecture:

  • ProviderRequestJob adds a generic async job result type to the request pipeline.
  • AnthropicBatchJob owns submit-time metadata, polling, timeout, cancellation, JSONL result parsing, and final status state.
  • The existing Anthropic adapter now exports request preparation and response parsing so batch mode reuses the same request-body construction and message parser as normal Anthropic messages.
  • requestModelPreset decides whether a preset should use batch mode, creates the prepared Anthropic request, strips batch-incompatible fields, and returns { type: "job" }.
  • The outer request loop wraps job success results so existing escape handling and after-request plugin replacers still run after the batch completes.
  • wrapAnthropicBatchStatusJob bridges provider job status into the request-status store without letting status UI failures affect the request.

Other changes:

  • Add Batch as a bundled Anthropic service tier option.
  • Add per-entry request-status abandon timeouts so long-running batch jobs are not dropped by the normal status cleanup.
  • Add focused tests for batch submission, preview payloads, polling, cancellation, late success, fetch logging, and request-status behavior.

Impact

Users can opt Anthropic presets into slower long-running batch requests. Existing streaming/non-streaming requests remain unchanged unless batch mode is selected. Batch mode does not automatically retry for banned character sets. Also, batch jobs bypass normal blank-response fallback/retry behavior and banned-character auto-regeneration.

Demo

All these E2E tests were conducted at version 1b2187a
For long videos, middle parts are API polling, so nothing happens really.
I suggest you to watch start and end part of the video.

Test settings / Test run
test-req.mp4
Base - Success
base.-.successful.request.mp4
Cancellation behavior - Cancelled
Cancellation.behavior.-.Cancelled.mp4
Cancellation behavior - Cancelled from Anthropic Server
Cancellation.behavior.-.server.side.cancel.mp4
how to cancel server-side

This path can be triggered by canceling batch in the Anthropic Console.

Cancellation behavior - Successful anyway
Cancellation.behavior.-.Successful.anyway.mp4
Invalid Request - Invalid API key
Invalid.Request.-.Invalid.API.key.mp4
Invalid Request - Invalid parameter
Invalid.Request.-.Invalid.parameter.mp4
image

Settings were made with additional parameters.

Batch with tool use - Success
simple.tool.call.-.success.mp4
image

Internally, multiple batch request is getting submitted sequentially.

image

Tool use must be enabled at the model preset, or else model hallucinates tool result.
This seems buggy, but it is not handled since it is not necessarilly batch-specific behavior.

Batch with tool use - Cancelled in the middle image
logging

Anthropic Batch API only logs two things: First batch submit and final results.

request log preview

request log preview

request log exmaple - iniital request

request log exmaple - iniital request

request log exmaple - final response success

request log exmaple - final response success

request log example - cancelled

request log example - cancelled

Additional Notes

After this PR's merge, there's a registry-side PR that matches this one at PocketRisu/pocketrisu-model-registry#1

Footnotes

  1. Modifies the behavior of prompting, requesting, or handling responses from AI models.

  2. Over 80% of the code is AI generated.

@tasoo-oos
tasoo-oos force-pushed the feat-preset-anthropic-batch-jobs branch from 76c8195 to 9c8b60b Compare June 20, 2026 16:56
@tasoo-oos
tasoo-oos marked this pull request as ready for review June 25, 2026 17:05
@tasoo-oos

tasoo-oos commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Questions

I decoupled the Claude Batching toggle from advanced settings from the model preset, so the preset-based request behavior is not affected from the toggle. Would this be the good behavior? Or would should this toggle also affect preset-based request?

image

I haven't tested it on playgrounds environment because I have no Idea how to make preset be used in playground settings. "Save as default" at preset binding works partially, but it does not inject API key to the request. Is it not implemented in v1.8.1?

@tasoo-oos

Copy link
Copy Markdown
Contributor Author

Also, I know this is pretty big for a single PR.
I will comply if you need any questions or help with this PR.

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