HTTP API

The API is JSON under /api/v1. Authenticate with the session cookie plus the X-Kojo-Csrf header, or with a bearer token. Request bodies are limited to 4 MiB and unknown fields are refused. Errors are {"error": "..."} with a 400, 401, 403, 404, 409 or 500 status.

Authentication

  • API tokens. server.auth.tokens in kojo.yaml lists static tokens, each with a name, a token of at least 16 characters and a role (default operator). Send one as Authorization: Bearer <token>.
  • The session cookie of a user signed in through the dashboard, together with the X-Kojo-Csrf header on requests that change state.

Each endpoint below names the lowest role that may call it.

CSRF

A request that changes state and is authenticated by the session cookie must carry the header X-Kojo-Csrf with any non-empty value. Without it the API answers 403. Requests authenticated with an API token do not need the header. The web UI sends it on every request that is not a GET.

A browser only sends a custom header to another origin after a CORS preflight, and kōjō approves none.

Sign-in and identity

Method Path Role Does
GET /auth/login None Starts the OIDC flow
GET /auth/callback None Finishes the OIDC flow
GET /auth/logout None Clears the session cookie
GET /api/v1/auth None Says whether OIDC is configured and whether the caller is signed in
GET /api/v1/me viewer The caller’s identity and roles, the version, the forges, the sandbox driver
GET /api/v1/users admin Users who signed in, with their roles

Sessions

Method Path Role Does
GET /api/v1/stats viewer Sessions by status, spend and critic pass rate per skill, last seven days. Also pull_request_outcomes: what became of the pull requests opened in the last 30 days, per repository and skill, with the merge rate and the human-edit rate
GET /api/v1/sessions viewer Lists sessions, each result without its diff and provenance. Query: status, repo, surface, since, before, limit (default 50, at most 200), and exclude_trigger to leave out the sessions of some triggers (eval,skill_test, comma-separated or repeated). A session that a limit keeps from starting has held
POST /api/v1/sessions operator Starts a session
GET /api/v1/sessions/{id} viewer One session with its result, its diff and the step that wrote each block of it (provenance), the follow-up rounds of its pull requests (follow_ups), and held when a limit keeps it from starting
GET /api/v1/sessions/{id}/steps viewer The session’s steps: the replay
POST /api/v1/sessions/{id}/cancel operator Requests cancellation
GET /api/v1/sessions/{id}/messages viewer What people told the session while it worked, oldest first, with takes_messages and, when it takes none, closed_because
POST /api/v1/sessions/{id}/messages operator Sends the session a message: {"text": "..."}
POST /api/v1/sessions/{id}/plan/approve operator Gives the go-ahead on the plan the session waits on
POST /api/v1/sessions/{id}/plan/decline operator Declines the plan the session waits on: it ends without changing anything
POST /api/v1/sessions/{id}/report operator Makes a link to the session’s shareable report; body optional: {"ttl": "72h"}
GET /api/v1/sessions/{id}/report operator The report page itself, as HTML
DELETE /api/v1/sessions/{id}/report admin Revokes every link to the session’s report made so far

The body of POST /api/v1/sessions has repo, text, skill, number, is_pr, dry_run, plan and inputs, the fields of kojo run. plan: true asks for a plan and a person’s go-ahead before code changes; it cannot be combined with dry_run. inputs carries named values for the skills, and two kinds of repository: reference.<name> a reference repository to read, linked.<name> a linked repository the session may also change, where <name> is the repository’s last path segment. A request for an input it may not have is answered with 400.

curl -X POST -H "Authorization: Bearer $KOJO_TOKEN" -H "Content-Type: application/json" \
  "$KOJO_SERVER/api/v1/sessions" \
  -d '{"repo": "github/acme/api", "number": 420, "text": "add the endpoint and its page", "inputs": {"linked.web": "github/acme/web"}}'

POST /api/v1/sessions/{id}/messages gives a queued or running session a correction or a detail. Its next model step reads it as guidance from a maintainer, inside the same fence as the request’s own text; it cannot change a skill’s goals, constraints, tools or limits, and it does not stop the session: cancelling is POST /api/v1/sessions/{id}/cancel. The answer is 202 with the stored message (id, seq, status pending). A message has at most 4000 characters and a session takes at most 20; beyond either, and for a session that takes no messages (waiting for an approval, over, read-only, a dry run), the answer is 400 with the reason. Each message has status pending until a model of the session reads it, then delivered with delivered_to (orchestrator or subagent:<skill>) and delivered_at, or unread when the session’s work ended first. Talking to a session at work has the rules.

curl -X POST -H "Authorization: Bearer $KOJO_TOKEN" -H "Content-Type: application/json" \
  "$KOJO_SERVER/api/v1/sessions/ses_01j.../messages" \
  -d '{"text": "keep the old endpoint working until the next release"}'

POST /api/v1/sessions/{id}/plan/approve and .../plan/decline decide the plan a session waits on. They take no body and answer 202 with the session. A session that waits on no plan, a plan already decided, one whose revision is being written, or one whose deadline passed is answered with 400 and the reason. To ask for a revised plan instead, send the session a message.

curl -X POST -H "Authorization: Bearer $KOJO_TOKEN" "$KOJO_SERVER/api/v1/sessions/ses_01j.../plan/approve"

A session’s result has pr_url, pr_number and branch for its primary pull request and, under pull_requests, every pull request it opened, one per repository that changed, each with repo, number, url, branch and draft. When the merge policy asked in chat, approval says how the question ended: approved, denied, or expired when nobody answered before its deadline. A follow-up session’s request has follow_up (session, the one that opened the pull request, empty on a person’s pull request; branch; trigger, mention or check_failed; check for a failed check; foreign: true when it commits to a person’s pull request), and its result round and, when it pushed, commit. follow_ups lists, for each pull request the session opened or continued that has follow-ups, its repo, number, url, branch, opened_by (empty for a person’s pull request), foreign, max_rounds and rounds, each with round, session_id, trigger, check, actor, status, outcome, commit and created_at. A session that a red default branch started has the trigger branch_red, a request with ref (the branch), sha (the red commit) and check (name, url, sha of the first failing check), and ends with the outcome already_green when no check of the head failed any more at its start. A session whose mention stacked a pull request on a person’s, though its author or the label asked for commits, has the reason in its request’s stacked.

A session that wrote a plan has it in result.plan, from the moment it is posted: skill, task, why (what asked for it), approach, files, risks, tests, not_doing, estimate (typical_usd and samples, the median cost of recent sessions of the skill; cap_usd, the per-session budget), revision and max_revisions, cost_usd (what writing it cost, part of the session’s cost), status (pending, revising, approved, declined or expired), approval_id, deadline, url (where it was posted), decided_by, decided_at and reason. A session whose plan was declined or expired ends succeeded with the outcome plan_declined or plan_expired.

Shareable reports

POST /api/v1/sessions/{id}/report makes a link to a read-only, redacted report of the session that anyone with the link can open without signing in. The answer is 201 with session, url (<server.public_url>/r/<token>) and expires_at. The link works for settings/reports.ttl (default 30 days), or for ttl when that is shorter; ttl is at least 1h. Each call makes a new link, audited as report.link without the link.

curl -X POST -H "Authorization: Bearer $KOJO_TOKEN" -H "Content-Type: application/json" \
  "$KOJO_SERVER/api/v1/sessions/ses_01j.../report" -d '{"ttl": "72h"}'

A session settings/reports does not allow, or a confidential one, is answered 403 with the reason; a server without server.auth.session_secret answers 503. GET on the same path returns the page as text/html under the same rules and headers as a link, audited as report.export: kojo sessions report --html uses it. DELETE revokes every link to the session’s report made so far, the ones in pull request descriptions included, and answers 200 with revoked and revocations, the number of revocations so far; a link made afterwards works.

The page itself is GET /r/<token>, outside /api/v1 and with no authentication: the token is the key.

Limits

Method Path Role Does
GET /api/v1/limits viewer Every team, repository, skill, person and trigger with its limits and what counts against them now; people for operator and up

The answer has:

  • install: the budgets of settings/models (per_session_usd, per_day_usd, per_month_usd), the install’s spend over the last 24 hours (spent_day_usd) and this calendar month (spent_month_usd), and its running, queued and held sessions.
  • teams: each team that owns repositories in rbac or has limits, with its repos, its limits (per_day_usd, per_month_usd, max_running; absent means none), spent_day_usd, spent_month_usd, running, queued, and held, the queued sessions this limit holds back now.
  • repos: the same for each repository that is enabled, belongs to a team, has limits, spent something this month, or has sessions running or queued, with its team.
  • skills: each skill with limits or spend this month: per_day_usd, per_month_usd, spent_day_usd, spent_month_usd and held.
  • people: for the operator role and up, each person with an entry in settings/limits or spend this month, most spent first, at most 200: name (the key), default when people.default is what applies to them, their limits, spent_day_usd, spent_month_usd, running, queued and held. people_default is people.default. For a viewer, people is empty and people_hidden is true.
  • triggers: each trigger with a cap: max_running, running, queued and held.
  • workers: how many sessions the replica that answered runs at once.

held on a session says why it does not start: reason in words, and either cap (scope repo, team, trigger or person; name; running; max_running) or budget (scope install, team, repo, skill or person; name; window day or month; spent_usd; limit_usd). For scope person the reason does not name the person, name is empty, and the counts and amounts are 0, because every viewer reads it. It is worked out when the session is read, from the limits and the running sessions at that moment.

curl -H "Authorization: Bearer $KOJO_TOKEN" "$KOJO_SERVER/api/v1/limits"

Campaigns

A campaign runs one task as one session per repository.

Method Path Role Does
GET /api/v1/campaigns viewer Lists campaigns, newest first. Query: status (pending, running, paused, done, cancelled), limit (default 50)
POST /api/v1/campaigns operator Creates a pending campaign; answers 201 with it
GET /api/v1/campaigns/{id} viewer A campaign and where each of its repositories stands
POST /api/v1/campaigns/{id}/confirm operator Starts a pending campaign. Body: max_cost_usd, at least the estimate as it is now
POST /api/v1/campaigns/{id}/continue operator Starts a paused campaign again. Body (optional): max_cost_usd, the new bound
POST /api/v1/campaigns/{id}/cancel operator Cancels a campaign and asks its open sessions to stop. On a cancelled campaign, asks its open sessions again
POST /api/v1/campaigns/{id}/retry operator Runs the failed repositories again, each as its next attempt

The body of POST /api/v1/campaigns has task (required unless skill is given), title (one line, at most 200 characters), skill, inputs (no name may start with KOJO_), the repositories as any of repos (a list of forge/owner/name), team (a team of rbac) and match (a pattern over enabled repositories, where * does not cross a /), max_parallel (1 to 50, default 5) and pilot (default 3, 0 for none). The answer is the campaign: repos it will run on, skipped with a reason each, items (one per repository: state, sessions, error, cost_usd), estimate (per_session_usd, max_cost_usd, and problem when the cost cannot be bounded), status, paused (pilot, cost or bound), problem (why the cost is not bounded, while paused at bound), max_cost_usd once confirmed, and who created and confirmed it.

GET /api/v1/campaigns/{id} adds rows, one per repository: status (the newest session’s, or pending, failed or cancelled when it has none), session_id, cost_usd (every attempt), outcome, pull_request (repo, number, url, branch, draft), pr_state (open, merged, closed), attempts and error; and totals: repos, by_status, over (done, failed or cancelled), spent_usd, merged and open pull requests. A listing has totals and no rows.

Mistakes (a refused selection, a title too long, a bound below the estimate, continuing a campaign that is not paused or whose cost is not bounded) answer 400 with the reason; an unknown ID 404. A cancel that could not ask every open session to stop answers 500 (the server log names the sessions); the campaign is cancelled all the same, and cancelling it again asks them again.

curl -X POST -H "Authorization: Bearer $KOJO_TOKEN" -H "Content-Type: application/json" \
  -d '{"title": "Logger v3", "task": "Move from logger v2 to v3.", "match": "github/acme/svc-*"}' \
  "$KOJO_SERVER/api/v1/campaigns"

Skills and drafts

Method Path Role Does
GET /api/v1/skills viewer The skills a repository (repo query) or the org resolves to
GET /api/v1/skills/{name} viewer One resolved skill with its files
DELETE /api/v1/skills/{name} operator Deletes a dashboard-managed skill from a scope (scope query)
POST /api/v1/skills/validate viewer Validates skill files against the schemas and a scope’s egress limits
GET /api/v1/tools viewer The tool catalog, the tiers, and the allowed credentials and hosts
GET /api/v1/schemas viewer The names of the JSON Schemas
GET /api/v1/schemas/{name} viewer One JSON Schema
GET /api/v1/drafts viewer Lists drafts (scope query)
POST /api/v1/drafts skill:edit Creates a draft
GET /api/v1/drafts/{id} viewer A draft with its validation, the active version and its eval
PUT /api/v1/drafts/{id} skill:edit Saves a draft’s files
DELETE /api/v1/drafts/{id} skill:edit Deletes a draft
POST /api/v1/drafts/{id}/test skill:edit Runs the draft as a dry-run session
POST /api/v1/drafts/{id}/eval skill:edit Starts an eval of the draft
POST /api/v1/drafts/{id}/activate operator Activates the draft. The draft of a proposal is activated only by a person signed in, never with an API token

A draft kōjō proposed (proposal_id set, author kojo) cannot be deleted: reject its proposal instead. Saving it is refused while the proposal is not ready and when the files would widen the skill, and the proposal records who edited it and what it loosens now.

Skill proposals

The changes kōjō proposes to its own skills. See Self-improvement.

Method Path Role Does
GET /api/v1/proposals viewer Lists proposals, newest first, without their files. Query: scope, skill, open=true (only those being written, measured or waiting for a person), limit (default 100, at most 500)
POST /api/v1/proposals operator Asks kōjō to propose a change to one skill now. Body: skill, scope (default org). Refused (400) when self-improvement is off for the skill, when the evidence is below min_evidence, or while the skill has an open proposal. Answers 202 with the proposal and its session
GET /api/v1/proposals/{id} viewer One proposal with its draft, the active version in use, the change it makes against that version now (widens, loosens), its eval and the baseline eval of the version in use, has_fixtures and accepted_test
POST /api/v1/proposals/{id}/approve operator, a person Activates the proposal’s draft through the activation gate. Body: message. Refused with 403 for an API token, whatever its role; refused with 400 unless the proposal is ready, when it would widen the skill in use, or when the approver edited it, last or at any time before, and the policy needs a second reviewer
POST /api/v1/proposals/{id}/reject operator Closes an open proposal and deletes its draft. Body: reason (optional), kept so the same change is not proposed again

Start one and read it back:

curl -X POST "$KOJO_SERVER/api/v1/proposals" \
  -H "Authorization: Bearer $KOJO_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"scope": "org", "skill": "fix-bug"}'

curl -H "Authorization: Bearer $KOJO_TOKEN" "$KOJO_SERVER/api/v1/proposals/$PROPOSAL_ID"

Config and revisions

Method Path Role Does
GET /api/v1/config viewer Every active object (scope query), with the role each needs
GET /api/v1/config/object viewer One active object. Query: scope (default org), object. A repository’s merge policy or schedules also have git_managed, file (what the default branch’s file makes), and pending (number, url, content) while kōjō’s pull request on the file is open; one kept in git with no revision yet answers 200 without revision
PUT /api/v1/config/object operator or admin, by object Writes a new revision and activates it. Body: content, message, and optionally base_revision, the revision the change was made from: when another one is active, the write is refused with 409. A repository’s merge policy or schedules kept in .factory/ answer 202 with the pull request instead, and base_revision does not apply to them (Editing a setting that lives in git)
GET /api/v1/config/export admin The whole config as YAML, or JSON with format=json
POST /api/v1/config/apply admin Applies an export (YAML or JSON body, at most 16 MiB). dry_run=1 writes nothing. Objects a repository keeps in .factory/ become pull requests, listed in pull_requests (scope, object, action, number, url, notes)
GET /api/v1/revisions viewer An object’s history. Query: scope, object, limit (default 50, at most 200)
GET /api/v1/revisions/{id} viewer One revision
POST /api/v1/revisions/{id}/activate operator or admin, by object Rollback. Of a setting a repository keeps in .factory/, a pull request (202)

Schedules, repositories and the rest

Method Path Role Does
GET /api/v1/schedules viewer Every schedule of every scope with its last and next run
POST /api/v1/schedules/parse operator Turns a description in words into a schedule proposal. Stores nothing.
GET /api/v1/repos viewer The configured repositories and the ones the forges can reach. For an admin, factory=1 adds to each configured one factory (factory_yaml, merge_policy_key, schedules_yaml, movable) or factory_error, read from its default branch
POST /api/v1/repos/<forge>/<owner>/<name>/factory admin Opens one pull request that moves the repository’s merge policy and schedules into .factory/. Answers 202 with pull_request, created and left_alone. See Moving from the dashboard
GET /api/v1/audit viewer The audit log. Query: actor, session, action, since, until, before, limit (default 100, at most 500)
GET /api/v1/audit/export operator The audit log as newline-delimited JSON. Query: since, until
GET /api/v1/evals viewer Eval runs. Query: skill, limit
POST /api/v1/evals skill:edit Starts an eval of a skill
GET /api/v1/evals/{id} viewer One eval run
POST /api/v1/evals/history operator Starts an eval from a repository’s history. Body: skill, repo, test_cmd, limit (1 to 50, required), since (a date or an RFC 3339 time; default 90 days ago). It mines and checks the cases without a model and stops as validated; answers 202 with the run’s id
POST /api/v1/evals/{id}/confirm operator Runs the valid cases of a validated history eval on live models. Body: max_cost_usd, the bound the run reported (history.estimate.max_cost_usd); refused when the bound is now higher, when it cannot be bounded, or while the daily budget is spent. Answers 202 with the run
GET /api/v1/memory viewer Memory. Query: q to search, repo, limit, scope (team, the default; mine, your personal memory; all, both), skill, source (exact, or a prefix when it ends with :; review: lists the lessons learned from reviews), and person (a person’s key: your own, or anyone’s with the admin role, which is audited)
POST /api/v1/memory viewer Adds a memory. Body: content, topic, repo, and scope: team (the default, needs operator) or personal (your own memory, any role)
DELETE /api/v1/memory/{id} viewer Deletes a memory. A team memory needs operator; a personal one is deleted by its owner or by an admin, and is 404 to anyone else
DELETE /api/v1/memory?person=<key> viewer Deletes every personal memory of one person: your own, or anyone’s with the admin role. Answers with the number deleted
GET /api/v1/doctor operator Runs the doctor checks on the server and returns the report

The times in since and until are RFC 3339. before is the ID of the last row of the previous page.

Change one object

PUT /api/v1/config/object writes a new revision of one object and activates it:

curl -X PUT "$KOJO_SERVER/api/v1/config/object?scope=org&object=settings/activation" \
  -H "Authorization: Bearer $KOJO_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"content": {"require_eval": true, "min_eval_pass_rate": 0.7, "require_second_reviewer": true}, "message": "gate activation on evals"}'

A client that reads an object, changes it and writes it back can send the ID of the revision it read as base_revision. When someone activated another revision in between, nothing is written and the answer is 409 with {"error": "it changed since you loaded it: reload and try again"}; read the object again and redo the change. kojo limits set and unset work this way. Without base_revision the last write wins, as the dashboard’s forms do.

curl -X PUT "$KOJO_SERVER/api/v1/config/object?scope=org&object=settings/limits" \
  -H "Authorization: Bearer $KOJO_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"content": {"skills": {"fix-bug": {"per_day_usd": 20}}}, "base_revision": "rev_01m9...", "message": "cap fix-bug"}'

A repository’s merge policy or schedules that the repository keeps in .factory/ are not written this way: the answer is 202 with the pull request that changes the file. The answers and refusals are listed in Editing a setting that lives in git. POST /api/v1/config/apply checks each such object before it writes anything, writes the revisions, then opens the pull requests; when one of those fails, the revisions stay, and applying the same document again is idempotent.

Revisions and rollback

Every object has a history. List it, newest first:

curl -H "Authorization: Bearer $KOJO_TOKEN" \
  "$KOJO_SERVER/api/v1/revisions?scope=org&object=settings/merge_policy"

A rollback activates an earlier revision:

curl -X POST -H "Authorization: Bearer $KOJO_TOKEN" \
  "$KOJO_SERVER/api/v1/revisions/$REVISION_ID/activate"

What a rollback checks and records is in Revisions and rollback.

The server also exposes /healthz, /readyz, the forge webhooks, the Slack routes and /mcp, and /metrics on a port of its own. They are covered in Observability and Surfaces.

Scroll to move. + - zoom, 0 fit, Esc close.100%