Skip to content

fix(sdk): add missing format field to SessionPromptData type - #26428

Closed
xxiaoxiong wants to merge 1 commit into
anomalyco:devfrom
xxiaoxiong:fix/sdk-format-type-missing
Closed

fix(sdk): add missing format field to SessionPromptData type#26428
xxiaoxiong wants to merge 1 commit into
anomalyco:devfrom
xxiaoxiong:fix/sdk-format-type-missing

Conversation

@xxiaoxiong

Copy link
Copy Markdown

Summary

Fixes a TypeScript type definition issue where the format field is missing from SessionPromptData, even though it exists in the OpenAPI spec and works at runtime.

Problem

Users trying to use structured output with the SDK get TypeScript errors:

const result = await client.session.prompt({
  path: { id: session.data?.id! },
  body: {
    parts: [{ type: "text", text: "Research Anthropic" }],
    format: {  // ❌ TypeScript error: format does not exist
      type: "json_schema",
      schema: { /* ... */ }
    }
  }
});

The OpenAPI spec (line 5254-5256 in packages/sdk/openapi.json) does include the format field:

"format": {
  "$ref": "#/components/schemas/OutputFormat"
}

But the generated TypeScript types in packages/sdk/js/src/gen/types.gen.ts are missing:

  • OutputFormat type
  • OutputFormatText type
  • OutputFormatJsonSchema type
  • format field in SessionPromptData.body

Root Cause

The types are auto-generated from the OpenAPI spec, but the generation appears to have skipped these definitions. This could be:

  1. A bug in the type generation tool (@hey-api/openapi-ts)
  2. The generated types were not committed after a recent spec update
  3. A configuration issue in the generation script

Solution

Manually added the missing type definitions based on the OpenAPI spec:

export type OutputFormatText = {
  type: "text"
}

export type OutputFormatJsonSchema = {
  type: "json_schema"
  schema: Record<string, unknown>
  retryCount?: number
}

export type OutputFormat = OutputFormatText | OutputFormatJsonSchema

And added the format field to SessionPromptData.body:

body?: {
  // ... other fields
  format?: OutputFormat
  parts: Array<...>
}

Changes

  • packages/sdk/js/src/gen/types.gen.ts:
    • Added OutputFormatText type
    • Added OutputFormatJsonSchema type
    • Added OutputFormat union type
    • Added format?: OutputFormat field to SessionPromptData.body

Testing

  • The types match the OpenAPI spec definitions
  • TypeScript users can now use the format parameter without type errors
  • No runtime behavior changes (the API already supported this field)

Notes

This is a manual fix. The proper long-term solution would be to:

  1. Investigate why the type generation skipped these definitions
  2. Re-run the generation script (./packages/sdk/js/script/build.ts) after fixing the root cause
  3. Commit the regenerated types

However, since the generation script requires Bun and a full build environment, this manual fix provides immediate relief for users hitting this issue.

Fixes #26408

The SessionPromptData type was missing the 'format' field that exists
in the OpenAPI spec. This field allows users to specify structured
output formats (text or json_schema) when sending prompts.

Added missing types:
- OutputFormatText: for plain text output
- OutputFormatJsonSchema: for JSON schema-based structured output
- OutputFormat: union type of the above
- format?: OutputFormat field in SessionPromptData.body

This allows TypeScript users to use the format parameter without
type errors, matching the actual API behavior.

Fixes #26408
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label May 9, 2026
@github-actions

github-actions Bot commented May 9, 2026

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

github-actions Bot commented May 9, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label May 9, 2026
@github-actions github-actions Bot closed this May 9, 2026
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.

[SDK] "format" doesn't exist in prompt's body types

1 participant