
Motherduck Rest Api
- 247 installs
- 53 repo stars
- Updated July 31, 2026
- motherduckdb/agent-skills
Integrate MotherDuck via REST API for programmatic queries, database management, automation, and agent-driven analytical workflows.
About
Documents how agents should use the MotherDuck REST API for authenticated programmatic access, including query execution, database operations, error handling, and embedding calls in backends or agent tooling.
- REST endpoints
- auth tokens
- programmatic SQL
- agent automation
Motherduck Rest Api by the numbers
- 247 all-time installs (skills.sh)
- +16 installs in the week ending Aug 4, 2026 (Skillselion tracking)
- Ranked #1,558 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
- Data as of Aug 4, 2026 (Skillselion catalog sync)
npx skills add https://github.com/motherduckdb/agent-skills --skill motherduck-rest-apiAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 247 |
|---|---|
| repo stars | ★ 53 |
| Last updated | July 31, 2026 |
| Repository | motherduckdb/agent-skills ↗ |
What it does
Integrate MotherDuck via REST API for programmatic queries, database management, automation, and agent-driven analytical workflows.
Files
REST API Administration
Use this skill when the user needs to manage MotherDuck service accounts, supported token operations, Duckling configuration, active accounts, or Dive embed sessions through the REST API.
Source Of Truth
- Prefer current MotherDuck REST API documentation, the public OpenAPI spec at
https://api.motherduck.com/docs/specs, or an explicit OpenAPI spec supplied by the user. - For token scope and embed behavior, cross-check the REST API docs and the Embedded Dives docs because they include operational constraints not obvious from the raw schema.
- If the MotherDuck MCP
ask_docs_questionfeature is available, use it to check whether public REST API guidance has changed. - Treat endpoint availability, preview status, token fields, and role requirements as current only when backed by the supplied spec or current docs.
Default Posture
- Treat the REST API as the control plane; SQL and data-plane queries go through a database connection, not the REST API.
- Use
https://api.motherduck.comas the base URL unless the user provides another environment. - Authenticate with
Authorization: Bearer ${MOTHERDUCK_ADMIN_TOKEN}and keep admin read-write tokens in backend-managed secrets. - Never use read-scaling tokens for REST API administration.
- Prefer read-before-write flows for configuration changes so the current account, service account, Duckling config, or Dive metadata is known before mutation.
- Treat
POST /v1/usersas service-account creation unless current docs explicitly broaden the API. - Assume active-account, Duckling configuration, service-account creation, service-account token creation, and Dive embed-session endpoints require an organization admin bearer token unless current docs say otherwise.
- Never expose generated access tokens in logs, browser code, client bundles, or committed files.
- Confirm destructive deletes with the user. Deleting a user permanently deletes that user and all of their data.
Workflow
1. Identify whether the task is service-account provisioning, token management, Duckling sizing, active-account inspection, or Dive embedding. 2. Confirm the admin token location and the target username or dive_id; never invent production identifiers. 3. Check token scope before calling token endpoints: users can create tokens for themselves, and admins can create tokens for service accounts, but admins cannot create tokens for other non-service-account members through the API. 4. For Duckling config changes, read the current config first, then update both read_write and read_scaling because the PUT payload requires both. 5. Preserve response fields that are only returned once, especially newly created token strings and embed session strings. 6. Surface API errors by status and response body; do not hide 400, 401, 403, 404, or 500 responses behind success-shaped fallbacks.
Open Next
- Read
references/REST_API_GUIDE.mdfor endpoint summaries, auth headers, request payloads, curl examples, validation limits, and operational gotchas.
Related Skills
motherduck-queryfor SQL and data-plane query workmotherduck-connectfor connection tokens and application connection posturemotherduck-security-governancefor admin-token handling, service-account posture, and access-boundary questionsmotherduck-create-divefor designing Dives before minting embed sessions
MotherDuck REST API Guide
Use this guide for control-plane workflows against https://api.motherduck.com.
The REST API is not the SQL query path. Use it for organization administration, service-account provisioning, supported token lifecycle work, Duckling configuration, active-account inspection, and Dive embed sessions.
Contents
- Authentication
- Endpoint Summary
- Service Account Provisioning
- Token Lifecycle
- Duckling Configuration
- Active Accounts
- Dive Embed Sessions
- Error Responses
Authentication
All endpoints use bearer authentication:
export MD_API="https://api.motherduck.com"
export MOTHERDUCK_ADMIN_TOKEN="<admin-token-from-secret-manager>"
curl -fsS \
-H "Authorization: Bearer ${MOTHERDUCK_ADMIN_TOKEN}" \
"${MD_API}/v1/active_accounts"Operational rules:
- Use a read-write access token for an organization Admin for admin/control-plane calls.
- Keep
MOTHERDUCK_ADMIN_TOKENin a backend secret manager or local environment variable, never source code. - Do not send admin bearer tokens to browsers.
- Do not use read-scaling tokens for REST API administration.
- Log status codes and error
codeormessage, but do not log bearer tokens or newly minted access tokens.
Endpoint Summary
| Operation | Method and path | Purpose | Notes |
|---|---|---|---|
| Create service account | POST /v1/users | Create a service account with the Member role | Username must be unique within the organization; no role field is accepted. |
| Delete user | DELETE /v1/users/{username} | Permanently delete a user and all their data | Destructive and cannot be undone. Confirm first. |
| Create token | POST /v1/users/{username}/tokens | Create an access token for a user | Response includes the token secret once. Store it immediately. |
| List tokens | GET /v1/users/{username}/tokens | List metadata for a user's tokens | Does not return token secret values. |
| Delete token | DELETE /v1/users/{username}/tokens/{token_id} | Invalidate a user access token | Use the token id, not the token secret. |
| Get Duckling config | GET /v1/users/{username}/instances | Read a user's Duckling instance configuration | Requires admin role. |
| Set Duckling config | PUT /v1/users/{username}/instances | Configure read-write and read-scaling Ducklings | Payload requires both read_write and read_scaling. |
| Get active accounts | GET /v1/active_accounts | Preview active accounts and active Ducklings | Preview endpoint; returns active Ducklings by account. |
| Create Dive embed session | POST /v1/dives/{dive_id}/embed-session | Mint an embed session for a service account | Requires username; optional session_hint can reuse read-scaling sessions. |
Service Account Provisioning
Create a service account:
curl -fsS -X POST \
-H "Authorization: Bearer ${MOTHERDUCK_ADMIN_TOKEN}" \
-H "Content-Type: application/json" \
-d '{"username":"analytics_app"}' \
"${MD_API}/v1/users"Username constraints from the runtime validator:
3..255characters- starts with a Unicode letter
- contains only Unicode letters, digits, and underscores
- unique within the organization
- case-insensitive for identity
The endpoint path says /v1/users, but it creates service accounts, not arbitrary human users or arbitrary-role users. Do not document role updates, service-account impersonation, share attachment routes, or attachment management as public REST API capabilities unless the current public spec exposes them.
Delete a user only after explicit confirmation:
curl -fsS -X DELETE \
-H "Authorization: Bearer ${MOTHERDUCK_ADMIN_TOKEN}" \
"${MD_API}/v1/users/analytics_app"The delete operation permanently deletes the user and all of their data.
Token Lifecycle
Create a read-write token:
curl -fsS -X POST \
-H "Authorization: Bearer ${MOTHERDUCK_ADMIN_TOKEN}" \
-H "Content-Type: application/json" \
-d '{"name":"backend-api","ttl":2592000,"token_type":"read_write"}' \
"${MD_API}/v1/users/analytics_app/tokens"Create a read-scaling token:
curl -fsS -X POST \
-H "Authorization: Bearer ${MOTHERDUCK_ADMIN_TOKEN}" \
-H "Content-Type: application/json" \
-d '{"name":"embed-read-scaling","ttl":86400,"token_type":"read_scaling"}' \
"${MD_API}/v1/users/analytics_app/tokens"Request fields:
name: required,1..255charactersttl: optional token lifetime in integer seconds,300..31536000; omit it for a token that remains valid until revokedtoken_type: optional,read_writeorread_scaling; defaults toread_write
Response fields include:
token: the access token secret, only returned on creationid: token UUID used for invalidationname,expire_at,created_tsread_onlytoken_type:read_writeorread_scaling
List token metadata:
curl -fsS \
-H "Authorization: Bearer ${MOTHERDUCK_ADMIN_TOKEN}" \
"${MD_API}/v1/users/analytics_app/tokens"Invalidate a token:
curl -fsS -X DELETE \
-H "Authorization: Bearer ${MOTHERDUCK_ADMIN_TOKEN}" \
"${MD_API}/v1/users/analytics_app/tokens/00000000-0000-0000-0000-000000000000"Token handling gotchas:
- Through the API, users can create tokens for themselves and admins can create tokens for service accounts.
- Admins cannot create tokens for other non-service-account members through the API.
- If a service account is newly created through the API, connect once with that service account's read-write token before relying on read-scaling tokens.
- The token secret is not returned by the list endpoint.
- Store the
idseparately from the token secret so rotation and invalidation can target the correct token. - Delete tokens by
id; do not rely on labels or names as stable deletion identifiers. - Prefer short TTLs for automation that can rotate tokens cleanly.
- Use read-scaling tokens for read-heavy serving paths that should not use the read-write Duckling.
Duckling Configuration
The endpoint path uses the legacy word instances, but it configures Ducklings.
Read a user's current Duckling configuration:
curl -fsS \
-H "Authorization: Bearer ${MOTHERDUCK_ADMIN_TOKEN}" \
"${MD_API}/v1/users/analytics_app/instances"Set read-write and read-scaling configuration:
curl -fsS -X PUT \
-H "Authorization: Bearer ${MOTHERDUCK_ADMIN_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"config": {
"read_write": {
"instance_size": "standard",
"cooldown_seconds": 600
},
"read_scaling": {
"instance_size": "standard",
"flock_size": 2,
"cooldown_seconds": 600
}
}
}' \
"${MD_API}/v1/users/analytics_app/instances"Allowed instance_size values:
pulsestandardjumbomegagiga
Validation limits:
read_write.instance_sizeis required.read_scaling.instance_sizeandread_scaling.flock_sizeare required.- The schema allows
read_scaling.flock_sizevalues between0and64, but effective limits are plan and organization specific. cooldown_seconds, when supplied, must be an integer between60and86400.cooldown_secondscannot be set forpulseDucklings.
Default cooldown behavior:
standard:60jumbo:60mega:300giga:600pulse: no cooldown
Use a read-before-write posture because PUT /v1/users/{username}/instances requires the full config object with both read_write and read_scaling. When switching an existing non-Pulse config to pulse, remove copied cooldown_seconds fields before sending the PUT.
A 400 response such as Invalid config for tier ... can mean the payload exceeded plan or organization limits even when it satisfies the OpenAPI schema.
Active Accounts
Inspect active accounts and active Ducklings:
curl -fsS \
-H "Authorization: Bearer ${MOTHERDUCK_ADMIN_TOKEN}" \
"${MD_API}/v1/active_accounts"The response has an accounts array. Each account includes:
usernameducklings[]withid,type, andstatus
Duckling fields:
id:rworrs.Ntype:read_writeorread_scalingstatus:activeorcooldown
The public OpenAPI spec marks this endpoint as preview, so avoid building brittle operational automation around response details without checking current docs.
Dive Embed Sessions
Create an embed session for a Dive:
curl -fsS -X POST \
-H "Authorization: Bearer ${MOTHERDUCK_ADMIN_TOKEN}" \
-H "Content-Type: application/json" \
-d '{"username":"analytics_app","session_hint":"customer-123"}' \
"${MD_API}/v1/dives/00000000-0000-0000-0000-000000000000/embed-session"Request fields:
username: required service account username within the organizationsession_hint: optional non-empty hint used to reuse the same read-scaling session across embed requests
Embedded Dives require a Business plan (ordinary Dives are available on all plans); verify plan requirements against current docs. Organizations without embed access should expect a 403.
The response contains an opaque session string backed by a short-lived read-scaling token that runs as the service account. Treat it as a runtime credential:
- do not persist it longer than needed
- do not log it
- do not confuse it with a user access token
- expect it to expire after 24 hours
Frontend iframe shape:
<iframe
src="https://embed-motherduck.com/sandbox/#session=<session_from_backend>"
sandbox="allow-scripts allow-same-origin"
></iframe>If the host site has a restrictive Content Security Policy, add https://embed-motherduck.com to frame-src.
Error Responses
Standard error responses use this shape:
{
"code": "BAD_REQUEST",
"message": "Bad Request",
"issues": [
{
"message": "field-specific validation message"
}
]
}Expected status codes:
400: malformed request or validation failure401: invalid credentials403: authenticated but unauthorized404: target user, token, Dive, or resource not found500: internal service error
Do not convert these into silent success. Preserve the status code and response body for the caller or operator.