Offer paid AI models on your storefront
Show the AI workspace on your storefront, with the free assistant model, paid models at your prices, projects a paid model builds in, and usage.
The AI workspace is a full page on your storefront where a signed-in customer works with a Claude model. The free model is your assistant: the same chat, with the same answers and the same message limits, in a page that fills the window. Every other model is paid. Its tokens are charged to the customer's account credit at your organization's prices.
This page shows how to read what your workspace offers, draw a model switch from it, and show a customer their balance, their usage and their own monthly limit. It also shows how to let a customer connect their GitHub account, create a repository, and build with a paid model in a project.
Important
Paid models are open while builder in the config answer is true. While it is false, the routes list the paid models with your prices and no customer can choose one: every customer's paid answer is builder_closed. Build the page so that it lists the paid models and lets none be picked until builder is true.
Before you begin
Section titled Before you begin- Add the assistant to your storefront first, as Add the assistant chat to your storefront describes. The workspace's free model is that assistant, and its chat uses the assistant's routes.
- Ask Coritan support to turn the workspace on for your organization. We set what you add to the cost of each model (your markup) and the most one customer may spend in a day at the same time. The workspace is not available to every organization yet.
- Set your organization's tax rate to zero, with prices that include tax. A charge for a paid model comes straight off the customer's credit and adds no tax, so we cannot turn the workspace on while your tax rate is above zero.
- Sign customers in as Sign customers in to your storefront describes. A paid model is for a signed-in customer with a verified email address.
- Let customers add credit, as Add credit describes. Paid models are paid from that balance and no invoice is made.
Check whether your storefront has it
Section titled Check whether your storefront has itThe assistant's GET /assistant/config answers workspace: true when your storefront should offer the page. It is the same for every caller, so use it to decide whether to show the link to the page or the button that makes the chat fill the window.
Every workspace route answers 404 for an organization that does not have the workspace.
Read what the workspace offers
Section titled Read what the workspace offerscurl "https://api.coritan.com/api/v1/orgs/acme/workspace/config" \
-H "Authorization: Bearer $CUSTOMER_TOKEN"
Leave out the header for a visitor: account is then null and signed_in is false. A token that is sent must be valid. An expired one answers 401, so refresh it first.
{
"enabled": true,
"builder": false,
"signed_in": true,
"currency": "USD",
"free": {"model": "claude-haiku-5-5", "name": "Claude Haiku 5.5", "messages_per_minute": 20, "messages_per_day": 500},
"models": [
{"id": "claude-sonnet-5", "name": "Claude Sonnet 5", "input": "3.90", "output": "19.50",
"cache_read": "0.39", "cache_write": "4.875", "context_tokens": 200000}
],
"account": {
"balance": "12.3400", "owed": "0.0000", "available": "12.3400",
"spent_today": "0.0000", "daily_cap": "25.00",
"spent_month": "1.2300", "monthly_limit": null,
"paid": {"allowed": false, "code": "builder_closed", "message": "Paid models are not open yet."}
}
}
The figures in this example are made up. Read yours from the route.
| Field | Meaning |
|---|---|
builder |
Whether a paid model can be chosen yet. |
free |
The model your assistant answers with, and how many messages a signed-in customer may send it in a minute and in a day. It costs the customer nothing. |
models |
The paid models, the one with the cheapest output first. Each has your price in USD for one million tokens: input, output, cache_read and cache_write. context_tokens is how much the model can read at once. |
account |
The signed-in customer's figures. available is balance less owed, which is usage that is not charged to the balance yet. |
account.paid |
Whether this customer may use a paid model now. When allowed is false, code says why and message is a sentence to show them. |
Every amount is a string, so no figure is lost to rounding. Balances and amounts have four decimals, daily_cap has two, and a price has at least two. When we cannot read a model's details, its name is its id and context_tokens is null.
Draw the model switch
Section titled Draw the model switch- Show
freefirst, withfree.name, and say that it is free. It is the chat your storefront already has. - List each entry of
modelswith itsnameand its prices for one million tokens.outputis the price a customer notices most, since it is the price of what the model writes. - While
builderisfalse, show the paid models and let none be picked. Say that paid models are not open yet. - Once
builderistrue, let a signed-in customer pick a paid model only whenaccount.paid.allowedistrue. Otherwise showaccount.paid.messagebeside the switch, with the button that fits thecodein the next section.
Do not keep a copy of the prices. Read the route when the page opens, because we change a model's cost and your markup without a release of your storefront.
Say why a customer cannot use a paid model
Section titled Say why a customer cannot use a paid modelaccount.paid answers the first of these that applies, in this order.
code |
message |
What to offer |
|---|---|---|
builder_closed |
Paid models are not open yet. | Nothing to do: every customer gets this while builder is false. |
support_session |
Paid models cannot be used in a support session. | Nothing to do: your staff are signed in as the customer. |
inactive |
This account cannot use paid models. | A way to contact your support. |
verify_email |
Verify your email address to use paid models. | The page where the customer verifies their email address. |
blocked |
Paid models are turned off for this account. Contact support. | A way to contact your support. We block an account after a payment dispute, or when you ask us to. |
daily_cap |
You have reached today's spending limit for paid models. It resets at midnight UTC. | Nothing to do until the next day: account.daily_cap is the limit and account.spent_today what counts towards it. |
monthly_limit |
You have reached the monthly limit you set for paid models. Raise it to go on. | The control that changes the monthly limit. |
add_funds |
Your balance is too low for this model. Add funds to go on. | Your page for adding credit. |
Show message as it is. The free model keeps working for a customer who gets any of these.
Show the customer's usage
Section titled Show the customer's usagecurl "https://api.coritan.com/api/v1/orgs/acme/workspace/usage?limit=20&offset=0" \
-H "Authorization: Bearer $CUSTOMER_TOKEN"
The answer lists the customer's own paid model usage, newest first, one item for each run. A run is one piece of work with a paid model, and its item sums the calls it made.
{
"items": [
{"run_ref": "run:81", "models": ["claude-sonnet-5"], "calls": 3,
"input_tokens": 41200, "output_tokens": 2310, "cache_read_tokens": 120000, "cache_write_tokens": 9000,
"amount": "0.2531", "status": "charged", "at": "2026-11-15T10:02:11Z"}
],
"total": 1,
"month": {"amount": "1.2300", "by_model": [{"model": "claude-sonnet-5", "calls": 14, "amount": "1.2300"}]}
}
status is charged once every call of the run is paid from the balance, and owed until then. Usage stays owed while the balance does not cover it, and is charged after the customer adds credit. total counts every run, for paging with limit and offset. month is what the customer spent this calendar month (UTC), in all and for each model.
The route needs the customer's token and answers 401 without one. Messages to the free model are never in this list.
Let the customer set a monthly limit
Section titled Let the customer set a monthly limitA customer can cap what they spend on paid models in a calendar month (UTC).
curl -X PUT "https://api.coritan.com/api/v1/orgs/acme/workspace/limit" \
-H "Authorization: Bearer $CUSTOMER_TOKEN" -H "Content-Type: application/json" \
-d '{"monthly_limit": "20.00"}'
monthly_limit is an amount in USD from 0.01 to 10000 with at most two decimals, as a string or a number. Send null to remove the limit. The answer is the customer's account, as the config route answers it, so you can redraw the figures from it.
Once spent_month reaches the limit, account.paid answers monthly_limit until the customer raises the limit or the month ends. The limit is checked before each call, so one call can pass it by that call's cost.
Let customers connect GitHub
Section titled Let customers connect GitHubA customer can connect their GitHub account in the workspace and choose which of their repositories your store may reach. They can also create a new repository from the workspace. A project can then work on one of those repositories, as Let customers build with a paid model describes.
Your store has a GitHub App of its own, so GitHub shows your store's name when it asks the customer to approve. Coritan support sets the App up for your organization: ask us when you ask for the workspace. The App can read and write code and pull requests in the repositories the customer chooses, and read their issues, checks and workflow runs. It also asks for GitHub's Administration permission. We use that permission only to create a repository when the customer asks. We never delete a repository or change its settings.
github in the config answer says where a customer stands: {"available": true, "linked": false, "login": null}. available is whether your store has a GitHub App. linked and login are the signed-in customer's connected account, and false and null without a token.
| Route | What it does |
|---|---|
GET /workspace/github |
Answers your store's App and the customer's connected account. |
POST /workspace/github/authorize |
Starts a connection. Answers the GitHub address to send the browser to. |
GET /workspace/github/callback |
Where GitHub sends the browser afterwards. Your page never calls it. |
POST /workspace/github/link |
Finishes the connection with the ticket the callback gave your page. |
DELETE /workspace/github |
Disconnects the account. |
GET /workspace/github/repositories |
Lists the repositories the customer chose for your store, and the accounts a new one can go to. |
POST /workspace/github/repositories |
Creates a repository for the customer on GitHub. |
GET /workspace/github/branches |
Lists the branches of one of them. |
Every route but the callback needs the customer's token and answers 401 without one. Put your workspace page at /workspace on your storefront: that is where the callback and GitHub send the browser.
Connect an account
Section titled Connect an accountOffer to connect GitHub when
github.availableistrueandgithub.linkedisfalse.When the customer asks to connect, start the connection from the workspace page.
Shellcurl -X POST "https://api.coritan.com/api/v1/orgs/acme/workspace/github/authorize" \ -H "Authorization: Bearer $CUSTOMER_TOKEN" -H "Origin: https://www.example.com"JSON{"url": "https://github.com/login/oauth/authorize?client_id=...&redirect_uri=...&state=...", "expires_in": 600}Send the browser to
url. It works for ten minutes.The customer approves your store's App on GitHub. GitHub sends the browser to the callback route, which sends it on to your workspace page with a ticket:
https://www.example.com/workspace?github=ticket&ticket=.... The browser returns to the storefront host the request in step 2 came from (itsOriginheader, or else itsReferer) when that host is one of your storefront's own, and to your storefront's main host otherwise.Post the ticket with the customer's token, then take
githubandticketout of the page's address.Shellcurl -X POST "https://api.coritan.com/api/v1/orgs/acme/workspace/github/link" \ -H "Authorization: Bearer $CUSTOMER_TOKEN" -H "Content-Type: application/json" \ -d '{"ticket": "..."}'JSON{ "configured": true, "linked": true, "login": "alex-example", "name": "Alex Example", "linked_at": "2026-11-15T10:02:11Z", "app_name": "Example Workspace", "install_url": "https://github.com/apps/example-workspace/installations/new" }A ticket works once, within 15 minutes, and only for the customer who started the connection.
GET /workspace/githubanswers the same fields at any time.Send the customer to
install_url, GitHub's page where they choose the repositories your store may reach. GitHub sends them back to/workspace?github=installedon your storefront's main host. Read the repository list again when you see it.
When the connection fails, the callback sends the browser to /workspace?github=error&reason=... with one of these reasons. Say what happened and offer to connect again.
reason |
What happened |
|---|---|
denied |
The customer did not approve on GitHub. |
state |
The connection was started more than ten minutes ago, was already finished, or was not started on your store. |
exchange |
GitHub did not accept the approval, or could not be reached. |
account |
That GitHub account cannot be used here. Another customer of your store may have connected it: one GitHub account connects to one customer. |
not_configured |
Your store has no GitHub App. Ask Coritan support to set it up. |
List the customer's repositories and branches
Section titled List the customer's repositories and branchescurl "https://api.coritan.com/api/v1/orgs/acme/workspace/github/repositories?q=site&page=1" \
-H "Authorization: Bearer $CUSTOMER_TOKEN"
{
"items": [{"full_name": "alex-example/site", "default_branch": "main", "private": true}],
"has_more": false,
"installations": 2,
"accounts": [
{"login": "alex-example", "kind": "user"},
{"login": "example-studio", "kind": "organization"}
],
"install_url": "https://github.com/apps/example-workspace/installations/new"
}
The list holds 30 repositories a page, sorted by name, without archived ones. q matches part of owner/name, ignoring case. When installations is 0, the customer has not chosen repositories yet: send them to install_url.
accounts holds the GitHub accounts your store's App is installed on for the customer. Their own account comes first, with kind user. Organizations follow by login, with kind organization. These are the accounts a new repository can go to. The key is the same on every page.
curl "https://api.coritan.com/api/v1/orgs/acme/workspace/github/branches?repository=alex-example/site" \
-H "Authorization: Bearer $CUSTOMER_TOKEN"
{"branches": ["main", "redesign"], "default_branch": "main"}
The default branch comes first, and the list holds at most 100 branches. q matches part of a branch name.
Both routes answer 409 when the customer has not connected GitHub, or when GitHub asks them to connect again. The branches route answers 404 when your store's App cannot reach the repository. The detail of each answer is a sentence you can show the customer.
Create a repository
Section titled Create a repositoryOffer this when the customer wants to start a new project. Let them choose the account from accounts in the repository list when it holds more than one.
curl -X POST "https://api.coritan.com/api/v1/orgs/acme/workspace/github/repositories" \
-H "Authorization: Bearer $CUSTOMER_TOKEN" -H "Content-Type: application/json" \
-d '{"name": "my-plugin", "description": "A plugin for my server"}'
{
"full_name": "alex-example/my-plugin",
"default_branch": "main",
"private": true,
"html_url": "https://github.com/alex-example/my-plugin",
"reachable": true
}
| Field | What it takes |
|---|---|
name |
Required. 1 to 100 letters, digits, dots, hyphens and underscores. It is not . or .. and does not end in .git. |
private |
true or false. The repository is private when you leave it out. |
description |
One line of at most 350 characters. Leave it out for none. |
owner |
The login of the account the repository goes to: one of accounts, in any case. Leave it out for the customer's own account. |
The answer is 201. GitHub creates the repository as the customer, with a first commit, so it has a branch to work on. html_url is its page on GitHub.
reachable says whether your store's App can reach the new repository. It is false when the customer chose selected repositories for your App and GitHub did not add the new one. Send the customer to install_url to choose it, then read the repository list again.
When the route refuses, detail is a sentence you can show the customer.
| Status | detail |
What happened |
|---|---|---|
422 |
A repository name holds letters, digits, dots, hyphens and underscores, 100 at most, and does not end in .git. | name is outside its rule. |
422 |
A description is one line of at most 350 characters. | description is longer, or holds a line break. |
422 |
Choose your own account or an organization this store's App is installed on. | owner is not one of accounts. |
409 |
Choose repositories on GitHub first, so this store's App is installed on your account. | The App is not installed on the customer's own account. Send them to install_url. |
409 |
A repository with that name already exists there. Choose another name. | The account has a repository with that name. |
422 |
GitHub did not accept that name. Try another. | GitHub refused the name for a reason of its own. |
403 |
GitHub did not allow a repository to be created there. Create it on GitHub, then choose it here. | The customer may not create repositories in that organization, or your store's App may not. |
409 |
GitHub is not connected. Connect GitHub in the workspace. | The customer has not connected an account. |
403 |
A support session cannot change the GitHub connection. | The request came from a support session. |
Disconnect
Section titled Disconnectcurl -X DELETE "https://api.coritan.com/api/v1/orgs/acme/workspace/github" \
-H "Authorization: Bearer $CUSTOMER_TOKEN"
The answer is {"linked": false}, and it is the same when nothing was connected. We delete the connection and ask GitHub to revoke its access. Your store's App stays on the customer's GitHub account until they remove it on GitHub.
Let customers build with a paid model
Section titled Let customers build with a paid modelA customer works with a paid model in a project. A project holds one conversation, the runs that answered it and a workspace. The workspace is a private place of the customer's own with the project's files, where the model writes, runs and tests code. A project can work on one of the customer's GitHub repositories and send its work there as a pull request. It can also copy a built file to one of the customer's own servers, after the customer says yes.
Each message the customer sends starts a run. Every call the model makes in it is charged to the customer's account credit at your price, and shows in the usage list. A project costs nothing while no run works in it.
Offer a paid model while builder is true and account.paid.allowed is true. The routes are under /workspace/builder. Each needs the customer's token and answers 401 without one.
| Route | What it does |
|---|---|
GET /workspace/builder/servers |
Lists the customer's servers that a project can be linked to. |
GET /workspace/builder/sessions |
Lists the customer's projects, the one with the newest activity first. |
POST /workspace/builder/sessions |
Starts a project. |
GET /workspace/builder/sessions/{session_uuid} |
Answers one project. |
PATCH /workspace/builder/sessions/{session_uuid} |
Renames or archives a project, or links it to a server. |
POST /workspace/builder/sessions/{session_uuid}/repository |
Names the repository of a project that started without one. |
GET /workspace/builder/sessions/{session_uuid}/messages |
Answers the project's conversation. |
POST /workspace/builder/sessions/{session_uuid}/messages |
Sends a message and starts a run. |
GET /workspace/builder/sessions/{session_uuid}/events |
Reads what the project's runs did, a page at a time. |
GET /workspace/builder/sessions/{session_uuid}/events/stream |
Follows the same events as they happen. |
POST /workspace/builder/sessions/{session_uuid}/runs/{run_id}/cancel |
Stops a run. |
POST /workspace/builder/sessions/{session_uuid}/approvals/{tool_use_id} |
Answers the card a run shows before it copies a file to a server. |
GET /workspace/builder/sessions/{session_uuid}/changes |
Answers what the project changed, as a list of files and a diff. |
GET /workspace/builder/sessions/{session_uuid}/files |
Lists a folder of the workspace. |
GET /workspace/builder/sessions/{session_uuid}/files/content |
Reads one file of the workspace. |
POST /workspace/builder/sessions/{session_uuid}/workspace/wake |
Wakes the workspace so its files can be read. |
A customer reaches their own projects and nobody else's. A route answers 404 with There is no such project. for any other session_uuid, whether it belongs to another customer or to nothing at all.
Start a project
Section titled Start a projectcurl -X POST "https://api.coritan.com/api/v1/orgs/acme/workspace/builder/sessions" \
-H "Authorization: Bearer $CUSTOMER_TOKEN" -H "Content-Type: application/json" \
-d '{"title": "Greeter plugin", "repository": "alex-example/my-plugin"}'
{
"uuid": "6f2b7c1e-3a4d-4e5f-8a9b-0c1d2e3f4a5b",
"title": "Greeter plugin",
"status": "active",
"repository": "alex-example/my-plugin",
"base_branch": "main",
"branch": "workspace/greeter-plugin-4c9a1e",
"model": "",
"pr": null,
"pull_requests": [],
"spent": "0.0000",
"workspace": {"status": "none"},
"preview": null,
"server": null,
"active_run": null,
"last_run": null,
"last_activity_at": "2026-11-15T10:02:11Z",
"created_at": "2026-11-15T10:02:11Z"
}
The answer is 201. Every field of the body is optional.
| Field | What it takes |
|---|---|
title |
1 to 120 characters. The project is named New project when you leave it out. |
repository |
A repository from the customer's repository list, as owner/name. Leave it out for a project that starts empty. |
base_branch |
The branch to start from. The repository's default branch when you leave it out. |
server |
The id of one of the customer's own servers, to link the project to it. Leave it out, or send null, for a project with no linked server. Link a project to a server has the rules. |
A project works on a branch of its own, named in branch. It never pushes to the branch it started from. A project that started empty gets a repository later through POST .../repository, with the same two fields. A project has one repository, and it cannot be changed afterwards.
A project answers these fields wherever it is answered.
| Field | Meaning |
|---|---|
spent |
What the project has cost the customer so far, in USD with four decimals. |
workspace.status |
none (the project has no workspace yet), starting, ready, asleep, failed or locked. |
active_run |
The run that works now, or null. Its status is queued, running, waiting_approval or waiting_workspace, which means the workspace is starting. |
last_run |
The newest run that ended, or null. Its status is completed, failed or cancelled. When error is not null it is a sentence to show the customer. |
pr and pull_requests |
The pull request of the project's branch, and every pull request the project opened. |
preview |
null, or {"url": "...", "ready": true} when the project has a preview address for a web server the model started. Anyone with the link can open it, so say so beside it. |
server |
null, or {"id": "...", "name": "..."} when the project is linked to one of the customer's servers. The name is the server's name now. |
PATCH with {"title": "..."} renames a project, and with {"archived": true} archives it. A body with none of title, archived and server answers 422. Archiving stops the project's run. The conversation stays readable in the archived list, and we delete the workspace's files soon after. An archived project cannot be opened again.
Link a project to a server
Section titled Link a project to a serverA customer can say that a project is for one of their own servers, such as the server a plugin is built for. Show the server's name on the project. The model is then told that the project is for one of the customer's servers, and its list of servers marks which, so a copy goes there unless the customer names another. A link gives the model nothing more: it still asks before a file reaches a server, every time.
List the servers the customer can choose from.
curl "https://api.coritan.com/api/v1/orgs/acme/workspace/builder/servers" \
-H "Authorization: Bearer $CUSTOMER_TOKEN"
{
"items": [
{"id": "0b7d2f4e-5a6c-4d8e-9f10-2a3b4c5d6e7f", "name": "Lobby", "software": "Paper", "state": "running"},
{"id": "3c9e1a7b-8d2f-4b6a-a1c3-5e7f9a1b3c5d", "name": "Survival", "software": "Fabric", "state": "offline"}
]
}
The list holds the customer's own servers and the servers another customer shared with them with the right to add files, by name, 50 at most. It leaves out a server whose service is suspended, cancelled or ending. software is empty when the server names none. state is running, starting, stopping, offline or unknown, or installing, install_failed or transferring while one of those holds the server up. A customer with no such server gets an empty list. The same list serves the assistant's chats, which link to a server in the same way.
Link the project when you start it, by sending the server's id as server.
curl -X POST "https://api.coritan.com/api/v1/orgs/acme/workspace/builder/sessions" \
-H "Authorization: Bearer $CUSTOMER_TOKEN" -H "Content-Type: application/json" \
-d '{"title": "Greeter plugin", "server": "0b7d2f4e-5a6c-4d8e-9f10-2a3b4c5d6e7f"}'
The project answers "server": {"id": "0b7d2f4e-5a6c-4d8e-9f10-2a3b4c5d6e7f", "name": "Lobby"}.
Link it later, link it to another server or unlink it with PATCH.
curl -X PATCH "https://api.coritan.com/api/v1/orgs/acme/workspace/builder/sessions/6f2b7c1e-3a4d-4e5f-8a9b-0c1d2e3f4a5b" \
-H "Authorization: Bearer $CUSTOMER_TOKEN" -H "Content-Type: application/json" \
-d '{"server": "3c9e1a7b-8d2f-4b6a-a1c3-5e7f9a1b3c5d"}'
| Body | What it does |
|---|---|
{"server": "<id>"} |
Links the project to that server, in the place of the one it was linked to. |
{"server": null} |
Unlinks the project. It changes nothing for a project with no link. |
A body without server |
Leaves the link as it is, so a rename does not unlink a project. |
A project has one linked server. A change takes effect with the customer's next message.
Both routes answer 422 with You have no server with that id. for a server that is not on the customer's list: an id that names nothing, another customer's server, a suspended one and text that is no id all read the same. Nothing is created or changed. PATCH answers 409 for an archived project, whose link can no longer change.
server is read again each time a project is answered. When the server is deleted or suspended, or a share is taken back, the project answers "server": null. When the customer renames the server, the project answers the new name.
Send a message
Section titled Send a messagecurl -X POST "https://api.coritan.com/api/v1/orgs/acme/workspace/builder/sessions/6f2b7c1e-3a4d-4e5f-8a9b-0c1d2e3f4a5b/messages" \
-H "Authorization: Bearer $CUSTOMER_TOKEN" -H "Content-Type: application/json" \
-d '{"text": "Add a /greet command that welcomes a player by name.", "model": "claude-sonnet-5"}'
{
"run": {"id": 81, "status": "queued", "step": 0, "model": "claude-sonnet-5", "error": null,
"started_at": null, "finished_at": null},
"message": {"id": 412, "seq": 1, "role": "user",
"content": [{"type": "text", "text": "Add a /greet command that welcomes a player by name."}],
"created_at": "2026-11-15T10:03:40Z"}
}
The answer is 202: the message is saved and the run waits its turn. model is the id of an entry of models in the config answer, and text holds 1 to 20,000 characters.
The route asks whether the customer may use that model before it saves anything. When they may not, it answers 402:
{"detail": {"code": "add_funds", "message": "Your balance is too low for this model. Add funds to go on."}}
code is one of the codes in Say why a customer cannot use a paid model, or no_price when model is not a paid model on offer. Show message, with the button that fits the code. A run asks the same question again before each call it makes. When the customer's credit runs out during a run, the run stops and its error holds the same sentence.
The route answers 409 while a run is live in the project, because a project works on one message at a time. It also answers 409 for an archived project. In both cases detail is a sentence for the customer.
GET .../messages answers the saved conversation as {"messages": [...]}. A message's content is a list of blocks. A text block holds what the customer or the model wrote. A tool_use block holds what the model asked a tool to do, as {type, id, name, input}. A tool_result block holds what the tool answered, as {type, tool_use_id, content, is_error}.
Follow a run
Section titled Follow a runA run reports what it does as events. Read them a page at a time, or follow them as they happen.
curl -N "https://api.coritan.com/api/v1/orgs/acme/workspace/builder/sessions/6f2b7c1e-3a4d-4e5f-8a9b-0c1d2e3f4a5b/events/stream?after=1040" \
-H "Authorization: Bearer $CUSTOMER_TOKEN" -H "Accept: text/event-stream"
: connected
id: 1041
event: status
data: {"run_id":81,"state":"thinking"}
id: 1042
event: text_delta
data: {"run_id":81,"text":"I will add the command to "}
: keepalive
The stream is server-sent events. Each frame has id (the event's id), event (its kind) and data (its payload as JSON). A line that starts with a colon is a comment: the stream opens with : connected and sends : keepalive after 15 quiet seconds. It ends after 15 minutes. Connect again from the last id you received, in the Last-Event-ID header or as after.
Send Accept: text/event-stream, or the frames arrive together when the stream ends. A browser's EventSource cannot send the Authorization header, so read the stream with fetch and the customer's token.
event |
data |
When |
|---|---|---|
run_started |
{run_id, model} |
A message started a run. |
status |
{run_id, state} |
The run moved on. state is thinking, running_tool, waiting_approval, waiting_workspace, updating_workspace, compacting or retrying. A retry also holds tries, retry_in (seconds) and error. |
text_delta |
{run_id, text} |
The model wrote the next piece of its answer. |
message |
{message_id, seq, role, content} |
A message was saved. It replaces the pieces that came before it. |
tool_call |
{run_id, tool_use_id, name, input, requires_approval} |
The model asked a tool to do something. |
tool_output |
{run_id, tool_use_id, text} |
A command that is running wrote output. |
tool_result |
{run_id, tool_use_id, is_error, summary} |
A tool finished. summary is one line of its answer. |
approval_requested |
{run_id, tool_use_id, name, input, summary} |
The run shows a card and waits for the customer. |
approval_resolved |
{run_id, tool_use_id, decision} |
The customer answered the card. |
usage |
{run_id, spent} |
The model made a call. spent is what the project has cost, as the project answers it. |
pushed |
{run_id, sha, branch, files} |
The run pushed a commit to the project's branch. |
branch |
{run_id, branch, base_branch} |
The project moved to a new branch. |
pull_request |
{run_id, number, url, state} |
The run opened or updated a pull request. |
deployed |
{run_id, tool_use_id, server, destination, bytes, sha256} |
A file reached one of the customer's servers. server is {id, name}. |
workspace |
{status} |
The workspace changed state, in the words of workspace.status. A locked workspace reads failed here: read the project for the exact word. |
run_finished |
{run_id, status, error} |
The run ended. error is null or a sentence to show the customer. |
Ignore a kind you do not know, so that a kind we add later does not break your page.
GET .../events answers the same events as {"events": [{id, kind, payload, created_at}], "last_id": 1042}. Pass last_id as after to read on. run_id keeps one run's events, and tail=true answers no events and the newest id. We keep events for seven days. The conversation stays in the messages after that.
To draw a project when the page opens:
- Read the project and its messages.
- When
active_runis notnull, read the events of that run withrun_id, and draw the run from them. Otherwise readtail=truefor the cursor. - Follow the stream from that cursor. Draw
text_deltapieces as they arrive, and replace them with eachmessage. - On
run_finished, read the project again forspent,last_runand the pull request.
POST .../runs/{run_id}/cancel stops a run. It ends at its next step, and run_finished says so.
Ask before a file reaches a server
Section titled Ask before a file reaches a serverThe model can copy one file from the workspace to one of the customer's own servers, such as a plugin it built. It never does so without the customer's yes.
The run sends
approval_requested, and its status becomeswaiting_approval. Show a card withsummary, which reads likeCopy build/libs/Greeter.jar to Lobby as plugins/Greeter.jar?.Post the customer's answer with the event's
tool_use_id.Shellcurl -X POST "https://api.coritan.com/api/v1/orgs/acme/workspace/builder/sessions/6f2b7c1e-3a4d-4e5f-8a9b-0c1d2e3f4a5b/approvals/toolu_01A9" \ -H "Authorization: Bearer $CUSTOMER_TOKEN" -H "Content-Type: application/json" \ -d '{"decision": "approve"}'decisionisapproveordeny. The answer is{"run": {...}}.After
approve, the run copies the file and sendsdeployed. The customer restarts the server to load it: a run never starts, stops or restarts a server. Afterdeny, the model is told that the customer said no.
The time a card waits does not count towards the run's time limit. The route answers 409 when that card is no longer waiting.
Show the workspace's files
Section titled Show the workspace's filesGET .../changes answers what the project changed since its last push, as {"files": [{path, status, additions, deletions}], "diff": "...", "truncated": false}. GET .../files?path=src lists one level of a folder as {"entries": [{path, type, size}]}, and GET .../files/content?path=src/Greeter.java reads a file as {"content": "...", "size": 412, "truncated": false, "binary": false}. A path is relative to the project's root. An absolute path, or one that holds .., answers 422.
These three routes never wake a workspace. While workspace.status is not ready they answer 409 with The workspace is asleep. Send a message to wake it.. A workspace sleeps when nothing has used it for a while, and a message wakes it. To let a customer look at the files without sending a message, call POST .../workspace/wake and wait for workspace.status to become ready. The wake route answers 409 with a sentence when another of the customer's projects is working or when your store's workspaces are all in use.
Support sessions
Section titled Support sessionsA support session can read the list of a customer's projects and one project's facts: its title, its state, the server it is linked to and what it has cost. It can also read the list of servers a project can be linked to. It cannot read a project's messages, events, changes or files: each answers 403 with A support session cannot read a project's conversation or files. It also cannot start a project, rename or archive one, link one to a server, name a repository, send a message, stop a run, answer a card or wake a workspace: each answers 403. Only the customer, with their own sign-in, starts work that costs them credit or sends a file to their server.
Tell customers who can read a project
Section titled Tell customers who can read a projectSay this where the customer works with a paid model, in your own words. Coritan's staff can read a project's conversation and its files when they investigate abuse. Your own staff see what a customer used and what it cost, and never the conversation or the code.
Result
Section titled ResultYour storefront shows the workspace page to customers when the assistant's config says workspace: true. The page holds the free chat, a model switch with your prices, the customer's balance and usage, and their monthly limit. A customer can connect their GitHub account, see the repositories they chose and create a new one. While builder is true, a customer who may use a paid model starts a project, sends it a message, follows the run and answers its card.
Limits
Section titled Limits- A customer can change their monthly limit 30 times an hour. Past that the route answers
429. limiton the usage route is 1 to 100, and 20 when you leave it out.- The most a customer may spend in a day is
account.daily_cap. A new account can have a lower cap for its first days. Ask Coritan support to change your caps. - The free model keeps the assistant's limits, which
free.messages_per_minuteandfree.messages_per_dayhold. - A support session can read the config and the usage. It cannot change the monthly limit (
403) or use a paid model. - A customer can start, finish and disconnect a GitHub connection 10 times an hour in all, and read the repository and branch lists 120 times an hour. Past that the routes answer
429. - A customer can create 10 repositories an hour. A request that GitHub refuses counts, and one with a bad
nameordescriptiondoes not. Past that the route answers429. - Nothing in the workspace deletes or renames a repository, or changes its settings. The customer does that on GitHub.
- One GitHub account connects to one customer of your store, and one customer to one GitHub account. Connecting again replaces the customer's earlier account.
pageon the repository list is 1 to 100.- A support session can read the GitHub connection and the two lists. It cannot connect, finish a connection, disconnect or create a repository (
403). - A project works on one message at a time. A second message answers
409until the run ends or the customer stops it. - A run works for a limited time and a limited number of steps. When it reaches either, it stops with a sentence in
error, and the next message goes on from there. - A customer keeps a limited number of projects that are not archived. Past it, starting a project answers
409with a sentence. Archiving a project makes room. - In one hour a customer can send 60 messages, stop a run 120 times, answer 30 cards, wake a workspace 30 times and read the workspace's files 600 times. Starting a project, renaming or archiving one, linking it to a server and naming its repository count together, 20 an hour. Reading the list of servers is not counted. Past a limit the route answers
429. - A project has one repository. Nothing a run does deletes a branch, pushes with force or pushes to the branch the project started from.
- A support session can read a customer's projects. It cannot change one, send a message, answer a card or wake a workspace (
403).
Troubleshooting
Section titled Troubleshooting- Every route answers
404 - Your organization does not have the workspace, or the path names another organization. Ask Coritan support to turn it on.
- A route answers
401 - The token is missing, expired or belongs to another organization's customer. Sign the customer in again, or refresh the token.
PUT /workspace/limitanswers422- The body is not
{"monthly_limit": ...}with an amount from0.01to10000that has at most two decimals, ornull. Thedetailof the answer is a sentence that says what the field takes. modelsis empty- No paid model is on offer yet. Show the free model alone.
- A project route answers
422withYou have no server with that id. - The
serveryou sent is not on the customer's list. ReadGET /workspace/builder/serversagain and send anidfrom it. A server leaves the list when its service is suspended or cancelled, or when a share is taken back. POST /workspace/github/authorizeanswers409- Your store has no GitHub App yet, and
github.availableisfalse. Ask Coritan support to set it up. POST /workspace/github/linkanswers400,403or409400: the ticket was already used, is older than 15 minutes, or was not made for your store.403: another customer started the connection.409: another customer of your store has connected that GitHub account. In each case thedetailis a sentence for the customer. Offer to connect again.- The repository list is empty
- When
installationsis0, the customer has not chosen repositories for your store's App. Send them toinstall_url. Otherwise no repository matchesq, or the ones they chose are archived. - A list answers
429or502 429: the customer read the lists more than 120 times in an hour, or GitHub is limiting requests.502: GitHub could not be reached. Try again in a few minutes.GET /workspace/github/branchesanswers422repositoryis not writtenowner/name, as GitHub shows it.POST /workspace/github/repositoriesanswers403for a customer who may create repositories on GitHub- Your store's App may not have the Administration permission yet. An App made before repositories could be created here keeps the permissions it was made with. Ask Coritan support to add the permission. Each customer then accepts it on GitHub. Until then the customer can create the repository on GitHub and choose it for your store.
- A new repository is not in the repository list
reachablewasfalse: the customer chose selected repositories for your store's App, so GitHub did not add the new one. Send them toinstall_urlto choose it.- A builder route answers
404withThere is no such project. - The
session_uuidis not a project of the signed-in customer. A customer reaches only their own projects. POST .../messagesanswers402- The customer may not use that model now.
detail.codesays why anddetail.messageis a sentence to show them. Nothing was saved, so the customer can send the message again once the cause is gone. POST .../messagesanswers409- A run is still live in the project, or the project is archived. Wait for
run_finished, or stop the run first. - The events of the stream arrive all at once
- The request did not send
Accept: text/event-stream, so the answer was compressed and held back until the stream ended. - The file routes answer
409 - The workspace is asleep, is starting, or the project has none yet. Call
POST .../workspace/wake, or let the customer send a message, and wait forworkspace.statusto becomeready. - A run ended with
Something went wrong on our side. Try again in a moment. - The run failed for a reason the customer cannot act on. Let them send the message again. If it keeps happening, contact Coritan support with the project's
uuid.