Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .changeset/current-document-and-video-schemas.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
'@transloadit/node': minor
'transloadit': minor
'@transloadit/types': minor
'@transloadit/zod': minor
'@transloadit/mcp-server': patch
---

Contract: sync API2’s `/ai/chat` file compatibility, PDF layout extraction, video normalization,
and DAM folder-listing schemas ([#11612](https://github.com/transloadit/api2/pull/11612),
[#11630](https://github.com/transloadit/api2/pull/11630),
[#11657](https://github.com/transloadit/api2/pull/11657),
[#11682](https://github.com/transloadit/api2/pull/11682),
[#11373](https://github.com/transloadit/api2/pull/11373), and
[#11639](https://github.com/transloadit/api2/pull/11639)).

- `/document/extract` accepts the `docling` text method and `json_layout` format. The layout
output schema describes pages, blocks, and table cells.
- Type-breaking: the parsed `/document/extract` method and format unions include `docling` and
`json_layout`, respectively. Update exhaustive handlers for either union to cover the new value.
- Type-breaking: parsed `RobotDocumentExtractInstructions` now require `keep_page_headers` and
`keep_page_footers`. Both fields are optional on input and default to `false` during parsing.
- Type-breaking: parsed `/video/encode` and `/video/ondemand` Instructions with hidden fields now
include `normalize_hdr`, defaulting to `false`. If you construct either parsed type directly,
set the field. The field remains optional in the corresponding input types.
51 changes: 33 additions & 18 deletions packages/node/src/alphalib/types/robots/_ai-models.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
type AiChatModelInputCapabilities = { pdf: boolean; image: boolean; gif?: true }

/**
* Transloadit's supported /ai/chat models and their input capabilities.
* This is intentionally not a complete vendor catalog: add models only after runtime behavior,
* pricing, and file handling have been reviewed.
*/
export const MODEL_CAPABILITIES: Readonly<Record<string, { pdf: boolean; image: boolean }>> =
export const MODEL_CAPABILITIES: Readonly<Record<string, AiChatModelInputCapabilities>> =
Object.freeze({
'anthropic/claude-sonnet-4-6': { pdf: true, image: true },
'anthropic/claude-4-sonnet-20250514': { pdf: true, image: true },
'anthropic/claude-sonnet-4-20250514': { pdf: true, image: true },
'anthropic/claude-opus-4-8': { pdf: true, image: true },
'anthropic/claude-opus-5': { pdf: true, image: true },
'anthropic/claude-opus-5-5': { pdf: true, image: true },
'anthropic/claude-4-opus-20250514': { pdf: true, image: true },
'anthropic/claude-opus-4-20250514': { pdf: true, image: true },
'anthropic/claude-sonnet-4-5': { pdf: true, image: true },
'anthropic/claude-opus-4-5': { pdf: true, image: true },
'anthropic/claude-opus-4-6': { pdf: true, image: true },
'anthropic/claude-opus-4-7': { pdf: true, image: true },
'anthropic/claude-fable-5': { pdf: true, image: true },
'anthropic/claude-fable-5-1': { pdf: true, image: true },
'anthropic/claude-sonnet-5': { pdf: true, image: true },
'anthropic/claude-sonnet-5-5': { pdf: true, image: true },
'anthropic/claude-sonnet-4-6': { pdf: true, image: true, gif: true },
'anthropic/claude-4-sonnet-20250514': { pdf: true, image: true, gif: true },
'anthropic/claude-sonnet-4-20250514': { pdf: true, image: true, gif: true },
'anthropic/claude-opus-4-8': { pdf: true, image: true, gif: true },
'anthropic/claude-opus-5': { pdf: true, image: true, gif: true },
'anthropic/claude-opus-5-5': { pdf: true, image: true, gif: true },
'anthropic/claude-4-opus-20250514': { pdf: true, image: true, gif: true },
'anthropic/claude-opus-4-20250514': { pdf: true, image: true, gif: true },
'anthropic/claude-sonnet-4-5': { pdf: true, image: true, gif: true },
'anthropic/claude-opus-4-5': { pdf: true, image: true, gif: true },
'anthropic/claude-opus-4-6': { pdf: true, image: true, gif: true },
'anthropic/claude-opus-4-7': { pdf: true, image: true, gif: true },
'anthropic/claude-fable-5': { pdf: true, image: true, gif: true },
'anthropic/claude-fable-5-1': { pdf: true, image: true, gif: true },
'anthropic/claude-sonnet-5': { pdf: true, image: true, gif: true },
'anthropic/claude-sonnet-5-5': { pdf: true, image: true, gif: true },
'openai/gpt-4.1-2025-04-14': { pdf: false, image: true },
'openai/chatgpt-4o-latest': { pdf: false, image: true },
'openai/o3-2025-04-16': { pdf: false, image: true },
Expand All @@ -44,9 +46,22 @@ export const MODEL_CAPABILITIES: Readonly<Record<string, { pdf: boolean; image:
'moonshot/kimi-k2': { pdf: false, image: false },
})

/** Default /ai/chat model used when `model` is `auto` or omitted. */
/** Default /ai/chat model when automatic selection can use it for the attached files. */
export const AI_CHAT_DEFAULT_MODEL = 'openai/gpt-6-astra' satisfies keyof typeof MODEL_CAPABILITIES

const aiChatImageMimes = ['image/png', 'image/jpeg', 'image/gif', 'image/webp']

/** Check MIME support for /ai/chat, optionally limited to a specific model. */
export function supportsAiChatFile(mime: string | null, model?: string): boolean {
if (mime == null) return false
if (mime.startsWith('text/')) return true
const kind = mime === 'application/pdf' ? 'pdf' : 'image'
if (kind === 'image' && !aiChatImageMimes.includes(mime)) return false
if (model == null) return true
const capabilities = MODEL_CAPABILITIES[model]
return Boolean(capabilities?.[kind] && (mime !== 'image/gif' || capabilities.gif))
}

/** Public model identifiers accepted by the image generation Robot. */
export const imageGenerateModelIdentifiers = [
'flux-1.1-pro-ultra',
Expand Down
92 changes: 92 additions & 0 deletions packages/node/src/alphalib/types/robots/_document-layout-output.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { z } from 'zod'

const provenanceShape = {
// A paragraph's page-specific continuations share their logical source item identity.
id: z.string().optional(),
label: z.string().optional(),
provenance: z
.array(
z.object({
page: z.number().int().positive(),
bbox: z.tuple([
z.number().finite(),
z.number().finite(),
z.number().finite(),
z.number().finite(),
]),
}),
)
.optional(),
}

/** Table cells anchored at zero-based rows/columns, preserving merged-cell spans. */
export const documentTableCellSchema = z.object({
text: z.string(),
row: z.number().int().nonnegative(),
column: z.number().int().nonnegative(),
row_span: z.number().int().positive(),
column_span: z.number().int().positive(),
header: z.boolean(),
})

/** Literal PDF content blocks shared by the native and self-hosted extraction methods. */
export const documentLayoutBlockSchema = z
.discriminatedUnion('kind', [
z.object({ ...provenanceShape, kind: z.literal('paragraph'), text: z.string() }),
z.object({
...provenanceShape,
kind: z.literal('heading'),
text: z.string(),
level: z.number().int().min(1).max(6),
}),
z.object({
...provenanceShape,
kind: z.literal('list'),
ordered: z.boolean(),
start: z.number().int(),
items: z.array(z.string()),
// Source markers can be alphabetic, Roman, decimal, or compound identifiers.
markers: z.array(z.string()).optional(),
}),
z.object({
...provenanceShape,
kind: z.literal('table'),
rows: z.array(z.array(z.string())),
header: z.boolean(),
cells: z.array(documentTableCellSchema).optional(),
}),
z.object({ ...provenanceShape, kind: z.literal('image'), name: z.string() }),
])
.superRefine((block, context) => {
if (
block.kind === 'list' &&
block.markers !== undefined &&
block.markers.length !== block.items.length
) {
context.addIssue({
code: z.ZodIssueCode.custom,
path: ['markers'],
message: 'Each list item must have a corresponding source marker.',
})
}
})

/** Versioned document extraction output, grouped by original one-based page number. */
export const documentLayoutOutputSchema = z.object({
schema_version: z.literal(1),
generator: z.object({ name: z.literal('docling'), document_version: z.string() }).optional(),
pages: z.array(
z.object({
page: z.number().int().positive(),
width: z.number().positive().optional(),
height: z.number().positive().optional(),
blocks: z.array(documentLayoutBlockSchema),
}),
),
})

/** A serializable content block; text is literal and image names identify retained results. */
export type DocumentLayoutBlock = z.infer<typeof documentLayoutBlockSchema>

/** The contents of a `json_layout` extraction result. */
export type DocumentLayoutOutput = z.infer<typeof documentLayoutOutputSchema>
5 changes: 2 additions & 3 deletions packages/node/src/alphalib/types/robots/ai-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,14 +481,13 @@ export const robotAiChatInstructionsSchema = robotBase
robot: z
.literal('/ai/chat')
.describe(
'## Analyze files with an LLM\n\nConnect an input Step explicitly with `use`. Text files are read into the conversation automatically. PDFs require a PDF-capable model; PNG and JPEG inputs require an image-capable model. Convert other document formats to PDF first, and transcribe audio or video to text before using the recording workflows. Provider capabilities alone do not establish support through this Robot.\n\nFor OCR or transcription pipelines, choose `format: "text"` on the upstream Step, then reference that Step with `use` on `/ai/chat`. You do not need to interpolate the file contents into `messages`.\n\nThe `schema` parameter must be a **string containing JSON Schema**, not an inline object. Use `format: "json"` with a serialized schema for structured fields, or `format: "text"` for an answer file. Set `result: true` to expose that file in Assembly Status and download its `ssl_url` to read the answer. Result URLs are temporary; add an export Step for durable storage.\n\nFor production, we recommend using your own Anthropic, OpenAI, or Google account. Store the matching key as `anthropic_api_key`, `openai_api_key`, or `google_generative_ai_api_key` in a Template Credential of the AI Providers type and reference it with `credentials`. With your own account, you have your own provider limits and credits. The provider bills you directly, and Transloadit charges only its fee: 30% of the provider cost, with a minimum fee of $0.0005 per chat request.\n\nTransloadit’s shared provider accounts are a quick way to try things out with `test_credentials: true`. Their credits and capacity are shared by all customers, so your <dfn>Step</dfn> can be delayed or refused for reasons outside your control. With these accounts, Transloadit bills the provider cost plus a 30% fee, with a minimum fee of $0.0005 per chat request.\n\nWith either key source, Transloadit retries HTTP 429 limit responses and HTTP 5xx server errors up to twice per model request, waiting between attempts. If the provider keeps rejecting the request, the <dfn>Step</dfn> fails. Rejections returned as HTTP 400, 401, or 403 fail without retrying. The minimum fee applies once across the chat request’s model calls. When the <dfn>Step</dfn>’s regular data volume charge is higher than the pricing above, that applies instead.\n\nProvider credentials are separate from Transloadit request authentication. The example below uses a Template Credential named `my_anthropic_credentials` and exposes its JSON file with `result: true`. `model: "auto"` resolves to a configured default; select an explicitly supported PDF-capable model when passing a PDF.\n\nStart with the [complete file-processing examples](/guides/ai-file-processing-workflows/) for invoice JSON, PDF questions, recording summaries, and image descriptions. For a longer invoice application walkthrough, see the [document intelligence pipeline](/blog/2026/01/ai-document-intelligence-pipeline/).',
'## Analyze files with an LLM\n\nConnect an input Step explicitly with `use`. Text files are read into the conversation automatically. Use PDF, PNG, JPEG, GIF, or WebP. GIFs require a compatible Claude model, which sees the first frame. Convert other documents to PDF and transcribe recordings to text.\n\nFor OCR or transcription pipelines, choose `format: "text"` on the upstream Step, then reference that Step with `use` on `/ai/chat`. You do not need to interpolate the file contents into `messages`.\n\nThe `schema` parameter must be a **string containing JSON Schema**, not an inline object. Use `format: "json"` with a serialized schema for structured fields, or `format: "text"` for an answer file. Set `result: true` to expose that file in Assembly Status and download its `ssl_url` to read the answer. Result URLs are temporary; add an export Step for durable storage.\n\nFor production, we recommend using your own Anthropic, OpenAI, or Google account. Store the matching key as `anthropic_api_key`, `openai_api_key`, or `google_generative_ai_api_key` in a Template Credential of the AI Providers type and reference it with `credentials`. With your own account, you have your own provider limits and credits. The provider bills you directly, and Transloadit charges only its fee: 30% of the provider cost, with a minimum fee of $0.0005 per chat request.\n\nTransloadit’s shared provider accounts are a quick way to try things out with `test_credentials: true`. Their credits and capacity are shared by all customers, so your <dfn>Step</dfn> can be delayed or refused for reasons outside your control. With these accounts, Transloadit bills the provider cost plus a 30% fee, with a minimum fee of $0.0005 per chat request.\n\nWith either key source, Transloadit retries HTTP 429 limit responses and HTTP 5xx server errors up to twice per model request, waiting between attempts. If the provider keeps rejecting the request, the <dfn>Step</dfn> fails. Rejections returned as HTTP 400, 401, or 403 fail without retrying. The minimum fee applies once across the chat request’s model calls. When the <dfn>Step</dfn>’s regular data volume charge is higher than the pricing above, that applies instead.\n\nThe example uses the Template Credential `my_anthropic_credentials`. Fileless and text-only requests keep the configured default with `model: "auto"`. For PDFs from `use`, it selects Anthropic or Gemini. PDFs and images prefer compatible customer keys, then shared keys enabled by `test_credentials: true` at the shared rate.\n\nStart with the [complete file-processing examples](/guides/ai-file-processing-workflows/) for invoice JSON, PDF questions, recording summaries, and image descriptions. For a longer invoice application walkthrough, see the [document intelligence pipeline](/blog/2026/01/ai-document-intelligence-pipeline/).',
),
// NOTE: model:"auto" is resolved server-side to AI_CHAT_DEFAULT_MODEL for now.
model: z
.union([vendorModelSchema, z.literal('auto')])
.default('auto')
.describe(
'The model to use. The default, "auto", uses Transloadit\'s configured default model; it does not select a model based on the attached file. Choose a model that supports your input files.',
'`auto` keeps the default model for fileless or text-only requests. For PDFs and images from `use`, it prefers compatible customer keys over enabled shared keys. Unsupported-only bundles are skipped. An admitted bundle with an unsupported file fails with `AI_CHAT_VALIDATION`.',
),
format: z.enum(['json', 'text', 'meta']).default('json'),
return_messages: z.enum(['all', 'last']).default('last'),
Expand Down
Loading
Loading