Skip to main content
POST
/
v1
/
function
/
{function_id}
/
invoke
Invoke function
curl --request POST \
  --url https://api.braintrust.dev/v1/function/{function_id}/invoke \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "input": "<unknown>",
  "expected": "<unknown>",
  "metadata": {},
  "tags": [
    "<string>"
  ],
  "messages": [
    {
      "role": "system",
      "content": "",
      "name": "<string>"
    }
  ],
  "parent": {
    "object_id": "<string>",
    "row_ids": {
      "id": "<string>",
      "span_id": "<string>",
      "root_span_id": "<string>"
    },
    "propagated_event": {}
  },
  "stream": true,
  "strict": true,
  "mcp_auth": {},
  "overrides": {},
  "version": "<string>"
}
'
import requests

url = "https://api.braintrust.dev/v1/function/{function_id}/invoke"

payload = {
    "input": "<unknown>",
    "expected": "<unknown>",
    "metadata": {},
    "tags": ["<string>"],
    "messages": [
        {
            "role": "system",
            "content": "",
            "name": "<string>"
        }
    ],
    "parent": {
        "object_id": "<string>",
        "row_ids": {
            "id": "<string>",
            "span_id": "<string>",
            "root_span_id": "<string>"
        },
        "propagated_event": {}
    },
    "stream": True,
    "strict": True,
    "mcp_auth": {},
    "overrides": {},
    "version": "<string>"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: JSON.stringify({
    input: '<unknown>',
    expected: '<unknown>',
    metadata: {},
    tags: ['<string>'],
    messages: [{role: 'system', content: '', name: '<string>'}],
    parent: {
      object_id: '<string>',
      row_ids: {id: '<string>', span_id: '<string>', root_span_id: '<string>'},
      propagated_event: {}
    },
    stream: true,
    strict: true,
    mcp_auth: {},
    overrides: {},
    version: '<string>'
  })
};

fetch('https://api.braintrust.dev/v1/function/{function_id}/invoke', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.braintrust.dev/v1/function/{function_id}/invoke",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'input' => '<unknown>',
    'expected' => '<unknown>',
    'metadata' => [
        
    ],
    'tags' => [
        '<string>'
    ],
    'messages' => [
        [
                'role' => 'system',
                'content' => '',
                'name' => '<string>'
        ]
    ],
    'parent' => [
        'object_id' => '<string>',
        'row_ids' => [
                'id' => '<string>',
                'span_id' => '<string>',
                'root_span_id' => '<string>'
        ],
        'propagated_event' => [
                
        ]
    ],
    'stream' => true,
    'strict' => true,
    'mcp_auth' => [
        
    ],
    'overrides' => [
        
    ],
    'version' => '<string>'
  ]),
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer <token>",
    "Content-Type: application/json"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.braintrust.dev/v1/function/{function_id}/invoke"

	payload := strings.NewReader("{\n  \"input\": \"<unknown>\",\n  \"expected\": \"<unknown>\",\n  \"metadata\": {},\n  \"tags\": [\n    \"<string>\"\n  ],\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"\",\n      \"name\": \"<string>\"\n    }\n  ],\n  \"parent\": {\n    \"object_id\": \"<string>\",\n    \"row_ids\": {\n      \"id\": \"<string>\",\n      \"span_id\": \"<string>\",\n      \"root_span_id\": \"<string>\"\n    },\n    \"propagated_event\": {}\n  },\n  \"stream\": true,\n  \"strict\": true,\n  \"mcp_auth\": {},\n  \"overrides\": {},\n  \"version\": \"<string>\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://api.braintrust.dev/v1/function/{function_id}/invoke")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"input\": \"<unknown>\",\n  \"expected\": \"<unknown>\",\n  \"metadata\": {},\n  \"tags\": [\n    \"<string>\"\n  ],\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"\",\n      \"name\": \"<string>\"\n    }\n  ],\n  \"parent\": {\n    \"object_id\": \"<string>\",\n    \"row_ids\": {\n      \"id\": \"<string>\",\n      \"span_id\": \"<string>\",\n      \"root_span_id\": \"<string>\"\n    },\n    \"propagated_event\": {}\n  },\n  \"stream\": true,\n  \"strict\": true,\n  \"mcp_auth\": {},\n  \"overrides\": {},\n  \"version\": \"<string>\"\n}")
  .asString();
require 'uri'
require 'net/http'

url = URI("https://api.braintrust.dev/v1/function/{function_id}/invoke")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"input\": \"<unknown>\",\n  \"expected\": \"<unknown>\",\n  \"metadata\": {},\n  \"tags\": [\n    \"<string>\"\n  ],\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"\",\n      \"name\": \"<string>\"\n    }\n  ],\n  \"parent\": {\n    \"object_id\": \"<string>\",\n    \"row_ids\": {\n      \"id\": \"<string>\",\n      \"span_id\": \"<string>\",\n      \"root_span_id\": \"<string>\"\n    },\n    \"propagated_event\": {}\n  },\n  \"stream\": true,\n  \"strict\": true,\n  \"mcp_auth\": {},\n  \"overrides\": {},\n  \"version\": \"<string>\"\n}"

response = http.request(request)
puts response.read_body
null

Authorizations

Authorization
string
header
required

Most Braintrust endpoints are authenticated by providing your API key as a header Authorization: Bearer [api_key] to your HTTP request. You can create an API key in the Braintrust organization settings page.

Path Parameters

function_id
string<uuid>
required

Function id

Body

application/json

Function invocation parameters

The request to invoke a function

input
any | null

Argument to the function, which can be any JSON serializable value

expected
any | null

The expected output of the function

metadata
object | null

Any relevant metadata. This will be logged and available as the metadata argument.

tags
string[] | null

Any relevant tags to log on the span.

messages
(system · object | user · object | assistant · object | tool · object | function · object | developer · object | fallback · object)[]

If the function is an LLM, additional messages to pass along to it

parent

Options for tracing the function call

stream
boolean | null

Whether to stream the response. If true, results will be returned in the Braintrust SSE format.

mode
enum<string> | null

The mode format of the returned value (defaults to 'auto')

Available options:
auto,
parallel,
json,
text,
null
strict
boolean | null

If true, throw an error if one of the variables in the prompt is not present in the input

mcp_auth
object

Map of MCP server URL to auth credentials

overrides
object | null

Partial function definition to merge with the function being invoked. Fields are validated against the function type's schema at runtime. For facets: { preprocessor?, prompt?, model? }. For prompts: { model?, ... }.

version
string

The version of the function

Response

200 - application/json

Function invocation response

The response is of type unknown.