Skip to content

feat(openai): preserve namespace on function_call output items#14789

Merged
R-Taneja merged 8 commits intomainfrom
rohan/openai-preserve-namespace-on-function-call
May 1, 2026
Merged

feat(openai): preserve namespace on function_call output items#14789
R-Taneja merged 8 commits intomainfrom
rohan/openai-preserve-namespace-on-function-call

Conversation

@R-Taneja
Copy link
Copy Markdown
Contributor

Summary

When the OpenAI Responses API dispatches a tool call from inside a `namespace` tool wrapper, the resulting `function_call` output item carries a `namespace` field identifying which namespace the dispatch came from. Example response from a Codex-style `tool_search` + `namespace` flow:

```json
{
"type": "function_call",
"id": "fc_...",
"call_id": "call_...",
"name": "get_weather",
"arguments": "{"location":"NYC"}",
"status": "completed",
"namespace": "weather_ns"
}
```

The provider's response schema didn't include `namespace`, so zod stripped it during validation. Downstream consumers (e.g. Vercel AI Gateway's OpenResponses-compat layer) couldn't surface namespace information back to clients.

Changes

  • Add `namespace: z.string().nullish()` to the three `function_call` schemas in `openai-responses-api.ts` (response output, output items, `response.output_item.done` stream events).
  • Forward `part.namespace` / `value.item.namespace` via `providerMetadata.openai.namespace` on the resulting `tool-call` content / stream parts in `openai-responses-language-model.ts` (both non-streaming and streaming paths).

Optional / nullish, so the change is fully backwards-compatible — no impact on requests that don't use namespace tools.

Test plan

  • `pnpm test:node` in `packages/openai` — 680/680 pass; 2 new tests cover present/absent cases.
  • `pnpm type-check:full` clean.
  • `pnpm check` clean.

Related

  • feat(openai): add new tool search tool #13157 — added `tool_search` (related Codex feature).
  • vercel/ai-gateway#1806 — gateway PR that propagates this field through to OpenResponses output (becomes effective once this lands and the gateway bumps).

Backports

If accepted, this should also backport to release-v6.0 (and possibly release-v5.0) so existing Codex traffic on the gateway gets the field. Happy to author those backports if the team prefers.

When the Responses API dispatches a tool call from inside a `namespace`
tool wrapper, the resulting function_call output item carries a
`namespace` field identifying which namespace the dispatch came from.
The provider's response schema didn't include namespace, so it was
stripped during validation and downstream consumers couldn't access it.

Adds namespace to the function_call schemas (response output, output
items, and response.output_item.done stream events) and surfaces it via
providerMetadata.openai.namespace on the resulting tool-call parts.
Nullish — no impact when namespace tools aren't in use.
So that streaming consumers can read namespace before the subsequent
tool-call event arrives. Useful for downstream layers (e.g. AI Gateway's
OpenResponses-compat) that emit completed function_call output items
during tool-input-end and would otherwise miss namespace until tool-call
arrives a step later.
Comment thread packages/openai/src/responses/openai-responses-language-model.ts
Copy link
Copy Markdown
Collaborator

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@R-Taneja code change looks reasonable, can you add an example that makes use of namespaces for tools so we can verify this? https://developers.openai.com/api/docs/guides/function-calling#defining-namespaces

Two examples under examples/ai-functions/src/{generate-text,stream-text}/openai/
that demonstrate `namespace` flowing through to dispatched function calls
when the model uses server-executed tool_search to find a deferred
function. The generate variant prints providerMetadata.openai on the
tool-call content part; the stream variant prints it on both
tool-input-end and the consolidated tool-call event.

Reviewer ask: #14789 (comment)...
@R-Taneja R-Taneja added the backport Admins only: add this label to a pull request in order to backport it to the prior version label Apr 28, 2026
@R-Taneja
Copy link
Copy Markdown
Contributor Author

@R-Taneja code change looks reasonable, can you add an example that makes use of namespaces for tools so we can verify this? https://developers.openai.com/api/docs/guides/function-calling#defining-namespaces

added!

@R-Taneja R-Taneja requested a review from felixarntz April 28, 2026 22:08
@R-Taneja R-Taneja merged commit bada0f3 into main May 1, 2026
18 checks passed
@R-Taneja R-Taneja deleted the rohan/openai-preserve-namespace-on-function-call branch May 1, 2026 18:18
@github-actions github-actions Bot removed the backport Admins only: add this label to a pull request in order to backport it to the prior version label May 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

✅ Backport PR created: #14910

gr2m pushed a commit that referenced this pull request May 1, 2026
…ems (#14910)

This is an automated backport of #14789 to the release-v6.0 branch. FYI
@R-Taneja

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

3 participants