Skip to Content
Observability

Functions

Welcome to the Functions documentation. This section provides detailed information about creating and using AI functions.

Overview

Functions are strongly-typed, composable building blocks that can be used to perform specific tasks. They provide structured outputs without the complexity of AI frameworks, allowing you to focus on your business logic rather than prompt engineering or model selection.

Rapid Prototyping

The ai object lets you call any arbitrary function like ai.researchCompany({ company }), ai.summarizeContent({ content }), or ai.doSomething({ task: 'write a snake game in HTML & vanilla JavaScript' }) and an object will be returned. This can be very helpful during development or to even just see what schema the AI wants to return.

import { ai } from 'functions.do' const titles = await ai.listBlogPostTitles({ topic: 'AGI Wrappers', tone: 'Clickbait Meme' }) const research = await ai.researchCompany({ company }, { model: 'perplexity/sonar-deep-research' }) // specify a particular model

Structured Outputs

Your business and application code should not be complicated by the leaky abstractions of AI frameworks. With new models being released daily, you shouldn’t put the model, prompts, or settings (like temperature, topP, topK, etc) in your code as the only thing that matters to your application is the return type of the output.

import { AI } from 'functions.do' const ai = AI({ leanCanvas: { productName: 'name of the product or service', problem: ['top 3 problems the product solves'], solution: ['top 3 solutions the product offers'], uniqueValueProposition: 'clear message that states the benefit of your product', unfairAdvantage: 'something that cannot be easily copied or bought', customerSegments: ['list of target customer segments'], keyMetrics: ['list of key numbers that tell you how your business is doing'], channels: ['path to customers'], costStructure: ['list of operational costs'], revenueStreams: ['list of revenue sources'], recommendations: ['list of recommendations based on the analysis'], }, }) const brand = await ai.storyBrand({ idea: 'Agentic Workflow Platform', icp: 'Alpha Devs & Empowered CTOs', })

Endpoints

List Functions

GET /functions

Returns a list of all functions accessible to the authenticated user.

Query Parameters

ParameterTypeDescription
limitintegerMaximum number of functions to return (default: 20)
offsetintegerNumber of functions to skip (default: 0)
sortstringField to sort by (default: ‘createdAt’)
orderstringSort order (‘asc’ or ‘desc’, default: ‘desc’)

Response

{ "data": [ { "id": "function_123", "name": "Summarize Text", "description": "Summarizes long text into concise points", "createdAt": "2023-01-01T00:00:00Z", "updatedAt": "2023-01-02T00:00:00Z" } // ... ], "meta": { "total": 100, "limit": 20, "offset": 0 } }

Get Function

GET /functions/:id

Returns details for a specific function.

Response

{ "id": "function_123", "name": "Summarize Text", "description": "Summarizes long text into concise points", "input": { "type": "object", "properties": { "text": { "type": "string", "description": "The text to summarize" }, "maxPoints": { "type": "integer", "description": "Maximum number of points in the summary", "default": 5 } }, "required": ["text"] }, "output": { "type": "object", "properties": { "summary": { "type": "array", "items": { "type": "string" }, "description": "Array of summary points" } } }, "code": "async function summarizeText({ text, maxPoints = 5 }) {\n // Function implementation\n}", "createdAt": "2023-01-01T00:00:00Z", "updatedAt": "2023-01-02T00:00:00Z" }

Create Function

POST /functions

Creates a new function.

Request Body

{ "name": "Summarize Text", "description": "Summarizes long text into concise points", "input": { "type": "object", "properties": { "text": { "type": "string", "description": "The text to summarize" }, "maxPoints": { "type": "integer", "description": "Maximum number of points in the summary", "default": 5 } }, "required": ["text"] }, "output": { "type": "object", "properties": { "summary": { "type": "array", "items": { "type": "string" }, "description": "Array of summary points" } } }, "code": "async function summarizeText({ text, maxPoints = 5 }) {\n // Function implementation\n}" }

Response

{ "id": "function_123", "name": "Summarize Text", "description": "Summarizes long text into concise points", "input": { "type": "object", "properties": { "text": { "type": "string", "description": "The text to summarize" }, "maxPoints": { "type": "integer", "description": "Maximum number of points in the summary", "default": 5 } }, "required": ["text"] }, "output": { "type": "object", "properties": { "summary": { "type": "array", "items": { "type": "string" }, "description": "Array of summary points" } } }, "code": "async function summarizeText({ text, maxPoints = 5 }) {\n // Function implementation\n}", "createdAt": "2023-01-01T00:00:00Z", "updatedAt": "2023-01-01T00:00:00Z" }

Update Function

PUT /functions/:id

Updates an existing function.

Request Body

{ "name": "Improved Text Summarizer", "description": "Summarizes long text into concise, informative points", "input": { "type": "object", "properties": { "text": { "type": "string", "description": "The text to summarize" }, "maxPoints": { "type": "integer", "description": "Maximum number of points in the summary", "default": 5 }, "style": { "type": "string", "enum": ["concise", "detailed", "bullet"], "default": "concise", "description": "Style of the summary" } }, "required": ["text"] }, "output": { "type": "object", "properties": { "summary": { "type": "array", "items": { "type": "string" }, "description": "Array of summary points" } } }, "code": "async function summarizeText({ text, maxPoints = 5, style = 'concise' }) {\n // Updated function implementation\n}" }

Response

{ "id": "function_123", "name": "Improved Text Summarizer", "description": "Summarizes long text into concise, informative points", "input": { "type": "object", "properties": { "text": { "type": "string", "description": "The text to summarize" }, "maxPoints": { "type": "integer", "description": "Maximum number of points in the summary", "default": 5 }, "style": { "type": "string", "enum": ["concise", "detailed", "bullet"], "default": "concise", "description": "Style of the summary" } }, "required": ["text"] }, "output": { "type": "object", "properties": { "summary": { "type": "array", "items": { "type": "string" }, "description": "Array of summary points" } } }, "code": "async function summarizeText({ text, maxPoints = 5, style = 'concise' }) {\n // Updated function implementation\n}", "createdAt": "2023-01-01T00:00:00Z", "updatedAt": "2023-01-02T00:00:00Z" }

Delete Function

DELETE /functions/:id

Deletes a function.

Response

{ "success": true, "message": "Function deleted successfully" }

Execute Function

POST /functions/:id/execute

Executes a function with the provided input.

Request Body

{ "input": { "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", "maxPoints": 3 } }

Response

{ "id": "execution_123", "functionId": "function_123", "status": "completed", "input": { "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", "maxPoints": 3 }, "output": { "summary": [ "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", "Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris." ] }, "createdAt": "2023-01-01T00:00:00Z", "completedAt": "2023-01-01T00:00:01Z" }

Error Handling

The API uses standard HTTP status codes to indicate the success or failure of requests. For more information about error codes and how to handle errors, see the Error Handling documentation.

Rate Limiting

API requests are subject to rate limiting to ensure fair usage and system stability. For more information about rate limits and how to handle rate-limiting responses, see the Rate Limiting documentation.

Webhooks

You can configure webhooks to receive notifications about function events. For more information about webhooks, see the Webhooks documentation.

SDKs

We provide SDKs for popular programming languages to make it easier to integrate with the Functions API:

Last updated on