POST
/
v2
/
chat
/
completions
import { createTelaClient } from '@meistrari/tela-sdk-js'

const tela = createTelaClient({
    apiKey: process.env.TELA_API_KEY,
})

const completion = await tela.completions.create<{ yourvariable: string }>({
  canvasId: process.env.TELA_CANVAS_ID,
  variables: {
      yourvariable: 'your value',
  },
})
{
  "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."
        }
      }
    }
  ]
}

Files

The Tela SDKs allows you to easily process files, such as PDFs, by creating a completion. Below is an example of processing a PDF document and receiving a file summary.

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.
    },
})

Streaming

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.

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))
}

Webhook

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.

import { createTelaClient } from '@meistrari/tela-sdk-js'

const tela = createTelaClient({
    apiKey: process.env.TELA_API_KEY,
})

const webhook = await tela.completions.create({
    canvasId: process.env.TELA_CANVAS_ID,
    variables: {
        document: tela.createFile('https://www.wmaccess.com/downloads/sample-invoice.pdf'),
    },
    webhookUrl: 'https://webhook.site/12345',
})

Body

application/json
The canvas to execute

Response

200
application/json
Successful completions
id
string

A unique identifier for this completion

object
string

The object type, which is always "chat.completion"

created
integer

The Unix timestamp (in seconds) of when the completion was created

choices
object[]

An array of completion choices generated by the model