Skip to content

fix: sync Anthropic usage chunks and Gemini input_audio from Python any-llm - #33

Merged
anurag-roy merged 1 commit into
mainfrom
cursor/any-llm-library-sync-27a5
Sep 15, 2026
Merged

anurag-roy merged 1 commit into
mainfrom
cursor/any-llm-library-sync-27a5

Conversation

@cursor

@cursor cursor Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Sync with mozilla-ai/any-llm main through 3727a2b (5 new commits since 9b3448f). One PR for the applicable library changes. No unmerged cursor[bot] sync PR was open, so this is a new PR.

Ported

  • #1392: native Anthropic streaming now puts final usage on a trailing message_stop chunk with choices: [], matching OpenAI's usage-only chunk. message_delta still carries finishReason. Consumers that read usage with if (chunk.choices.length === 0) now work for Anthropic the same way they do for OpenAI and MiniMax. Azure Anthropic and Vertex Anthropic inherit the converter. If the SDK attaches an accumulated message.usage on stop, that wins over the tokens collected from message_start / message_delta.
  • #1390: Gemini already accepted OpenAI input_audio parts; this aligns the remaining request shape. Format names map to audio/<format> (wav, mp3, flac, ogg, …), missing data/format raise InvalidRequestError, invalid base64 is rejected, and the 20 MB inline limit is checked from the encoded length before decoding. Data-URL payloads remain accepted. Vertex AI inherits the same conversion.
  • #1387: normalizeProviderError now reads HTTP status from an attached response.statusCode / response.status when the error object itself has none. Same idea as Python reading aiohttp's response.status after status_code.

Already present (tests added)

  • #1393: non-streaming Bedrock already kept assistant text alongside tool calls. Added coverage for joined text blocks and a bare tool call reporting content: null.

Skipped (not applicable)

  • #1391: Python agent-loop integration/unit tests only. This repo has no agent loop.

Tracked source SHA is now 3727a2bf3c36dec36677a42d7bd7a4b3141af48a. oxfmt and oxlint were run after the changes.

Open in Web View Automation 

Note

Medium Risk
Anthropic streaming consumers that assumed usage on the finish-reason chunk must read the trailing empty-choices chunk; Gemini audio validation is stricter and may reject previously tolerated payloads.

Overview
Syncs any-llm-ts with Python any-llm at 3727a2b (parity manifest, porting docs, patch release notes; package version 0.5.0).

Anthropic streaming now matches OpenAI-style usage chunks: message_delta still carries finishReason (and refusal/stop details) but no longer attaches usage there. Final token counts (including cache fields when present) land on a trailing message_stop chunk with choices: [], preferring accumulated message.usage on stop when the SDK provides it. Azure/Vertex Anthropic adapters inherit this path.

Gemini input_audio accepts any string format (not just mp3/wav), maps { data, format } to audio/<format> inline MIME types, requires both fields via InvalidRequestError, and centralizes base64 + 20 MB inline validation (including size check from encoded length before decode). Docs reflect flac/ogg and similar formats.

Error normalization also reads HTTP status from nested response.statusCode / response.status on SDK error objects (aiohttp-style), so 4xx mapping works when status is not on the top-level error.

Tests cover the new stream usage contract, Gemini audio conversion/validation, attached-response status parsing, and Bedrock non-streaming assistant text alongside tool calls (regression coverage only; no Bedrock adapter logic change in this PR).

Reviewed by Cursor Bugbot for commit 1ffa165. Bugbot is set up for automated code reviews on this repo. Configure here.

…ny-llm

Port mozilla-ai/any-llm through 3727a2b: trailing Anthropic usage-only
stream chunks, Gemini input_audio format mapping, and HTTP status from
attached SDK responses.

Co-authored-by: Anurag Roy <anuragroy@duck.com>
@vercel

vercel Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
any-llm-ts Ready Ready Preview Sep 15, 2026 3:48am UTC

@anurag-roy
anurag-roy marked this pull request as ready for review September 15, 2026 06:15
@anurag-roy
anurag-roy merged commit 56891cd into main Sep 15, 2026
8 checks passed
@anurag-roy
anurag-roy deleted the cursor/any-llm-library-sync-27a5 branch September 15, 2026 06:17

This branch was successfully deployed

1 active deployment
Preview — 1ffa165b Deployed Sep 15, 2026 by vercel[bot]
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.

2 participants