Skip to main content
Applies to:


Summary

Goal: Add tags to functions created via SDK by using the API directly. Features: Create Function API endpoint supports tags while SDK Builder classes do not.

Configuration Steps

Step 1: Use the Create Function API endpoint

When creating a function via the API, you can include a tags array in the request body. This is not currently possible when using SDK builder helpers. Create Function Endpoint
POST https://api.braintrust.dev/v1/function

Step 2: Make a POST request to the Create Function endpoint

Include the tags parameter in your request body.
import requests

api_key = "YOUR_API_KEY"

response = requests.post(
    "https://api.braintrust.dev/v1/function",
    headers={
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json",
    },
    json={
        "project_id": "your-project-id",
        "function_data": {
            "type": "scorer",
            "name": "my-scorer",
        },
        "tags": ["production", "v1"],
    },
)

response.raise_for_status()
print(response.json())

Step 3: TypeScript example

Same approach for TypeScript users.
const apiKey = "YOUR_API_KEY";

const response = await fetch("https://api.braintrust.dev/v1/function", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${apiKey}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    project_id: "your-project-id",
    function_data: {
      type: "scorer",
      name: "my-scorer",
    },
    tags: ["production", "v1"],
  }),
});

if (!response.ok) {
  throw new Error(`Request failed: ${response.status} ${response.statusText}`);
}

const data = await response.json();
console.log(data);