Agent skill

Function Dev

by butterbase-ai in butterbase-ai/butterbase-skills

A skill your agent uses when developing, deploying, or debugging Butterbase serverless functions, or when the user needs to add backend logic like webhooks, scheduled jobs, or custom API endpoints

MITAuto-check passedBackend & APIs

Install Function Dev

skills CLI
$ npx skills add butterbase-ai/butterbase-skills --skill function-dev -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install butterbase-ai/butterbase-skills function-dev --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/butterbase-ai/butterbase-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/function-dev .claude/skills/function-dev && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
function-dev
GitHub stars
534
Token cost
~2.8k tokens
SKILL.md length
619 words
Files
1
Skills in repo
39
Repo updated
First seen
Licence
MIT

At a glance

A skill your agent uses when developing, deploying, or debugging Butterbase serverless functions, or when the user needs to add backend logic like webhooks, scheduled jobs, or custom API endpoints

  • Works in 8 steps: Handler Signature → Trigger Types → Database Access → …
  • Debugging Butterbase serverless functions
  • SKILL.md covers 1. Handler Signature, 2. Trigger Types, 3. Database Access and 4. Environment Variables, plus 4 more sections
  • Reaches api.openai.com and api.butterbase.ai; needs OPENAI_API_KEY and WEBHOOK_SECRET

What it does

Function Dev is an agent skill from butterbase-ai/butterbase-skills. Use when developing, deploying, or debugging Butterbase serverless functions, or when the user needs to add backend logic like webhooks, scheduled jobs, or custom API endpoints

Its SKILL.md is about 2.8k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Backend & APIs, covering Serverless, Webhooks and REST APIs. The repository describes itself as: Plugin for Butterbase.ai. The licence is MIT.

When your agent uses it

  • Debugging Butterbase serverless functions
  • The user needs to add backend logic like webhooks
  • Custom API endpoints

Example prompts

  • “/function-dev”

Requirements

  • A credential in OPENAI_API_KEY
  • A credential in WEBHOOK_SECRET

Workflow steps

8 steps, taken from the step headings in SKILL.md.

  1. Handler Signature
  2. Trigger Types
  3. Database Access
  4. Environment Variables
  5. Complete Working Examples
  6. Testing & Debugging
  7. Common Mistakes
  8. Quick Reference

What it can do on your machine

Read from SKILL.md and the folder at commit aa8ae69. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are typescript and json).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Hosts in commands or code, which the agent is likely to contact:

    • api.openai.com
    • api.butterbase.ai

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names these keys or tokens, usually read from environment variables:

    • OPENAI_API_KEY
    • WEBHOOK_SECRET

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Function Dev loads about 2.8k tokens when it runs. Until then it costs about 47 tokens; SKILL.md has 619 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~47
When it runs · the whole SKILL.md, loaded when a task matches
~2.8k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from butterbase-ai/butterbase-skills at commit aa8ae69, republished under its MIT licence (© butterbase-ai). 619 words, ~2,773 tokens.

Download SKILL.mdSave it as .claude/skills/function-dev/SKILL.md (or your agent's skills folder).
name
function-dev
description
Use when developing, deploying, or debugging Butterbase serverless functions, or when the user needs to add backend logic like webhooks, scheduled jobs, or custom API endpoints

Serverless Function Development on Butterbase

Guide for developing and deploying serverless functions on Butterbase's Deno runtime. Covers handler signatures, trigger types, database access, environment variables, and testing.


1. Handler Signature

Every function exports a single handler function with this signature:

typescript
export async function handler(
  request: Request,
  context: {
    db: PostgresClient,                                  // RLS-aware DB client
    env: Record<string, string>,                         // env vars set on the function
    user: { id: string } | null,                         // present for HTTP+auth:required; null for cron
    waitUntil: (p: Promise<unknown>) => void,            // background work after Response (≤30s)
    idempotency: {
      claim: (key: string, opts?: { scope?: string; ttlSeconds?: number }) => Promise<boolean>
    }                                                    // atomic dedup for webhook retries
  }
): Promise<Response>

CRITICAL: The handler MUST return new Response() (Web API standard). Do NOT return plain objects.

Correct:

typescript
return new Response(JSON.stringify({ message: "ok" }), {
  status: 200,
  headers: { "Content-Type": "application/json" }
});

Wrong (will fail):

typescript
return { status: 200, body: "ok" };  // NOT a Response object!

2. Trigger Types

HTTP Trigger

Invoke the function via an HTTP request.

json
{
  "trigger": {
    "type": "http",
    "config": { "method": "POST", "path": "/my-endpoint", "auth": "required" }
  }
}

Auth options:

  • "required" — request must include a valid JWT; ctx.user is always set
  • "optional" — JWT is parsed if present; ctx.user may be null
  • "none" — public endpoint; no auth needed; ctx.user is always null

Cron Trigger

Execute the function on a schedule.

json
{
  "trigger": {
    "type": "cron",
    "config": { "schedule": "0 9 * * *", "timezone": "UTC" }
  }
}

Uses standard 5-field cron expressions:

  • "*/5 * * * *" — every 5 minutes
  • "0 0 * * 0" — weekly, Sunday at midnight
  • "0 3 * * *" — daily at 3am UTC
  • "0 9 * * 1-5" — weekdays at 9am

Cron functions run as butterbase_service (RLS bypassed). ctx.user is always null.


WebSocket Trigger

Fire when a connected client sends a matching event over the realtime WebSocket.

json
{
  "trigger": {
    "type": "websocket",
    "config": { "event": "chat-message" }
  }
}

Fires when client sends matching event via realtime WebSocket connection. The request body contains the event payload sent by the client.


S3 Upload Trigger (placeholder — not yet implemented)
json
{
  "trigger": {
    "type": "s3_upload",
    "config": { "prefix": "uploads/", "contentTypes": ["image/*"] }
  }
}

3. Database Access

Use ctx.db.query(sql, params) for all database queries. Always use parameterized queries to prevent SQL injection — NEVER use string interpolation.

typescript
// Always use $1, $2 placeholders — never string interpolation
const { rows } = await ctx.db.query(
  'SELECT * FROM posts WHERE author_id = $1',
  [ctx.user.id]  // params array
);
SELECT
typescript
const { rows } = await ctx.db.query(
  'SELECT * FROM posts WHERE author_id = $1 AND published = true',
  [ctx.user.id]
);
INSERT
typescript
await ctx.db.query(
  'INSERT INTO logs (event, user_id) VALUES ($1, $2)',
  ['page_view', ctx.user.id]
);
UPDATE
typescript
await ctx.db.query(
  'UPDATE posts SET title = $1, updated_at = now() WHERE id = $2 AND author_id = $3',
  [newTitle, postId, ctx.user.id]
);
RLS Behavior by Invocation Type
InvocationRoleRLS
End-user JWTbutterbase_userEnforced — ctx.db queries filtered by policies
API key (bb_sk_)butterbase_serviceBypassed — sees all data
Cron triggerbutterbase_serviceBypassed — sees all data

4. Environment Variables

  • Set at deploy time: pass envVars parameter to deploy_function
  • Update without redeploying: use update_function_env
  • Access in handler: ctx.env.VARIABLE_NAME
  • Encrypted at rest: values are never exposed in logs or API responses

Common uses: API keys, webhook secrets, external service URLs.

typescript
const apiKey = ctx.env.OPENAI_API_KEY;
const webhookSecret = ctx.env.WEBHOOK_SECRET;
const serviceUrl = ctx.env.EXTERNAL_SERVICE_URL;

5. Complete Working Examples

Example 1 — Protected API Endpoint (auth: required)

Returns the authenticated user's posts.

typescript
export async function handler(req, ctx) {
  const { rows } = await ctx.db.query(
    'SELECT id, title, created_at FROM posts WHERE author_id = $1 ORDER BY created_at DESC',
    [ctx.user.id]
  );
  return new Response(JSON.stringify(rows), {
    headers: { "Content-Type": "application/json" }
  });
}

Deploy:

deploy_function(
  app_id,
  name: "my-posts",
  code: ...,
  trigger: {
    type: "http",
    config: { method: "GET", path: "/my-posts", auth: "required" }
  }
)

Example 2 — Webhook Receiver (auth: none)

Accepts an incoming webhook, validates the signature, and stores the event.

typescript
export async function handler(req, ctx) {
  const body = await req.json();
  const signature = req.headers.get("x-webhook-signature");
  // Validate signature against ctx.env.WEBHOOK_SECRET
  await ctx.db.query(
    'INSERT INTO webhook_events (event_type, payload) VALUES ($1, $2)',
    [body.type, JSON.stringify(body)]
  );
  return new Response("ok", { status: 200 });
}

Deploy with: trigger: { type: "http", config: { method: "POST", path: "/webhook", auth: "none" } }


Example 3 — Cron Cleanup Job

Deletes expired sessions on a nightly schedule.

typescript
export async function handler(req, ctx) {
  const result = await ctx.db.query(
    "DELETE FROM sessions WHERE expires_at < now() RETURNING id"
  );
  return new Response(JSON.stringify({ deleted: result.rowCount }), {
    headers: { "Content-Type": "application/json" }
  });
}

Deploy with: trigger: { type: "cron", config: { schedule: "0 3 * * *" } }


Show full SKILL.md (259 more words)Show less
Example 4 — External API Call

Proxies a request to an external AI service using a stored API key.

typescript
export async function handler(req, ctx) {
  const { prompt } = await req.json();
  const response = await fetch("https://api.openai.com/v1/chat/completions", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "Authorization": `Bearer ${ctx.env.OPENAI_API_KEY}`
    },
    body: JSON.stringify({
      model: "gpt-4",
      messages: [{ role: "user", content: prompt }]
    })
  });
  const data = await response.json();
  return new Response(JSON.stringify(data), {
    headers: { "Content-Type": "application/json" }
  });
}

Deploy with envVars: { OPENAI_API_KEY: "sk-..." } and trigger: { type: "http", config: { method: "POST", auth: "required" } }


Example 5 — Error Handling Pattern

Always wrap handler logic in try/catch and return a proper error Response.

typescript
export async function handler(req, ctx) {
  try {
    const { id } = await req.json();
    const { rows } = await ctx.db.query(
      'SELECT * FROM items WHERE id = $1',
      [id]
    );
    if (rows.length === 0) {
      return new Response(JSON.stringify({ error: "Not found" }), {
        status: 404,
        headers: { "Content-Type": "application/json" }
      });
    }
    return new Response(JSON.stringify(rows[0]), {
      status: 200,
      headers: { "Content-Type": "application/json" }
    });
  } catch (err) {
    return new Response(JSON.stringify({ error: "Internal server error" }), {
      status: 500,
      headers: { "Content-Type": "application/json" }
    });
  }
}

6. Testing & Debugging

The standalone tools deploy_function and invoke_function are unchanged. Everything else (logs, env updates, listing, deletion) is handled by manage_function with an action parameter.

Invoke a Function
invoke_function(
  app_id: "app_abc123",
  function_name: "my-function",
  method: "POST",
  body: { key: "value" }
)

Returns the full HTTP response (status, headers, body, duration_ms). Use this immediately after deploying to verify behavior.

View Error Logs
manage_function(
  app_id: "app_abc123",
  action: "get_logs",
  function_name: "my-function",
  level: "error"
)

Returns recent invocations with errors, stack traces, and captured console.log/warn/error output.

View All Logs
manage_function(
  app_id: "app_abc123",
  action: "get_logs",
  function_name: "my-function",
  limit: 100,
  since: "2026-01-15T00:00:00Z"
)

Filters: limit (default 100), since (ISO timestamp), level ("error" or "all").

List Functions & Metrics
manage_function(app_id: "app_abc123", action: "list")

Returns each function's name, trigger, URL, status, and metrics (invocationCount, errorRate, avgDuration, lastInvoked).


7. Common Mistakes

MistakeFix
Returning plain object instead of ResponseAlways use new Response(JSON.stringify(data), { headers: {...} })
SQL injection via string interpolationUse parameterized queries: $1, $2 placeholders
Not wrapping in try/catchAlways catch errors and return a Response with error status
Forgetting async on handlerHandler must be async function handler(...)
Exceeding timeout (30s default)Increase timeoutMs in deploy_function or optimize the function
Not setting Content-Type headerAlways include "Content-Type": "application/json" for JSON responses

8. Quick Reference

Deploy a Function
deploy_function(
  app_id: "app_abc123",
  name: "my-function",
  code: "export async function handler(req, ctx) { ... }",
  trigger: { type: "http", config: { method: "POST", auth: "required" } },
  envVars: { MY_SECRET: "value" },
  timeoutMs: 30000,       // default: 30s, max: 300s
  memoryLimitMb: 128      // default: 128MB
)
Update Env Vars (without redeploying)
manage_function(
  app_id: "app_abc123",
  action: "update_env",
  function_name: "my-function",
  env: { MY_SECRET: "new-value", DELETE_ME: null }   // null deletes the key
)
Delete a Function
manage_function(
  app_id: "app_abc123",
  action: "delete",
  function_name: "my-function"
)
Invocation URL Pattern
https://api.butterbase.ai/v1/{app_id}/fn/{function-name}

For HTTP triggers, this is the URL clients call directly.


If a docs/butterbase/00-state.md exists in the working directory, prefer invoking via /butterbase-skills:journey-functions so the journey orchestrator stays in sync.

© butterbase-ai, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in skills/function-dev of butterbase-ai/butterbase-skills.

Open the folder on GitHubat commit aa8ae69

Compare with similar skills

Function Dev next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Function Dev compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Function Dev this skillbutterbase-ai/butterbase-skills534—~2.8kAutomated safety check: PassMIT
Upstash Qstashdavila7/claude-code-templates32k5 repos~597Automated safety check: PassMIT
NubaseOtterMind/Nubase623—~2.2kAutomated safety check: NotesApache-2.0
Polylith Base CreationDavidVujic/python-polylith553—~757Automated safety check: PassMIT
Frappe App Devfrappe/skills146—~943Automated safety check: PassNone
Workspace APIfriday-platform/friday-studio104—~9.3kAutomated safety check: NotesCustom licence

Similar skills

  • Upstash Qstash

    davila7/claude-code-templates

    Upstash QStash expert for serverless message queues, scheduled jobs, and reliable HTTP-based task delivery without managing infrastructure.

    32k GitHub starsUsed in 5 repos~597 tokens
    Backend & APIsAuto-check passed
  • Nubase

    OtterMind/Nubase

    A skill your agent uses when the user mentions Nubase broadly, wants a backend for an AI-generated app, or needs to deploy/publish generated code online — across Database, Auth, Storage, Assets…

    623 GitHub stars~2.2k tokensUpdated 10 days ago
    Backend & APIsAuto-check: notes
  • Polylith Base Creation

    DavidVujic/python-polylith

    Create a Polylith base with poly create base — the entry point of a deployable application (HTTP API, CLI, message-queue consumer, AWS Lambda handler, GCP Cloud Function, scheduled job).

    553 GitHub stars~757 tokensUpdated 3 days ago
    Backend & APIsAuto-check passed
  • Frappe App Dev

    frappe/skills

    Builds full-stack Frappe Framework applications end-to-end. An agent skill from frappe/skills.

    146 GitHub stars~943 tokensUpdated 7 days ago
    Backend & APIsAuto-check passed
  • Workspace API

    friday-platform/friday-studio

    Create, list, update, delete, and clean up workspaces via the daemon HTTP API at $FRIDAYDURL.

    104 GitHub stars~9.3k tokensUpdated 1 mo ago
    Backend & APIsAuto-check: notes
  • Neon Functions

    neondatabase/agent-skills

    Official

    Long-running, serverless Node.js HTTP functions deployed onto your Neon branch, with DATABASEURL injected automatically and compute that runs next to your data.

    100 GitHub stars~12k tokensUpdated yesterday
    Backend & APIsAuto-check: notes

More from butterbase-ai/butterbase-skills

All 39 skills in this repo
  • AI

    butterbase-ai/butterbase-skills

    A skill your agent uses when calling the app's AI gateway from agent tools — chat completions, embeddings, listing models, configuring defaults or BYOK, reading token/cost usage

    534 GitHub stars~1.1k tokensUpdated 2 days ago
    Auto-check passed
  • Auth Setup

    butterbase-ai/butterbase-skills

    A skill your agent uses when configuring OAuth providers (Google/GitHub/Apple/X/etc.), setting up post-login auth hooks, tuning JWT lifetimes, or generating service API keys

    534 GitHub stars~2.2k tokensUpdated 2 days ago
    Auto-check passed
  • Build App

    butterbase-ai/butterbase-skills

    A skill your agent uses when building a new Butterbase app from scratch, creating a full-stack application, or when the user asks to set up a complete backend with database, auth, and deployment

    534 GitHub stars~4.9k tokensUpdated 2 days ago
    Auto-check passed
  • Contributing

    butterbase-ai/butterbase-skills

    A skill your agent uses when contributing to the Butterbase codebase, adding new MCP tools, creating API routes, writing migrations, or understanding the monorepo architecture

    534 GitHub stars~1.5k tokensUpdated 2 days ago
    Auto-check passed
  • Debug Rls

    butterbase-ai/butterbase-skills

    A skill your agent uses when users report access denied errors, see wrong data, RLS policies are not working, or when troubleshooting Row-Level Security issues in Butterbase

    534 GitHub stars~3.5k tokensUpdated 2 days ago
    Auto-check passed
  • Deploy Frontend

    butterbase-ai/butterbase-skills

    A skill your agent uses when deploying a frontend (React, Next.js, or static HTML) to a live URL on Butterbase, or when troubleshooting deployment issues like MIME type errors or blank pages

    534 GitHub stars~2.8k tokensUpdated 2 days ago
    Auto-check passed

Categories

Questions about Function Dev

What does Function Dev do?

A skill your agent uses when developing, deploying, or debugging Butterbase serverless functions, or when the user needs to add backend logic like webhooks, scheduled jobs, or custom API endpoints. Function Dev is an agent skill from butterbase-ai/butterbase-skills.

When should I use Function Dev?

Function Dev fits situations like: debugging Butterbase serverless functions; the user needs to add backend logic like webhooks; custom API endpoints.

How do I install Function Dev in Claude Code?

Run `npx skills add butterbase-ai/butterbase-skills --skill function-dev -a claude-code`. Or copy the skill folder (skills/function-dev in butterbase-ai/butterbase-skills) into .claude/skills/function-dev in your project. Claude Code loads it when a task matches its description.

How do I install Function Dev in Codex?

Run `npx skills add butterbase-ai/butterbase-skills --skill function-dev -a codex`. Or copy the skill folder (skills/function-dev in butterbase-ai/butterbase-skills) into .agents/skills/function-dev in your project. Codex loads it when a task matches its description.

Can I use Function Dev in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add butterbase-ai/butterbase-skills --skill function-dev -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/function-dev, .gemini/skills/function-dev, .github/skills/function-dev and .opencode/skills/function-dev in your project.

What does Function Dev need to run?

Going by SKILL.md and its folder, Function Dev needs credentials named OPENAI_API_KEY and WEBHOOK_SECRET. Our summary lists: A credential in OPENAI_API_KEY; A credential in WEBHOOK_SECRET.

Does Function Dev access the network?

SKILL.md names 2 domains. In commands or code: api.openai.com and api.butterbase.ai; the agent is likely to contact these when it follows the instructions. This is read from the text; nothing was executed.

Is Function Dev safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Function Dev use?

Function Dev is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Function Dev use?

About 2.8k tokens (SKILL.md is roughly 11k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Function Dev?

Skills that share tags, products or a category with Function Dev: Upstash Qstash (davila7/claude-code-templates, 32k stars), Nubase (OtterMind/Nubase, 623 stars), Polylith Base Creation (DavidVujic/python-polylith, 553 stars) and Frappe App Dev (frappe/skills, 146 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Function Dev?

butterbase-ai (a GitHub organization) maintains it in butterbase-ai/butterbase-skills, which has 534 GitHub stars. The repository holds 39 skills in this directory. The repository was last updated on October 5, 2026.

Source: butterbase-ai/butterbase-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.