Skip to content

fix(ai-anthropic): read message batch results instead of failing on 200 - #10130

Merged
tim-smart merged 4 commits into
Effect-TS:v4/next-minorfrom
Gourav224:fix/anthropic-batch-results-jsonl
Oct 29, 2026
Merged

tim-smart merged 4 commits into
Effect-TS:v4/next-minorfrom
Gourav224:fix/anthropic-batch-results-jsonl

Conversation

@Gourav224

@Gourav224 Gourav224 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem

GET /v1/messages/batches/{id}/results answers 200 with a JSON Lines body (application/x-jsonl). The pinned spec puts a JSON schema under that non-JSON media type. The HttpClient generator skips it, so messageBatchesResults and betaMessageBatchesResults matched only 4xx and failed every successful response with StatusCode: Unexpected status code.

Fix

Generated.ts is generated, so the fix is in packages/ai/anthropic/codegen.yml:

  • A spec patch reads both results responses as bytes ({ type: "string", format: "binary" }), the same way the file download operations already work. messageBatchesResults and betaMessageBatchesResults now return the body as a Uint8Array. The new messageBatchesResultsStream and betaMessageBatchesResultsStream return it as a Stream<Uint8Array>, since a batch's results can be large.
  • MessageBatchIndividualResponse and BetaMessageBatchIndividualResponse, the spec's schemas for one result line, are added to includeSchemas, so each line can be decoded:
client.messageBatchesResultsStream(batchId, undefined).pipe(
  Stream.decodeText(),
  Stream.splitLines,
  Stream.mapEffect((line) => Schema.decodeUnknownEffect(Schema.fromJsonString(Generated.MessageBatchIndividualResponse))(line))
)

Generated.ts is updated to match. The committed file predates the generator's current output (for example, its client interface has no E/R parameters), so a full regeneration would also rewrite unrelated code. The edit is limited to what this config change produces, in the file's current style. I ran node packages/tools/ai-codegen/src/bin.ts generate --provider anthropic and checked that the results operations and the two line schemas it generates match this edit.

I didn't teach the HttpClient generator to decode NDJSON into a typed stream. That is a change to @effect/openapi-generator (both transformers) beyond this fix. The bytes plus line schema cover the issue's use case.

Tests

packages/ai/anthropic/test/Generated.test.ts uses the issue's fake HttpClient, which answers 200 with application/x-jsonl:

  • messageBatchesResults returns the body, and each line decodes with MessageBatchIndividualResponse.
  • messageBatchesResultsStream streams the body, decoded line by line.
  • betaMessageBatchesResults returns the body, and each line decodes with BetaMessageBatchIndividualResponse.

Before the fix, the test file doesn't load, because the stream method and line schemas don't exist yet. The underlying call fails with Unexpected status code (200 ...), as in the issue.

Validation: pnpm lint-fix, pnpm test --run packages/ai/anthropic/test/Generated.test.ts, pnpm check.

Closes #10107
Closes EFF-3115

🤖 Generated with Claude Code

GET /v1/messages/batches/{id}/results answers 200 with a JSON Lines
body (application/x-jsonl). The spec gives that response a JSON schema
under a non-JSON media type, which the HttpClient generator skips, so
messageBatchesResults only matched 4xx and sent every successful
response to unexpectedStatus.

Patch the spec in codegen.yml so the 200 is read as bytes, like the
file download operations: messageBatchesResults returns the body as a
Uint8Array and the new messageBatchesResultsStream streams it. Generate
MessageBatchIndividualResponse (and its Beta variant) so each line can
be decoded. The same applies to betaMessageBatchesResults.

Generated.ts is updated to match what the patched config generates.

Closes Effect-TS#10107

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@changeset-bot

changeset-bot Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 49b7adf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 33 packages
Name Type
@effect/ai-anthropic Minor
effect Minor
@effect/opentelemetry Minor
@effect/vitest Minor
@effect/ai-cloudflare Minor
@effect/ai-openai-compat Minor
@effect/ai-openai Minor
@effect/ai-openrouter Minor
@effect/ai-typesafe Minor
@effect/atom-react Minor
@effect/atom-solid Minor
@effect/atom-vue Minor
@effect/platform-browser Minor
@effect/platform-bun Minor
@effect/platform-deno Minor
@effect/platform-node-shared Minor
@effect/platform-node Minor
@effect/sql-clickhouse Minor
@effect/sql-d1 Minor
@effect/sql-libsql Minor
@effect/sql-mssql Minor
@effect/sql-mysql2 Minor
@effect/sql-pg Minor
@effect/sql-pglite Minor
@effect/sql-sqlite-bun Minor
@effect/sql-sqlite-do Minor
@effect/sql-sqlite-node Minor
@effect/sql-sqlite-react-native Minor
@effect/sql-sqlite-wasm Minor
@effect/docgen Minor
@effect/doctest Minor
@effect/graphql-generator Minor
@effect/openapi-generator Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@effect-bot
effect-bot changed the base branch from main to v4/next-minor October 29, 2026 17:40
@effect-janitor effect-janitor Bot added 4.0 and removed 4.0 labels Oct 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
arbitrary-combinators.ts 39.35 KB 39.35 KB 0.00 KB (0.00%)
basic.ts 7.18 KB 7.18 KB 0.00 KB (0.00%)
batching.ts 11.06 KB 11.06 KB 0.00 KB (0.00%)
brand.ts 6.84 KB 6.84 KB 0.00 KB (0.00%)
cache.ts 11.49 KB 11.49 KB 0.00 KB (0.00%)
config.ts 22.77 KB 22.77 KB 0.00 KB (0.00%)
differ.ts 21.92 KB 21.92 KB 0.00 KB (0.00%)
http-client.ts 26.86 KB 26.86 KB 0.00 KB (0.00%)
http-router.ts 36.85 KB 36.85 KB 0.00 KB (0.00%)
logger.ts 11.96 KB 11.96 KB 0.00 KB (0.00%)
metric.ts 9.42 KB 9.42 KB 0.00 KB (0.00%)
optic.ts 7.05 KB 7.05 KB 0.00 KB (0.00%)
pubsub.ts 15.97 KB 15.97 KB 0.00 KB (0.00%)
queue.ts 12.77 KB 12.77 KB 0.00 KB (0.00%)
schedule.ts 11.74 KB 11.74 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 14.02 KB 14.02 KB 0.00 KB (0.00%)
schema-binary.ts 41.06 KB 41.06 KB 0.00 KB (0.00%)
schema-class.ts 21.65 KB 21.65 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 29.51 KB 29.51 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 27.91 KB 27.91 KB 0.00 KB (0.00%)
schema-string-transformation.ts 15.27 KB 15.27 KB 0.00 KB (0.00%)
schema-string.ts 12.26 KB 12.26 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.19 KB 16.19 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 38.87 KB 38.87 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 26.10 KB 26.10 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 20.83 KB 20.83 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 20.97 KB 20.97 KB 0.00 KB (0.00%)
schema-toFormatter.ts 21.07 KB 21.07 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 26.11 KB 26.11 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 21.16 KB 21.16 KB 0.00 KB (0.00%)
schema.ts 20.75 KB 20.75 KB 0.00 KB (0.00%)
stm.ts 14.15 KB 14.15 KB 0.00 KB (0.00%)
stream.ts 10.33 KB 10.33 KB 0.00 KB (0.00%)

@tim-smart
tim-smart enabled auto-merge (squash) October 29, 2026 22:30
@tim-smart
tim-smart merged commit be6f42b into Effect-TS:v4/next-minor Oct 29, 2026
11 checks passed
tim-smart added a commit that referenced this pull request Oct 30, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
@Gourav224
Gourav224 deleted the fix/anthropic-batch-results-jsonl branch October 30, 2026 04:35
tim-smart added a commit that referenced this pull request Nov 3, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 3, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 3, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 3, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 3, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 3, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 3, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 3, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 3, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 3, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 4, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 4, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
tim-smart added a commit that referenced this pull request Nov 4, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 4, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 6, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 6, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 6, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 6, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 6, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 6, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 7, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 7, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 7, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 8, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
tim-smart added a commit that referenced this pull request Nov 16, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 16, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 16, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 16, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 16, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 16, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 16, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 17, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 17, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 17, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 17, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 17, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 17, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 17, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 17, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 17, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 17, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 17, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 18, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
effect-bot added a commit that referenced this pull request Nov 18, 2026
…00 (#10130)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Effect Bot <[email protected]>
Co-authored-by: Tim <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@effect/ai-anthropic: messageBatchesResults fails with "Unexpected status code" on its 200 JSON Lines response

3 participants