### Tela API Reference: GET /task Endpoint Source: https://docs.tela.com/en/creating-tasks This documentation outlines the parameters available for the `/task` GET endpoint, used to retrieve tasks from an application. It covers options for pagination, filtering by status, date ranges, approval details, and sorting results. ```APIDOC GET /task Description: Retrieve tasks from an app. Parameters: Pagination: limit: Type: integer Description: Number of results per response. Default: 10 Range: 1-100 offset: Type: integer Description: Starting position of results. Default: 0 Filtering: status: Type: array of strings Description: Array of task statuses. Options: "created", "running", "validating", "completed", "failed" since: Type: timestamp or ISO 8601 string Description: Start date for filtering tasks. until: Type: timestamp or ISO 8601 string Description: End date for filtering tasks. approvedBy: Type: string Description: Email of the user who approved the task. revisionProcess: Type: string Description: Type of revision received. Options: "approvedWithRevisions", "approvedDirectly" promptApplicationId: Type: string Description: ID of the application where the task was created. promptVersionId: Type: string Description: ID of the Canvas version used to create the task. ids: Type: array of strings Description: Array of specific task IDs to retrieve. Sorting: orderBy: Type: string Description: Field to sort by. Options: "name", "reference", "approvedAt", "createdAt", "updatedAt", "id", "status", "approvedBy", "createdBy" order: Type: string Description: Sort direction. Options: "asc", "desc" ``` -------------------------------- ### Fetch Completed Tasks from Tela API (JavaScript) Source: https://docs.tela.com/en/creating-tasks This JavaScript snippet demonstrates how to fetch 50 completed tasks from the Tela API created after November 1st, 2024, sorted by name in ascending order. It utilizes the `fetch` API to construct a GET request, setting query parameters for `limit`, `promptApplicationId`, `status`, `since`, `orderBy`, and `order`. Authentication is handled via a Bearer token in the Authorization header. ```JavaScript const url = new URL('https://api.tela.com/task') url.searchParams.append('limit', '50') url.searchParams.append('promptApplicationId', '{YOUR_APPLICATION_ID}') url.searchParams.append('status', JSON.stringify(['completed'])) url.searchParams.append('since', '2024-11-01T00:00:00Z') url.searchParams.append('orderBy', 'name') url.searchParams.append('order', 'asc') const response = await fetch(url, { method: 'GET', headers: { 'Authorization': `Bearer ${process.env.TELA_API_KEY}`, 'Content-Type': 'application/json' } }); const tasks = await response.json() ``` -------------------------------- ### Creating Tela Task with Webhook Notification Source: https://docs.tela.com/en/creating-tasks This example illustrates how to create a Tela task and specify a `webhook_url`. Upon task completion or failure, Tela will send a POST request to the provided URL, allowing for asynchronous notification without the need for client-side polling. ```TypeScript const task = await tela.completions.create<{ document: TelaFile }, { fileSummary: string }>( applicationId: process.env.TELA_APPLICATION_ID, variables: { document: tela.createFile('https://example.com/document.pdf') }, webhook_url: "https://example.com/webhook" }) ``` -------------------------------- ### Include Conversational Messages in Tela API Call Source: https://docs.tela.com/en/completion-api-guide This example illustrates how to add a 'messages' array to a Tela API completion request. Messages provide conversational context to the model, enhancing interaction and output quality. The sequence of messages is crucial, representing the chronological flow of the conversation with alternating user and assistant turns. ```Typescript 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') }, messages: [ { role: 'user', content: { type: 'text', text: 'Hello, how can I assist you today?' } }, { role: 'assistant', content: { type: 'image_url', image_url: { url: 'https://example.com/image.png', detail: 'high' } } } ] }) ``` -------------------------------- ### Make API Call Asynchronous with Async Flag Source: https://docs.tela.com/en/completion-api-guide Extends the API request body with an `async` key set to `true` to enable asynchronous behavior. An `id` will be returned immediately, allowing you to monitor the status of the call. ```Curl curl -XPOST https://api.tela.com/v2/chat/completions \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer API-KEY' \ -d '{ ..., "async": true }' ``` -------------------------------- ### Make API Call Asynchronous with Webhook URL Source: https://docs.tela.com/en/completion-api-guide Passes a `webhook_url` key in the API request body to make the completion asynchronous. The response will be sent via a POST request to the provided URL when the completion is finished. ```Typescript 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') }, webhook_url: "https://example.com/webhook" }) ``` -------------------------------- ### Define Canvas Call Variables with Tela SDK Source: https://docs.tela.com/en/completion-api-guide This snippet demonstrates how to define variables for a Tela canvas API call using the Tela SDK. It shows how to pass a file URL as a variable, which can also be a Buffer, Blob, or other types. These variables are used to customize prompt behavior and are pre-filled in code snippets generated by the connect modal. ```Typescript variables: { document: tela.createFile('https://www.wmaccess.com/downloads/sample-invoice.pdf'), // It is possible to pass a URL, Buffer, Blob, etc. }, ``` -------------------------------- ### Enable Streaming for Tela Canvas API Calls Source: https://docs.tela.com/en/completion-api-guide This snippet demonstrates how to enable streaming for a Tela canvas completion call. By setting the 'stream' key to 'true' in the request body, the API response can be consumed in real-time, which is useful for applications requiring immediate data updates. ```Typescript 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') }, stream: true }) ``` -------------------------------- ### Polling Tela Task Status for Completion Source: https://docs.tela.com/en/creating-tasks This code demonstrates how to create a new task using the Tela SDK and then continuously poll its status. The loop fetches the task's current state from the `/task/{id}` API endpoint until the task is either 'completed' or 'failed', ensuring the application waits for the task's final outcome. ```TypeScript let task = await tela.completions.create<{ document: TelaFile }, { fileSummary: string }>( applicationId: process.env.TELA_APPLICATION_ID, variables: { document: tela.createFile('https://example.com/document.pdf') }, }) let isTaskCompleted = false while (!isTaskCompleted) { const response = await fetch(`https://api.tela.com/task/${task.id}`) task = await response.json() isTaskCompleted = task.status === 'completed' || task.status === 'failed' } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.