Skip to content
Alpha

An API to create a Git repository for each user or agent

Give every user or agent its own Git repository: create repositories from your server over the API, hand each agent a short-lived token for its branches, and clean up when the task ends.

The Upstream API is in alpha. Endpoints, fields and limits can change before it's stable. Send feedback to support@coline.app.

An agent platform runs one Upstream app. Your server uses it to create a repository per task, mint a token that pushes only to the agent's branches, and delete the repository when it's done. Agents never see your app's key.

1. Create the app

Create it once, from your server or a terminal, with your own token (apps:write; upstream auth login grants it). The app needs repo:create to create and delete repositories, and contents:write to mint tokens that push. Ask for them by name with scopes:

curl -X POST https://api.upstream.codes/v1/apps \
  -H "Authorization: Bearer $UPSTREAM_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "owner": "acme",
    "manifest": {
      "name": "my-platform",
      "callback_urls": ["https://platform.example.com/upstream/callback"],
      "hook_attributes": { "url": "https://platform.example.com/upstream/webhook" },
      "scopes": ["repo:read", "repo:create", "contents:write"],
      "default_events": ["push", "repository"]
    }
  }'

owner is the organization your agents' repositories live in. The response holds the app's id, its private key (pem) and its webhook secret, once. Keep them on your server.

Then install it on that organization:

curl -X POST https://api.upstream.codes/v1/user/installations \
  -H "Authorization: Bearer $UPSTREAM_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "app": "my-platform", "owner": "acme", "all": true }'

App quickstart has every field of both calls.

2. Create a repository and a token

npm install @colineapp/upstream-sdk
import { createPlatformClient } from "@colineapp/upstream-sdk";

const upstream = createPlatformClient({ appId: process.env.UPSTREAM_APP_ID!, privateKey: process.env.UPSTREAM_PRIVATE_KEY! });
const repo = await upstream.createRepository({ name: "task-4821", visibility: "private", autoInit: true });
const { token } = await upstream.createRepositoryToken(repo.fullName, { access: "write", branches: ["agent/*"], expiresIn: 3600 });

The client signs the app JWT, finds the app's installation, mints the installation token and mints a new one five minutes before it expires. If a token is refused, it mints a new one and sends the request again. Pass installationId when the app is installed in more than one place.

createRepository sends an Idempotency-Key, so a retry never makes a second repository. Pass your own idempotencyKey (the task ID works) to make retries across restarts safe too.

The private key can be a PEM (PRIVATE KEY, RSA PRIVATE KEY or EC PRIVATE KEY), a private JWK or a Web Crypto CryptoKey: RSA, Ed25519 or P-256.

3. Give the token to the agent

The urt_ token works on this one repository only:

  • As the Git password over HTTPS, with any user name.
  • As a Bearer token on this repository's API.
  • With branches, a push to any other ref is refused. * matches any characters.
  • It lasts 60 seconds to 12 hours (expiresIn, default an hour). Anywhere else it gets what a stranger gets.
git clone "https://agent:$UPSTREAM_REPO_TOKEN@upstream.codes/acme/task-4821.git"
cd task-4821
git switch -c agent/fix-login
git commit -am "Fix the login redirect"
git push origin agent/fix-login

To keep the token out of the remote URL, pass it per command: git -c credential.helper= -c "http.extraHeader=Authorization: Bearer $UPSTREAM_REPO_TOKEN" push.

4. Hear about pushes

Set the app's webhook URL and subscribe to push and repository. Every repository the app creates sends its events there, signed with your webhook secret. App webhooks shows how to check them.

5. Clean up

await upstream.revokeRepositoryToken(repo.fullName, tokenId); // stops working at once
await upstream.deleteRepository(repo.fullName);

An app deletes only repositories it created. Uninstalling the app revokes every token it minted.

Other calls

upstream.api is a typed client signed in as the installation, for any REST API endpoint:

await upstream.api.post("/repos/{owner}/{repo}/changes", {
  params: { owner: "acme", repo: "task-4821" },
  body: { title: "Fix the login redirect", sourceBranch: "agent/fix-login", targetBranch: "main" },
});

upstream.app is signed in as the app itself, for /app/… endpoints. upstream.installationToken() returns the current installation token, for tools that take one.

Limits

App installations get much higher limits than people, counted per installation:

App installationPerson
New repositories, forks, Issues, Change Requests3,000 a minute20 a minute
Git writes through the API6,000 a minute120 a minute
Comments3,000 a minute60 a minute
Releases1,200 a minute20 a minute
Indexed code search6,000 a minute120 a minute
API requests1,000,000 an hour1,000,000 an hour

Installation tokens: 60 a minute per app. The client mints one an hour, so this only matters with many installations.

Repositories per organization follow its plan: 100 on Free, 500 on Pro, 2,000 on Team and 10,000 on Enterprise. For more repositories or higher limits, contact us: we lift the repository cap and raise or remove the per-minute limits for platform accounts.

Errors

Every error has the same shape:

{ "error": { "code": "UPSTREAM_RATE_LIMITED", "message": "Too many requests. Try again in a minute." } }

The SDK throws UpstreamApiError with status, code and message, and retries 429 on its own, twice by default.

StatusCodeMeaning
401TOKEN_INVALIDThe app JWT or token is wrong, expired or revoked. The client mints a new one and tries once more.
403UPSTREAM_REPOSITORY_LIMITThe organization has as many repositories as its plan includes.
403APP_NAMESPACE_FORBIDDENThe app tried to create a repository outside the namespace it's installed on.
403INSTALLATION_OPERATION_DENIEDA repository token tried to create a repository. Only the installation can.
409GIT_REPOSITORY_MIGRATINGThe repository is being moved. Retry shortly.
429UPSTREAM_RATE_LIMITEDOver a per-minute limit. Wait for the next minute.
400INSTALLATION_REQUIREDFrom the SDK: the app has no installation, or several and you didn't pass installationId.