Skip to content

Accept null service_tier and tool_calls in openai-compat responses - #10371

Merged
tim-smart merged 7 commits into
Effect-TS:v4/next-minorfrom
clean99:contrib/effect-compat-nullable-reply-fields
Nov 4, 2026
Merged

tim-smart merged 7 commits into
Effect-TS:v4/next-minorfrom
clean99:contrib/effect-compat-nullable-reply-fields

Conversation

@clean99

@clean99 clean99 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

OpenAI-compatible servers that serialize pydantic response models with a plain model_dump() send null for fields they leave unset. With the openai Python SDK (3.45.0), ChatCompletion(...).model_dump() includes a top-level "service_tier": null and "tool_calls": null on the message. vLLM's ChatCompletionResponse defaults service_tier to None and is returned with model_dump(). The compat client accepts these fields only as absent or a string/array, so generateText fails:

AiError: OpenAiClient.createResponse: Invalid response: Expected array
  at ["choices"][0]["message"]["tool_calls"]

or with Expected string at ["service_tier"] when only the tier is null. A downstream project hit both and now deletes the fields in an HttpClient wrapper: its Qwen endpoint returned service_tier: null, and some models returned tool_calls: null. In a stream, a chunk with service_tier: null fails the chunk schema and is dropped as an unknown event, so its text never arrives.

Make both fields nullable, as the streamed delta's tool_calls already is, and read null like an absent value: a null tier adds no serviceTier metadata and does not replace a tier from an earlier chunk. The new generateText test fails when either response field goes back to its strict schema, and the new streamText test fails without the chunk change (text "Hel" instead of "Hello"); responses with a tier or with tool calls decode as before.

Related

Closes EFF-3373

Same handling as #7269 and #8333 for streamed deltas.

Chat completion responses whose body carries `service_tier: null` or
`message.tool_calls: null` failed to decode, so generateText ended with
an InvalidResponseError. Streamed chunks with `service_tier: null` failed
the chunk schema and were dropped as unknown events, losing their text.

Make both fields nullable, matching the streamed delta's tool_calls, and
treat null like an absent value when reading them. The new generateText
test fails without the schema change.
Add a streamText test where a chunk with service_tier "default" is
followed by one with service_tier null. Without the chunk schema change
the second chunk is dropped and the text is "Hel"; the test also checks
that the null tier does not replace "default" in the finish metadata.

Assert that a null service_tier in a non-streaming response adds no
serviceTier metadata, and narrow the changeset to what each field does.
@changeset-bot

changeset-bot Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f2bffb0

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-openai-compat Minor
effect Minor
@effect/opentelemetry Minor
@effect/vitest Minor
@effect/ai-anthropic Minor
@effect/ai-cloudflare 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-janitor effect-janitor Bot added the 4.0 label Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

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.41 KB 39.41 KB 0.00 KB (0.00%)
basic.ts 7.23 KB 7.23 KB 0.00 KB (0.00%)
batching.ts 11.08 KB 11.08 KB 0.00 KB (0.00%)
brand.ts 6.87 KB 6.87 KB 0.00 KB (0.00%)
cache.ts 11.54 KB 11.54 KB 0.00 KB (0.00%)
config.ts 22.84 KB 22.84 KB 0.00 KB (0.00%)
differ.ts 22.00 KB 22.00 KB 0.00 KB (0.00%)
http-client.ts 27.09 KB 27.09 KB 0.00 KB (0.00%)
http-router.ts 37.00 KB 37.00 KB 0.00 KB (0.00%)
logger.ts 12.01 KB 12.01 KB 0.00 KB (0.00%)
metric.ts 9.47 KB 9.47 KB 0.00 KB (0.00%)
optic.ts 7.10 KB 7.10 KB 0.00 KB (0.00%)
pubsub.ts 16.02 KB 16.02 KB 0.00 KB (0.00%)
queue.ts 12.89 KB 12.89 KB 0.00 KB (0.00%)
schedule.ts 11.80 KB 11.80 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 14.14 KB 14.14 KB 0.00 KB (0.00%)
schema-binary.ts 41.99 KB 41.99 KB 0.00 KB (0.00%)
schema-class.ts 21.73 KB 21.73 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 29.60 KB 29.60 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 27.99 KB 27.99 KB 0.00 KB (0.00%)
schema-string-transformation.ts 15.35 KB 15.35 KB 0.00 KB (0.00%)
schema-string.ts 12.34 KB 12.34 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.27 KB 16.27 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 38.95 KB 38.95 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 26.15 KB 26.15 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 20.90 KB 20.90 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 21.05 KB 21.05 KB 0.00 KB (0.00%)
schema-toFormatter.ts 21.14 KB 21.14 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 26.17 KB 26.17 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 21.23 KB 21.23 KB 0.00 KB (0.00%)
schema.ts 20.82 KB 20.82 KB 0.00 KB (0.00%)
stm.ts 14.20 KB 14.20 KB 0.00 KB (0.00%)
stream.ts 10.38 KB 10.38 KB 0.00 KB (0.00%)

@effect-bot
effect-bot changed the base branch from main to v4/next-minor November 4, 2026 10:44
@effect-janitor effect-janitor Bot removed the 4.0 label Nov 4, 2026
@effect-bot
effect-bot force-pushed the v4/next-minor branch 6 times, most recently from a23a9b6 to ad75670 Compare November 4, 2026 23:33
@tim-smart
tim-smart merged commit e4eb5bd into Effect-TS:v4/next-minor Nov 4, 2026
14 of 15 checks passed

This branch is waiting to be deployed

1 waiting deployment
fork — f2bffb04 Waiting Nov 4, 2026 by effect-bot via approval-gate #25096
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.

3 participants