REST API
Reference for the Coder REST API, including endpoints, authentication, and schemas.
On this page
Get started with the Coder API:
Set up your environment
Set up your environmentThe code samples on each endpoint's page read your deployment URL and a session token from two environment variables, CODER_URL and CODER_SESSION_TOKEN, the same ones the Coder CLI reads.
If you are logged in with the Coder CLI v2.31.1 or later and have jq installed, set both from your login:
export CODER_URL="$(coder whoami -o json | jq -r '.[0].url')"
export CODER_SESSION_TOKEN="$(coder login token)"For scripts and CI, create a long-lived token instead, with coder tokens create or under Settings > Tokens in the dashboard:
coder tokens create --name ci --lifetime 30dStore the token in your secret store, and set the variables from it where the script runs:
export CODER_URL="https://coder.example.com"
export CODER_SESSION_TOKEN="$(cat /run/secrets/coder-token)"Keep the token out of your shell history and out of committed files.
Quickstart
QuickstartGenerate a token on your Coder deployment by visiting:
https://coder.example.com/settings/tokensList your workspaces
# CLI
curl https://coder.example.com/api/v2/workspaces?q=owner:me \
-H "Coder-Session-Token: <your-token>"Use cases
Use casesSee some common use cases for the REST API.
Request size limits
Request size limitsAn endpoint that accepts a request body reads at most 4 MiB of it, unless it
sets a limit of its own.
An endpoint that sets its own limit declares 413 in this reference and
names the limit in the description, so the per-endpoint page is where to look
one up. A few endpoints answer 413 for a reason other than the size of
the request body, and their descriptions say so.
A body that exceeds the limit that applies to it is answered with
413 Payload Too Large, and the response names the limit it exceeded:
{
"message": "Request body too large.",
"detail": "Maximum request body size is 4194304 bytes."
}The limits are fixed. There is no deployment option that raises them.
Sections
SectionsGeneral
AI Gateway
List AI Gateway clients GET
Alias: also available at /api/v2/aibridge/clients for backward compatibility.
List AI Gateway models GET
Alias: also available at /api/v2/aibridge/models for backward compatibility.
List AI Gateway sessions GET
Alias: also available at /api/v2/aibridge/sessions for backward compatibility.
Get AI Gateway session threads GET
Alias: also available at /api/v2/aibridge/sessions/{session_id} for backward compatibility.
AI Providers
Agents
Applications
Audit
Authorization
Builds
Get workspace build secrets GET
Lists the metadata of the secrets linked to a workspace build, including secrets whose values a later build cleared.
Chats
Connect to chat workspace desktop via WebSockets GET
Raw binary WebSocket stream of the chat workspace desktop.
List chat attachments GET
Returns every file part in the user-visible user and assistant messages of a chat, newest first, so a client can list a chat's attachments without paging through every message in the chat.
Get chat cost GET
Cost covers the whole chat tree: the root chat plus every subagent chat beneath it.
List chat user prompts GET
Returns the user-authored prompts in a chat, newest first, with each prompt's text parts concatenated in the order they were authored.
Upload a file to a chat's workspace POST
Streams the request body into the chat workspace's upload directory.
Debug
Enterprise
Get group AI spend GET
Returns the AI spend limit and aggregate spend for the group.
Get group members AI spend GET
Returns aggregate AI spend attributed to the group per requested user.
Export organization AI spend as CSV GET
Returns per-user, per-group, per-model, per-provider aggregated AI spend for the organization as CSV, built from raw AI Gateway token usage.
Get organization groups AI spend GET
Returns AI spend limits and aggregate spend for the requested groups.
Get group members AI spend by organization GET
Returns aggregate AI spend attributed to the group per requested user.
Get groups by organization (paginated) GET
Unlike "Get groups by organization" (GET /organizations/{organization}/groups), which authorizes each group individually via its ACL, this endpoint requires organization-wide group read permission…
Files
Upload file POST
Swagger notice: Swagger 2.0 doesn't support file upload with a content-type different than application/x-www-form-urlencoded.
Git
InitScript
Insights
Members
Notifications
Organizations
PortSharing
Prebuilds
Provisioning
Secrets
TemplateBuilder
Templates
Get templates by organization GET
Returns a list of templates for the specified organization.
Get all templates GET
Returns a list of templates.
Users
WorkspaceProxies
Workspaces
Create user workspace by organization POST
Create a new workspace using a template.
Create user workspace POST
Create a new workspace using a template.