TypeScript
Python
JavaScript
cURL
PHP
Go
Java
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.
typescript
javascript
python
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' ) ,
} ,
} )
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.
typescript
javascript
python
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.
typescript
javascript
python
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' ,
} )
Chat completion response Chat completion webhook response Chat completion stream response A unique identifier for this completion
The object type, which is always "chat.completion"
The Unix timestamp (in seconds) of when the completion was created
An array of completion choices generated by the model
The message object containing the completion
The role of the message author (e.g., "assistant")
The content of the message, which can be either a string or an object
choices.message. tool_calls
An array of tool calls, if any
A unique identifier for this completion
The object type, which is always "chat.completion"
The Unix timestamp (in seconds) of when the completion was created
An array of completion choices generated by the model
The message object containing the completion
The role of the message author (e.g., "assistant")
The content of the message, which can be either a string or an object
choices.message. tool_calls
An array of tool calls, if any
Response structure for a chat completion webhook. This represents the data sent to the webhook URL when a chat completion is finished.
Unique identifier for this chat completion response
The current status of the chat completion. 'created' means the request has been received but processing hasn't started. 'running' means the chat completion is currently being processed. 'succeeded' means the chat completion has finished successfully. 'failed' means the chat completion encountered an error and couldn't complete.
Available options:
created
,
failed
,
running
,
succeeded
Contains information about the input provided for this chat completion
Variables passed to the chat completion, including any file URLs
input_content.variables. {key}
Array of messages that were part of the input
input_content.messages. role
The role of the message sender (e.g., 'user', 'assistant', 'system')
input_content.messages. content
The content of the message. Can be a string for text messages, or an object for more complex content types like images.
input_content.messages. function_call
Optional. Information about a function call, if applicable.
input_content.messages.function_call. name
input_content.messages.function_call. arguments
Information about files used in the chat completion
input_content.files. used_at
Available options:
variables
,
messages
input_content.files. parsed_content
Available options:
image
,
file
Contains the output generated by the chat completion
The role of the entity providing the output
Available options:
system
,
user
,
assistant
,
function
output_content. tool_calls
Optional. Information about tool calls made during the completion.
output_content.tool_calls. name
output_content.tool_calls. arguments
output_content. information
Optional. Additional information about the completion process.
output_content.information. duration
output_content.information. cost
output_content.information. input_tokens
output_content.information. output_tokens
output_content. has_structured_output
Indicates whether the output has a structured format
The main content of the chat completion output
output_content. input_messages
Optional. The input messages in a string format.
The original input parameters provided for this chat completion
The ID of the version used for this chat completion
The ID of the canvas used for this chat completion
The ID of the application associated with this chat completion
The URL where webhook notifications are sent
The variables to pass to the canvas
raw_input.variables. {key}
Available options:
user
,
assistant
raw_input.messages. content
The content of the message, either as a string or a file
Override default settings specified in the canvas. This allows for fine-tuning the completion behavior for this specific request.
Specifies whether to use a chat or completion model.
Available options:
chat
,
completion
The specific model to use for this completion. If not specified, the default model set in the canvas will be used.
raw_input.override. temperature
Controls randomness in the output. Values between 0 and 1. Lower values make the output more focused and deterministic.
raw_input.override. functions
An array of functions that the model can call. This allows for more structured and interactive completions.
raw_input.override.functions. id
raw_input.override.functions. name
raw_input.override.functions. description
raw_input.override.functions. parameters
raw_input.override.functions.parameters. type
Available options:
object
raw_input.override.functions.parameters. properties
raw_input.override.functions.parameters. required
raw_input.override. structured_output
Configuration for generating structured output.
raw_input.override.structured_output. enabled
Whether to enable structured output for this completion.
raw_input.override.structured_output. schema
The schema defining the structure of the output. This is used when structured output is enabled.
raw_input.override.structured_output.schema. properties
Defines the properties of the structured output
raw_input.override.structured_output.schema. type
The type of the schema, always "object" for structured output
Available options:
object
raw_input.override.structured_output.schema. title
raw_input.override.structured_output.schema. description
A description of the schema
raw_input.override.structured_output.schema. required
An array of required property names
The raw output from the chat completion process
The date used for compatibility checks
The ID of the prompt version used for this chat completion
The ID of the prompt application, if applicable
The ID of the workspace where this chat completion was executed
The timestamp when this chat completion was created
The timestamp when this chat completion was last updated
The object of the completion
The created time of the completion
The model of the completion
choices.delta. function_call
choices.delta.function_call. name
choices.delta.function_call. arguments
The complete message object for the stream response
The role of the message author (e.g., "assistant")
The content of the message
Information about a function call, if applicable
message.function_call. name
The name of the function being called
message.function_call. arguments
The arguments passed to the function
An array of tool calls made during the completion
The name of the tool being called
message.tool_calls. arguments
The arguments passed to the tool
message. structured_content
Structured content of the message, if applicable