{ "id": "crsv-i52z8vnqekc", "object": "chat.completion", "created": 1728399621, "choices": [ { "message": { "role": "assistant", "content": { "text": "The content of the PDF is not provided, so a summary cannot be generated." } } } ] }
{ "id": "crsv-i52z8vnqekc", "object": "chat.completion", "created": 1728399621, "choices": [ { "message": { "role": "assistant", "content": { "text": "The content of the PDF is not provided, so a summary cannot be generated." } } } ] }
The Tela SDKs allows you to easily process files, such as PDFs, by creating a completion. You can use various file sources including public URLs, vault URLs from uploaded files, or pass multiple files in a single variable.
When passing file URLs directly (without using the SDK’s .createFile() method), you must wrap them in an object with a file_url property. The .createFile() method handles this formatting automatically.
Below is an example of processing a single PDF document:
Copy
import { createTelaClient } from '@meistrari/tela-sdk-js'import type { TelaFile } from '@meistrari/tela-sdk-js'const tela = createTelaClient({ apiKey: process.env.TELA_API_KEY,})const completion = await tela.completions.create<{ document: TelaFile }, { fileSummary: string }>({ canvasId: process.env.TELA_CANVAS_ID, variables: { document: tela.createFile('https://www.wmaccess.com/downloads/sample-invoice.pdf'), // It is possible to pass a URL, Buffer, Blob, etc. },})
After uploading a file using the /v3/files endpoint, you can use the vault URL in your completions. When not using the SDK’s .createFile() method, you need to wrap the URL in an object with a file_url property:
Copy
// First, upload a file and get the file IDconst fileId = '3fa85f64-5717-4562-b3fc-2c963f66afa6' // UUID from file uploadconst completion = await tela.completions.create({ canvasId: process.env.TELA_CANVAS_ID, variables: { document: { file_url: `vault://${fileId}` }, // Using vault:// URL as object },})
The Tela SDKs provides a stream option, which allows you to consume the stream of the completion. Below is an example of consuming a stream of the completion.
Copy
import fs from 'node:fs'import { createTelaClient } from '@meistrari/tela-sdk-js'import type { TelaFile } from '@meistrari/tela-sdk-js'const tela = createTelaClient({ apiKey: process.env.TELA_API_KEY,})const PATH = 'examples/stream/sample-invoice.pdf'const fileStream = fs.createReadStream(PATH)const completion = await tela.completions.create<{ document: TelaFile }, { fileSummary: string }>({ canvasId: process.env.TELA_CANVAS_ID, variables: { document: tela.createFile(fileStream), }, stream: true,})for await (const chunk of completion) { console.log(JSON.stringify(chunk))}
The Tela SDKs provides a webhookUrl option, which allows you to receive a webhook when the completion is finished. Below is an example of receiving a webhook when the completion is finished.