Connections, actions and models
Sealed connections, Slack, email and HTTP actions sent only after the merge, and a model gateway with per-run budgets and cost.
The gateway (/gateway/v1, and /llm/v1 for models) holds what agents use through Forkbase instead of holding it
themselves:
- Connections: each credential once (Slack, SMTP, an HTTP API, a model provider, an MCP server), sealed, by name.
- Actions: a Slack post, an email or an HTTP request that a run queues in its world and Forkbase sends only after the run merges: never for a rejected, discarded or expired run, and checked against the policy before.
- Slack approvals: held runs posted to a channel, where a linked team member approves or rejects them as themself.
- Models: calls to Anthropic, OpenAI or an OpenAI-compatible server with the run's token, within the policy's models and budgets, with tokens and cost counted on the run.
Every route takes the service key. In the dashboard, admins manage connections (Settings, Connections) and anyone sees actions (Agents, Actions); operators may retry or dismiss a failed action.
Connections
curl -X POST $FORKBASE_URL/gateway/v1/connections -H "apikey: $SERVICE_KEY" -H "content-type: application/json" -d '{
"name": "slack", "kind": "slack",
"secret": { "bot_token": "xoxb-..." },
"meta": { "default_channel": "#claims" }
}'A name is a lowercase letter then 1 to 40 lowercase letters, digits or _. Each kind takes a fixed set of fields;
an unknown field is refused, so a secret under the wrong name is never stored in the clear.
kind | secret | meta |
|---|---|---|
slack | bot_token (chat:write), signing_secret?, app_token? (approvals) | team_id?, default_channel?, approvals_channel?, base_url? (https://slack.com/api) |
smtp | password? | host, port, from (Ops <ops@yourco.com>), username?, tls? (starttls default, tls, none) |
http | header_value (Bearer ...) | base_url, header_name? (Authorization), allow_private? |
anthropic | api_key | base_url? (https://api.anthropic.com), allow_private? |
openai | api_key | base_url? (https://api.openai.com), organization?, allow_private? |
openai_compatible | api_key? | base_url, organization?, allow_private? |
mcp | bearer_token? | url, allow_private? |
- Sealed. Secret fields are sealed with a key made from the instance's secret. No response, log, ledger entry
or audit row holds them: reads show
secret_hint,"••••"and the last 4 characters. - Read:
GET /connectionslists them withused_by(bound functions, policies whosehttp.requestactions name them, actions not sent yet that name them) andlast_used_at. - Change:
PATCH /connections/{name} {meta?, secret?}: meta fields given replace theirs (nullremoves one); asecretreplaces the whole secret. Actions read a connection when they are sent, so a rotated key is used at once. - Delete:
DELETE /connections/{name}answers 409 withused_bywhile something uses it, unless?force=true. - Test:
POST /connections/{name}/testmakes one cheap call (Slackauth.test, SMTPNOOP,HEAD base_url,GET /v1/models, MCPinitialize) within 10 s and answers{ok, detail}. The detail never repeats what the far end sent beyond a status. - Private addresses. Before a request, its host is resolved and every address checked; loopback, private,
link-local (
169.254.169.254), unique-local and similar addresses are refused, and the request goes to the checked address (a second lookup can't move it).allow_private: trueon a connection (a local Ollama, a service on your network) orgateway.allow_private_urlslets them through. Redirects are never followed.
Functions
A function sees a connection only if it is bound to it: deploy with "connections": ["slack", "billing"] and each
attempt gets FORKBASE_CONNECTION_SLACK, FORKBASE_CONNECTION_BILLING: the connection's fields (secret and meta,
with kind and base_url) as JSON, read when the attempt starts. An unbound connection isn't there.
const billing = JSON.parse(process.env.FORKBASE_CONNECTION_BILLING!);
await fetch(`${billing.base_url}/refunds`, { method: "POST", headers: { [billing.header_name ?? "Authorization"]: billing.header_value } });Binding hands the key to the function's code: it is trusted code, run as this server's user, not a sandbox. An agent outside the server (an MCP client, a remote agent with a run token) never gets a key this way. Prefer actions, which leave the key in Forkbase.
Actions
In its world, an agent queues an action with NOTIFY ON MERGE on one of three channels:
notify on merge "slack.post", '{"channel": "#claims", "text": "Claim 42 approved"}';
notify on merge "email.send", '{"to": ["ada@yourco.com"], "subject": "Claim 42", "text": "Approved."}';
notify on merge "http.request", '{"connection": "billing", "method": "POST", "path": "/refunds", "body": {"claim": 42}}';| Channel | Payload | Result |
|---|---|---|
slack.post | channel, text, blocks?, thread_ts?, connection? | {ts, channel} |
email.send | to (an address or up to 20), subject, text, html?, connection? | {message_id} |
http.request | connection, path, method? (POST), body?, headers? | {status, body} (body cut at 4 KB) |
connectiondefaults to the only connection of that kind (slack,smtp); none or several fail the action.http.requestalways names itshttpconnection and reaches only paths under itsbase_url: no other host, no.., no//. It carriesIdempotency-Key: <effect id>, and the connection's header, which a payload can't set.- Email addresses are taken strictly (
local@domain, no names, brackets, commas or line breaks); a subject has no line break. - When. Nothing goes out while the run is open or held. When it merges, the engine releases the effect and
Forkbase keeps it as an action, sent within a second or two. A rejected, discarded or expired run's actions are
dropped (a rejected one's ledger says
effect.dropped). Every action is also aneffect.<channel>event, as before. - Retries. A server error, a timeout or a 429 is tried again after 1 min, 5 min, 30 min, 2 h and 6 h
(
gateway.retry_waits_s); a 429'sRetry-Afteris used instead, up to an hour. A refusal (a 4xx, Slack'schannel_not_found, an invalid payload, a missing connection) fails it at once.POST /actions/{id}/retrysends a failed one again with its tries started over;POST /actions/{id}/dismisssets it aside. - At least once. If the server stops between the call and its record, the action is tried again: a Slack post or
an email may then arrive twice; an HTTP receiver can drop the repeat by its
Idempotency-Key. - Undo. Undoing a merged run cancels its actions not sent yet. The ones already sent stay sent: the undo answer
lists them (
actions_sent), so whoever undid it can follow up. - On the run.
GET /agents/v1/runs/{id}hasactions: before the merge, what it queued with a one-linesummaryand anyproblem; after, each action'sstatus,attemptsandresult. The approval page and the dashboard's run view list them, so approving a run is approving what it sends. The ledger recordsaction.queued,action.done,action.retry,action.failedandeffect.dropped. GET /gateway/v1/actions?status=&run=&limit=lists actions, newest first;statusispending,running,done,failed,dismissedorcancelled.
Actions in policies
A policy file's [forkbase] table holds rules Forkbase checks itself (the engine never sees them):
# policies/claims.toml
max_rows = 20
[forkbase]
invalid_effects = "hold" # the default; "allow" lets an invalid payload merge (its action then fails)
[forkbase.actions]
"slack.post" = ["#claims", "#ops"]
"email.send" = ["*@yourco.com", "finance@partner.com"]
"http.request" = ["billing:POST /refunds", "billing:* /refunds/*"]When a run is proposed, every action it queued is checked. An invalid payload, or a target its channel's list
doesn't name, holds the run for a person with the reason (slack.post to #random isn't in the policy's actions); approving it merges no more than what was held. Without [forkbase.actions] every target is allowed;
with it, a channel it doesn't list allows none. Slack channels match as written (case aside), emails by address or
*@domain, HTTP requests as <connection>:<METHOD> <path> (* for any method, a trailing * for a path prefix,
the query left out). The engine's own rules (max_effects, effects_per_hour, review_channels) still apply.
Turning actions off
gateway.actions is auto (the default), on or off. With auto, Forkbase doesn't send these three channels
while a webhook listens for them (*, effect.* or the channel's own event): a consumer of your own would send them
twice. Effects queued before the first start of a version with actions are never sent. With actions off, the three
channels are events only, as other channels are.
Slack approvals
A Slack app of your own posts every held run to a channel with Approve and Reject. A click decides as the
team member that Slack account is linked to: the same approve and reject as the dashboard, with the member's email as
the run's decided_by and an entry in the audit log. It uses Slack's Socket Mode, so the server needs no public URL.
- Make the app.
GET /gateway/v1/slack/manifest?name=Forkbase(or Settings, Slack, Download the manifest) is a manifest for Create New App, From a manifest at api.slack.com/apps: a bot withchat:write,chat:write.publicandusers:read, interactivity on, Socket Mode on. Install it to your workspace. - Give Forkbase its tokens. A
slackconnection withbot_token(the Bot User OAuth Token,xoxb-),app_token(an App-Level Token withconnections:write,xapp-) andapprovals_channel(#approvals, or a channel id). Invite the app to the channel if it is private. - Link people. Each member presses Get my link code in Settings, Slack (
POST /gateway/v1/slack/link, which needs a member's own sign-in), clicks Approve or Reject on any message, and pastes the code when Slack asks. A code works once, for 15 minutes.
What it checks:
- Only accounts of the app's own workspace decide (not Slack Connect users), and never guests: linking asks Slack
(
users.info) and refuses restricted accounts. - Only enabled operators and admins decide. A viewer can link, and their click is refused with a note only they see. A disabled or removed member's link stops working at once.
- Reject asks why; the reason is kept with the run.
- Every click, link and refusal goes in the audit log (method
SLACK). - A message lists the tables and row counts, the actions sent on merge, the policy's reasons and the cost so far. When a run has more than fits (over 10 tables or actions, or a long action), the message offers only Open in Forkbase, so nobody approves what they couldn't see.
- Each held run is posted once, whichever server sees it first; once it is decided anywhere (Slack, the dashboard, an approval link) or expires, its message is replaced with what happened and who decided, without buttons.
- Slack may send an interaction twice; each is handled once.
Without app_token, held runs are still posted, with only Open in Forkbase. With an approvals channel set, the
old incoming webhook (agents.slack_webhook_url) isn't sent too.
| Route (service key; admins in the dashboard) | |
|---|---|
GET /gateway/v1/slack | the app's state (connected), its channel, the linked accounts, the latest messages |
GET /gateway/v1/slack/manifest?name= | the app's manifest |
POST /gateway/v1/slack/link | the calling member's link code ({code, expires_at, role, decides}); any member may call it |
POST /gateway/v1/slack/test | a message to the approvals channel |
DELETE /gateway/v1/slack/users/{slack_user} | unlinks a Slack account |
Tools
Agents call the tools of other MCP servers through Forkbase: GitHub, Linear, an internal service. Forkbase holds the server's token, shows each agent only the tools it was given, pins every tool's definition, and calls a tool that changes things only after the agent's run merges.
- Add the server. A connection of kind
mcpwith itsurl(Streamable HTTP) and, if it needs one, itsbearer_token. A private address is refused unless the connection setsallow_private. - Sync it.
POST /gateway/v1/mcp-servers/{name}/sync(or Agents, Tools, Sync now) lists its tools; Forkbase syncs each server again every 6 hours by itself. A tool is named<server>__<name>(github__create_issue). - Review each tool. A new tool starts turned off, as a write tool. An admin reads its definition, says whether it
reads or writes (
kind), and approves it:PATCH /gateway/v1/tools/{id} {"approve": true, "kind": "read", "enabled": true}. - Give it to agents.
PUT /gateway/v1/agents/{name}/tools {"tools": ["github__create_issue", ...]}. An agent's policy may narrow what it can use further:
[forkbase]
tools = ["github__*", "linear__search_issues"] # *, an id, or a prefix ending in *Pinning. Approving copies the definition (its description, schemas and annotations, hashed over canonical JSON),
and agents only ever see that copy. When a sync finds a tool's definition changed upstream, the tool is turned off:
it leaves every agent's list and calls to it fail until an admin compares the two and approves the new one. A
description is text the model reads, so a server can't slip new instructions to your agents. A tool the server stops
listing is gone and can't be called.
Read and write. A read tool is called at once. A write tool takes one more argument, forkbase_run: the caller's
own open run. The call is queued in that run's world as an effect on channel tool.<id> (arguments up to 64 KB) and
answers {"staged": true}; the actions' executor makes the call only once the run merges, with the actions' retries,
and never for a rejected or discarded run. It shows on the Actions page like any other effect. The server's own
readOnlyHint is only a hint: the kind an admin set decides.
Checks. Each call checks that the tool is assigned to the agent, that its policy allows it, and that it is
present, approved at its current definition and on. The executor checks again at merge, including that the run's
agent was given the tool, so an agent can't reach one by writing NOTIFY ON MERGE 'tool.x' itself. A policy holds a
run that queued a tool it doesn't allow. Every call, read or write, is a tool entry in the run's ledger with its
arguments. Tokens never leave Forkbase: not in definitions, results or the ledger.
Over MCP. An agent connected to Forkbase's /mcp sees its tools beside Forkbase's own. With more than 20, it sees
search_tools (query: the best 8 by name and description) and call_tool (name, arguments) instead.
| Route (service key; admins in the dashboard) | |
|---|---|
GET /gateway/v1/mcp-servers | each mcp connection: last sync, error, tool counts |
POST /gateway/v1/mcp-servers/{name}/sync | sync now: {tools, new, changed, gone} |
GET /gateway/v1/tools?server= | every tool: state (new, approved, changed, gone), kind, enabled, its definition (and the approved one when changed), its agents |
GET /gateway/v1/tools/{id} | one tool |
PATCH /gateway/v1/tools/{id} | approve, kind (read or write), enabled (turning on needs the current definition approved) |
GET /gateway/v1/agents/{name}/tools | an agent's tools |
PUT /gateway/v1/agents/{name}/tools | sets them: {"tools": [...]} |
Tool arguments can be limited per tool by guardrails: see Agents, Guardrails.
Models
Agents call models through Forkbase (/llm/v1) with their run's token instead of a provider's key. Forkbase
checks the policy's models and budgets, sends the call to the provider with the connection's key, passes the answer
back as the provider sent it (streams included), and counts its tokens and cost on the run.
| Route | Format | Connections |
|---|---|---|
POST /llm/v1/messages | Anthropic Messages | anthropic |
POST /llm/v1/chat/completions | OpenAI Chat Completions | openai, openai_compatible (OpenRouter, Ollama, vLLM, Groq...) |
GET /llm/v1/models | the models the caller may name |
Point the provider's SDK at Forkbase and use the run's token (FORKBASE_RUN_TOKEN in a job) as its key:
import Anthropic from "@anthropic-ai/sdk";
const claude = new Anthropic({ baseURL: `${process.env.FORKBASE_URL}/llm`, apiKey: process.env.FORKBASE_RUN_TOKEN });
await claude.messages.create({ model: "anthropic/claude-haiku-5-5", max_tokens: 512, messages: [...] });from openai import OpenAI
llm = OpenAI(base_url=f"{os.environ['FORKBASE_URL']}/llm/v1", api_key=os.environ["FORKBASE_RUN_TOKEN"])
llm.chat.completions.create(model="openrouter/meta-llama/llama-4-scout", messages=[...])- Model.
connection/model(anthropic/claude-sonnet-5-5), or the model alone when only one connection speaks the route's format. Forkbase sends the provider the model alone, and answers withx-forkbase-model: connection/model. - Who. A run's token (
fbr_,x-api-keyorAuthorization: Bearer) while the run is open: a held or decided run calls no model (409run_not_open). An agent's own token (fba_) bills the agent with no run, unless its policy hasrequire_run. Any other key is refused (403). A job's function uses its run's token. - Passed through. The body as sent (except
model, a loweredmax_tokens, andstream_options.include_usageasked of an OpenAI stream),anthropic-versionandanthropic-beta. The caller's own credentials never reach the provider. A provider's error comes back with its status and body. - Timeouts. 120 s to the provider's first byte, 15 min for a whole call. Private addresses are refused as for
other connections (
allow_privatefor a local Ollama). - Errors are in the route's format (
{type: "error", error: {type, message}}or{error: {message, type}}) with acode:model_not_allowed403,budget_exhausted402,run_required403,run_not_open409,format_mismatch400,provider_unreachable502,provider_timeout504.
Guardrails in the run's policy also apply here: see Agents, Guardrails.
Budgets in policies
# policies/claims.toml
[forkbase]
models = ["anthropic/claude-haiku-5-5", "anthropic/claude-sonnet-5-5", "local/*"]
max_cost_usd = 0.50 # per run
max_tokens = 200000 # per run, input and output
agent_daily_cost_usd = 20 # per agent, per UTC day, its runs and its own token
over_budget = "hold" # at propose: "hold" (the default), "reject" or "allow"
require_run = true # the agent's own token may not call modelsmodelslistsconnection/model,connection/*, a model alone (on any connection) or*. Absent: any.- Before a call, the run's spend plus what its calls in flight reserved (their
max_tokensat the model's price) must be undermax_cost_usd, its tokens undermax_tokens, and the agent's day underagent_daily_cost_usd; otherwise 402budget_exhausted. A token budget lowers the call'smax_tokens(ormax_completion_tokens) to the tokens left. A call's cost is known only when it ends, so the last call may take a run pastmax_cost_usd. - At propose, a run that spent past
max_cost_usdormax_tokensis held for a person with the reason (spent $0.62 of $0.50 on models), rejected with 402 (reject: its world is discarded), or merged as its other rules say (allow).
Spend and prices
GET /agents/v1/runs/{id}hasusage: {calls, input_tokens, output_tokens, cost_usd, unmetered, unpriced}; the run view shows it, and the overview shows what runs cost by outcome, and per merged run.- Usage is read from the answer (
usage, or the stream's last events). A provider that reports none (some local servers) leaves the callunmetered: counted, never failed. - Cost comes from the price table, per million tokens: input, output, cached input (Anthropic's cache writes at 1.25
times input). Forkbase ships prices for Anthropic's current models;
PUT /gateway/v1/prices/{model} {input_usd, output_usd, cached_input_usd?}sets any other (an OpenAI model, a local one at 0) or overrides one (Agents, Models in the dashboard). A model with no price is counted in tokens (unpriced), at no cost. - A run's model calls made elsewhere count too:
POST /agents/v1/runs/{id}/usage {model, input_tokens, output_tokens, cost_usd?}with the run's token (withoutcost_usd, the price table's). - Each call is an
llmledger entry (model, connection, tokens, cost, time to first byte,result:ok,error,refused,unmetered), an OpenTelemetrychat <model>span, and on/metrics:forkbase_llm_requests_total,forkbase_llm_tokens_total,forkbase_llm_cost_usd_total,forkbase_llm_first_byte_seconds(observability). Prompts and answers are never kept.
Something wrong or missing? Edit this page on GitHub or open an issue.