# Call every Sailfork operation from TypeScript, Python or a model's tool loop.

The official SDKs are on npm and PyPI as sailfork, with a typed method for each of the 214 operations in the API.

[Read the SDK docs](https://sailfork.com/docs/sdk) [Browse every method](https://sailfork.com/docs/sdk-reference)

open-pr.ts

```
import Sailfork from 'sailfork';const sf = new Sailfork(); // SAILFORK_TOKEN, else the CLI tokenconst repo = sf.repo('acme/shop');const pr = await repo.pulls.create({	title: 'Pin the AWS provider',	branch: 'agent/pin-aws',	base: 'main',});const merge = await pr.merge();if (merge.status === 'held') {	console.log('held', merge.held);	console.log('approve at', merge.url);}
```

Output

```
$ bun run open-pr.tsheld c0a8f6e2-5b1d-4c0e-9a77-3d2e8f41b6a9approve at https://sailfork.com/requests
```

bun add sailfork

## A merge that waits for a person comes back as a value.

When an organization holds an agent's merges, merge() returns a held result with the request id and the page where a person decides. Wait on that id, then merge again.

[How held writes work](https://sailfork.com/docs/sdk-typescript-held-and-waits#writes-held-for-a-person)

1. Your script

   await pr.merge()

   - status

     held

   - held

     c0a8f6e2-5b1d-4c0e-9a77-3d2e8f41b6a9

   - url

     https\://sailfork.com/requests

2. A person at acme

   Merge acme/shop#418

   Asked by the release-bot token, waiting on you

3. Your script again

   await sf.wait({ kind: 'held', owner: 'acme', id: merge.held })

   state: met

   await pr.merge()

   status: done

- TypeScript

  sf.repo('acme/shop').pull(418).merge()

- Python

  sf.repo("acme/shop").pull(418).merge()

- Claude tool

  pull_merge { org: "acme", repo: "shop", number: 418 }

- CLI

  sailfork pr merge 418

- REST

  POST /api/repos/acme/shop/pulls/418/merge

## The method you call is the operation the CLI already runs.

Handles such as sf.repo('acme/shop').pull(418) fill in the owner, repository and number, so a call carries only what is new.

[Every method and its arguments](https://sailfork.com/docs/sdk-reference)

## A retried write applies once, and a failure fits on one line.

Every write sends one Idempotency-Key across its attempts. Anything the client does not retry throws a typed error carrying the code, hint and request id.

[Errors and retries](https://sailfork.com/docs/sdk-typescript-errors)

pr.merge(), three attempts, one idempotency key

1. 1

   503 unavailable

   waits about 500 ms

2. 2

   429 rate_limited, Retry-After: 2

   waits 2 s

3. 3

   200 done

   returns the merged pull request

A 404 is not retried, so it throws and prints on one line

```
NotFoundError: not_found: not found | request: req_05e1... | docs: https://sailfork.com/docs/api#error-codes
```

## Claude merges it through the same call.

Pass anthropicTools to a tool-use loop and run() executes whichever tool the model picks, a held answer included. For OpenAI, pass openaiTools (OPENAI_TOOLS in Python).

[Tool definitions](https://sailfork.com/docs/sdk-typescript-tools)

agent.ts

```
import Anthropic from '@anthropic-ai/sdk';import { anthropicTools, run } from 'sailfork/tools';const claude = new Anthropic();const messages: Anthropic.MessageParam[] = [	{ role: 'user', content: 'Merge acme/shop pull request 418.' },];while (true) {	const reply = await claude.messages.create({		model: 'claude-sonnet-5-5',		max_tokens: 4096,		tools: anthropicTools,		messages,	});	messages.push({ role: 'assistant', content: reply.content });	const calls = reply.content.filter((b) => b.type === 'tool_use');	if (calls.length === 0) break;	const results = [];	for (const call of calls) {		const out = await run(call.name, call.input as Record<string, unknown>);		results.push({ type: 'tool_result' as const, tool_use_id: call.id, content: JSON.stringify(out) });	}	messages.push({ role: 'user', content: results });}
```

1. What the loop saw
2. You Merge acme/shop pull request 418.
3. Claude pull_merge {"org":"acme","repo":"shop","number":418}
4. run() {"status":"held","held":"c0a8f6e2-5b1d-4c0e-9a77-3d2e8f41b6a9","url":"https\://sailfork.com/requests","message":"HELD FOR A PERSON: ..."}
5. Claude The merge is held for a person at acme. Approve it at https\://sailfork.com/requests, then ask me again and I will merge it.

## Limits and defaults

- The SDKs have 214 methods each, one per operation in the catalog that the REST API, the CLI and the MCP server share.
- A failed call retries up to 2 times by default, after a dropped connection, a timeout, 408, 429 or 5xx. A Retry-After over 60 seconds is thrown instead of waited for.
- Each attempt times out after 60 seconds, or 5 minutes for the operations the catalog marks long.
- An approval for a held merge covers one request and lasts 24 hours.
- Errors come in 32 codes, each with its own class in TypeScript and Python.
- TypeScript runs on Node 20 or later, Bun, Deno and Workers with no runtime dependencies. Python needs 3.11 or later, and Sailfork and AsyncSailfork share one surface.

## Questions

###

Use the MCP server at https\://sailfork.com/mcp when your agent host speaks MCP, such as Claude Code or Cursor. Use the SDK when you write the loop or the automation yourself. The tool names and schemas match.

###

It takes the token you pass, then the SAILFORK_TOKEN environment variable, then the token the Sailfork CLI stored at sign-in. The host defaults to sailfork.com; set SAILFORK_HOST or pass a host for another one.

###

No. A token is refused at the approval step, so only a person can decide it, in the browser. After a decline, the same merge throws a held_declined error for 24 hours.

###

The TypeScript package uses the global fetch, so it runs wherever one exists. Do not ship a personal token to a page; use a token scoped to what the page needs.
