diff --git a/packages/sdk/openapi.json b/packages/sdk/openapi.json
index ce2f2e7d1..5b79514ab 100644
--- a/packages/sdk/openapi.json
+++ b/packages/sdk/openapi.json
@@ -2420,6 +2420,9 @@
"type": "boolean"
}
},
+ "format": {
+ "$ref": "#/components/schemas/OutputFormat"
+ },
"system": {
"type": "string"
},
@@ -2796,6 +2799,9 @@
"type": "boolean"
}
},
+ "format": {
+ "$ref": "#/components/schemas/OutputFormat"
+ },
"system": {
"type": "string"
},
@@ -6073,6 +6079,52 @@
},
"required": ["type", "properties"]
},
+ "OutputFormatText": {
+ "type": "object",
+ "properties": {
+ "type": {
+ "type": "string",
+ "const": "text"
+ }
+ },
+ "required": ["type"]
+ },
+ "JSONSchema": {
+ "type": "object",
+ "propertyNames": {
+ "type": "string"
+ },
+ "additionalProperties": {}
+ },
+ "OutputFormatJsonSchema": {
+ "type": "object",
+ "properties": {
+ "type": {
+ "type": "string",
+ "const": "json_schema"
+ },
+ "schema": {
+ "$ref": "#/components/schemas/JSONSchema"
+ },
+ "retryCount": {
+ "default": 2,
+ "type": "integer",
+ "minimum": 0,
+ "maximum": 9007199254740991
+ }
+ },
+ "required": ["type", "schema"]
+ },
+ "OutputFormat": {
+ "anyOf": [
+ {
+ "$ref": "#/components/schemas/OutputFormatText"
+ },
+ {
+ "$ref": "#/components/schemas/OutputFormatJsonSchema"
+ }
+ ]
+ },
"FileDiff": {
"type": "object",
"properties": {
@@ -6120,6 +6172,9 @@
},
"required": ["created"]
},
+ "format": {
+ "$ref": "#/components/schemas/OutputFormat"
+ },
"summary": {
"type": "object",
"properties": {
@@ -6245,6 +6300,28 @@
},
"required": ["name", "data"]
},
+ "StructuredOutputError": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string",
+ "const": "StructuredOutputError"
+ },
+ "data": {
+ "type": "object",
+ "properties": {
+ "message": {
+ "type": "string"
+ },
+ "retries": {
+ "type": "number"
+ }
+ },
+ "required": ["message", "retries"]
+ }
+ },
+ "required": ["name", "data"]
+ },
"ContextOverflowError": {
"type": "object",
"properties": {
@@ -6352,6 +6429,9 @@
{
"$ref": "#/components/schemas/MessageAbortedError"
},
+ {
+ "$ref": "#/components/schemas/StructuredOutputError"
+ },
{
"$ref": "#/components/schemas/ContextOverflowError"
},
@@ -6423,6 +6503,7 @@
},
"required": ["input", "output", "reasoning", "cache"]
},
+ "structured": {},
"variant": {
"type": "string"
},
@@ -8128,6 +8209,9 @@
{
"$ref": "#/components/schemas/MessageAbortedError"
},
+ {
+ "$ref": "#/components/schemas/StructuredOutputError"
+ },
{
"$ref": "#/components/schemas/ContextOverflowError"
},
diff --git a/packages/web/src/content/docs/sdk.mdx b/packages/web/src/content/docs/sdk.mdx
index 56b4a093d..4462d3440 100644
--- a/packages/web/src/content/docs/sdk.mdx
+++ b/packages/web/src/content/docs/sdk.mdx
@@ -127,24 +127,24 @@ You can request structured JSON output from the model by specifying an `outputFo
const result = await client.session.prompt({
path: { id: sessionId },
body: {
- parts: [{ type: 'text', text: 'Research Anthropic and provide company info' }],
+ parts: [{ type: "text", text: "Research Anthropic and provide company info" }],
outputFormat: {
- type: 'json_schema',
+ type: "json_schema",
schema: {
- type: 'object',
+ type: "object",
properties: {
- company: { type: 'string', description: 'Company name' },
- founded: { type: 'number', description: 'Year founded' },
+ company: { type: "string", description: "Company name" },
+ founded: { type: "number", description: "Year founded" },
products: {
- type: 'array',
- items: { type: 'string' },
- description: 'Main products'
- }
+ type: "array",
+ items: { type: "string" },
+ description: "Main products",
+ },
},
- required: ['company', 'founded']
- }
- }
- }
+ required: ["company", "founded"],
+ },
+ },
+ },
})
// Access the structured output
@@ -154,29 +154,29 @@ console.log(result.data.info.structured_output)
### Output Format Types
-| Type | Description |
-|------|-------------|
-| `text` | Default. Standard text response (no structured output) |
-| `json_schema` | Returns validated JSON matching the provided schema |
+| Type | Description |
+| ------------- | ------------------------------------------------------ |
+| `text` | Default. Standard text response (no structured output) |
+| `json_schema` | Returns validated JSON matching the provided schema |
### JSON Schema Format
When using `type: 'json_schema'`, provide:
-| Field | Type | Description |
-|-------|------|-------------|
-| `type` | `'json_schema'` | Required. Specifies JSON schema mode |
-| `schema` | `object` | Required. JSON Schema object defining the output structure |
-| `retryCount` | `number` | Optional. Number of validation retries (default: 2) |
+| Field | Type | Description |
+| ------------ | --------------- | ---------------------------------------------------------- |
+| `type` | `'json_schema'` | Required. Specifies JSON schema mode |
+| `schema` | `object` | Required. JSON Schema object defining the output structure |
+| `retryCount` | `number` | Optional. Number of validation retries (default: 2) |
### Error Handling
If the model fails to produce valid structured output after all retries, the response will include a `StructuredOutputError`:
```typescript
-if (result.data.info.error?.name === 'StructuredOutputError') {
- console.error('Failed to produce structured output:', result.data.info.error.message)
- console.error('Attempts:', result.data.info.error.retries)
+if (result.data.info.error?.name === "StructuredOutputError") {
+ console.error("Failed to produce structured output:", result.data.info.error.message)
+ console.error("Attempts:", result.data.info.error.retries)
}
```
@@ -298,27 +298,27 @@ const { providers, default: defaults } = await client.config.providers()
### Sessions
-| Method | Description | Notes |
-| ---------------------------------------------------------- | ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
-| `session.list()` | List sessions | Returns Session[] |
-| `session.get({ path })` | Get session | Returns Session |
-| `session.children({ path })` | List child sessions | Returns Session[] |
-| `session.create({ body })` | Create session | Returns Session |
-| `session.delete({ path })` | Delete session | Returns `boolean` |
-| `session.update({ path, body })` | Update session properties | Returns Session |
-| `session.init({ path, body })` | Analyze app and create `AGENTS.md` | Returns `boolean` |
-| `session.abort({ path })` | Abort a running session | Returns `boolean` |
-| `session.share({ path })` | Share session | Returns Session |
-| `session.unshare({ path })` | Unshare session | Returns Session |
-| `session.summarize({ path, body })` | Summarize session | Returns `boolean` |
-| `session.messages({ path })` | List messages in a session | Returns `{ info: `Message`, parts: `Part[]`}[]` |
-| `session.message({ path })` | Get message details | Returns `{ info: `Message`, parts: `Part[]`}` |
+| Method | Description | Notes |
+| ---------------------------------------------------------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
+| `session.list()` | List sessions | Returns Session[] |
+| `session.get({ path })` | Get session | Returns Session |
+| `session.children({ path })` | List child sessions | Returns Session[] |
+| `session.create({ body })` | Create session | Returns Session |
+| `session.delete({ path })` | Delete session | Returns `boolean` |
+| `session.update({ path, body })` | Update session properties | Returns Session |
+| `session.init({ path, body })` | Analyze app and create `AGENTS.md` | Returns `boolean` |
+| `session.abort({ path })` | Abort a running session | Returns `boolean` |
+| `session.share({ path })` | Share session | Returns Session |
+| `session.unshare({ path })` | Unshare session | Returns Session |
+| `session.summarize({ path, body })` | Summarize session | Returns `boolean` |
+| `session.messages({ path })` | List messages in a session | Returns `{ info: `Message`, parts: `Part[]`}[]` |
+| `session.message({ path })` | Get message details | Returns `{ info: `Message`, parts: `Part[]`}` |
| `session.prompt({ path, body })` | Send prompt message | `body.noReply: true` returns UserMessage (context only). Default returns AssistantMessage with AI response. Supports `body.outputFormat` for [structured output](#structured-output) |
-| `session.command({ path, body })` | Send command to session | Returns `{ info: `AssistantMessage`, parts: `Part[]`}` |
-| `session.shell({ path, body })` | Run a shell command | Returns AssistantMessage |
-| `session.revert({ path, body })` | Revert a message | Returns Session |
-| `session.unrevert({ path })` | Restore reverted messages | Returns Session |
-| `postSessionByIdPermissionsByPermissionId({ path, body })` | Respond to a permission request | Returns `boolean` |
+| `session.command({ path, body })` | Send command to session | Returns `{ info: `AssistantMessage`, parts: `Part[]`}` |
+| `session.shell({ path, body })` | Run a shell command | Returns AssistantMessage |
+| `session.revert({ path, body })` | Revert a message | Returns Session |
+| `session.unrevert({ path })` | Restore reverted messages | Returns Session |
+| `postSessionByIdPermissionsByPermissionId({ path, body })` | Respond to a permission request | Returns `boolean` |
---