All primitives

Compute / your logic, managed

Custom Functions

Make your application do something unique.

The idea

Put your business rules in one focused function.

Imagine building an application that calculates shipping prices. The price depends on weight, distance, delivery speed, and discounts.

That is business logic specific to your application. A Custom Function lets you run it without managing a traditional application server.

Application blip

Shipping Calculator

Interactive demo
Shipping details

Adjust the inputs to see the business logic recalculate.

From 0.1 to 70 kilograms.

Distance changes the zone fee.

Choose standard, express, or overnight.

Try WELCOME10 for 10% off this demo quote.

Change an input to recalculate the estimate.

Behind the scenes

A small function turns an action into an answer.

  1. User action
  2. Custom Function
  3. Business logic
  4. Result

The app sends validated inputs to a function. It applies your business rules and returns a structured result for the rest of the application to use.

What could you build?

  • Pricing engines
  • Payment workflows
  • Third-party integrations
  • Data transformations
  • Custom automation

Implementation notes

  • Keep functions focused on one business rule.
  • Validate inputs before calculating or calling other services.
  • Return structured results the rest of your app can use.

Implementing it

With a coding agent

Ask your agent to add custom logic

Agent setup (mock link)

Copy this prompt, fill in the bracketed details, and paste it into your coding agent. It describes the goal, the business rule, and the guardrails.

Bracketed text marks details only you can fill in. 896 / 6,000 characters.

Fill in:APP OR PRODUCTBUSINESS RULE OR TASKINPUTS AND TYPESSTRUCTURED RESULTRULES, LIMITS, AND EDGE CASESINVALID OR MISSING INPUTTHIRD-PARTY SERVICEWHERE IN THE APPIMPORTANT EXAMPLES, EDGE CASES, AND FAILURES

Good foundation · 65/100

Traditional SDK / API

Calculate shipping with a custom function

TypeScript
const destinationFees = { "new-york": 6, chicago: 4, "los-angeles": 7.5 }
const deliveryFees = { standard: 0, express: 4.5, overnight: 9 }

export function calculateShipping(input: {
  weightKg: number
  destination: keyof typeof destinationFees
  delivery: keyof typeof deliveryFees
  discountCode?: string
}) {
  const subtotal = 6.5 + input.weightKg * 1.5 + destinationFees[input.destination] + deliveryFees[input.delivery]
  const discount = input.discountCode?.trim().toUpperCase() === "WELCOME10" ? subtotal * 0.1 : 0
  return Math.round((subtotal - discount) * 100) / 100
}

Key takeaway

Custom Functions let you implement the logic that makes your application different from everyone else’s.

Next primitive

Document Database