GridBase
    Console

    Search the API reference

    Find an endpoint by name or path

    Account

    The caller's own account: profile, roles, API tokens, workspaces and request history. Every route here is scoped to whoever the token belongs to — there is no user id in any path.

    GET/account/profile
    PATCH/account/profile
    GET/account/request-logs
    GET/account/roles
    GET/account/tokens
    POST/account/tokens
    DEL/account/tokens/{token_id}
    GET/account/tokens/{token_id}
    PATCH/account/tokens/{token_id}
    POST/account/tokens/{token_id}/revoke
    GET/account/tokens/{token_id}/usage
    GET/account/workspaces
    POST/account/workspaces
    DEL/account/workspaces/{workspace_id}
    GET/account/workspaces/{workspace_id}
    PATCH/account/workspaces/{workspace_id}
    How account behaves

    Shapes

    • Collections are {meta, items} with count inside meta; single objects and every successful mutation are {meta, item}.
    • A mutation returns the resource it changed, not a status word.
    • Errors are always the error body with a machine code and the request_id. A 200 never carries an error.
    • An oversized limit is refused with limit_exceeded, not clamped.
    • An unknown sort field is refused with the allow-list in detail.allowed, not silently replaced by the default.
    • Partial writes are PATCH, because the body has always been partial.
    • Token secrets are not returned by any read. See List Tokens.

    Rate limiting

    These routes count against your token's rate limit, like every other route here. Exceeding it returns rate_limited (429).

    A dashboard polling these should rely on the response cache below rather than on being unmetered.

    Caching

    Every route here declares its caching, and the answer shows up in the response headers. All of them send Cache-Control: no-store and Vary: Authorization: the cache is the server's own and ends there, so a browser never holds a copy the server cannot invalidate.

    Cached per caller, 60s, X-Cache-Status: HIT|MISS with X-Cache-Tier: private-live:

    • GET /account/profile
    • GET /account/roles
    • GET /account/workspaces
    • GET /account/workspaces/{workspace_id}

    The subject is part of the cache key, so a hit can only ever be served back to the caller who produced it. Any write to your account drops all four, so your own PATCH is visible on your next GET rather than up to 60s later — including writes on another resource, since active_tokens on the profile moves when you create or revoke a token. The one case the TTL rather than invalidation covers: a workspace shared with you that its owner edits, which you may read up to 60s stale.

    Not cached, X-Cache-Status: BYPASS:

    • every /account/tokens route, including usage. This is the credential surface, and a stale answer here is the one you read during an incident — a revoked token still listed as live. There is nothing to win either; max_tokens is single digits.
    • GET /account/request-logs. Every request changes it, including that one.
    • every POST, PATCH and DELETE.

    The cache headers are declared before the handler runs, so they reach the client on a miss as well as a hit.

    How these examples were produced

    Response examples on the read routes were captured from a real account and then redacted: ids, emails and token fragments are replaced with placeholders of the same shape. Field names, types, presence and ordering are as the server returns them.

    The workspace write routes were exercised end to end against production as a self-cleaning round trip — create, read back, duplicate-name conflict, patch, clear a field with null, delete, confirm 404, confirm no residue — so their behaviour here is observed, though the example bodies are redacted.

    The token create, revoke and delete routes were exercised end to end with a throwaway token — created with a one-day expiry, used twice so the auth middleware cached it, revoked, confirmed to be rejected with 401 on the very next call, then deleted and confirmed gone. That round trip is what verifies the cache eviction described in Revoke Token.

    Token update was verified only as far as its refusals — every validation, quota and conflict response in this folder was exercised against production and is reproduced verbatim — because its success path writes to a working key. Its example is constructed from the handler and says so.

    Get Profile

    GET/api/v2/account/profile

    The caller's own user record, quotas, and the facts about their newest usable token.

    Example response (captured, redacted): { "item": { "id": "8a16b84e-0000-0000-0000-000000000000", "email": "someone@example.com", "allow_email": true, "disabled": false, "clerk_user_id": "user_00000000000000000000000000", "last_login_at": "2025-11-17T11:32:59.719847Z", "created_at": "2024-09-07T12:02:14.356858Z", "updated_at": "2025-11-17T11:32:59.827312Z", "quotas": { "max_tokens": 5, "max_rate_limit": 50, "active_tokens": 1, "v2_account": { "requests_per_minute": 50, "history_days": 7, "denied_groups": ["power_grid", "tariffs", "incentives"] } }, "trial_ends_at": "2029-09-09T12:04:01.547Z", "rate_limit": 10000, "token_scope": "api" }, "meta": { "source": "users" } }

    Always present: id, email, allow_email, disabled, created_at, updated_at, quotas (with all three of its original fields).

    quotas.v2_account is what your subscription entitles you to on v2, and is a different thing from max_rate_limit beside it: that one is a per-token ceiling applied when a token is minted, a v1 concept. This one is account-wide and shared by all of your tokens.

    • requests_per_minute — one allowance for every token you own
    • history_days — how far back from may reach on endpoints that serve a row per reading, interval, event or day. Omitted when history is unlimited
    • denied_groups — endpoint groups your plan does not include at all. Calling one answers 403 plan_required. Omitted when nothing is withheld

    v2_account is present on every plan, because every plan has a per-minute allowance:

    planrequests_per_minutehistory_daysdenied_groups
    Free507power_grid, tariffs, incentives
    Standard500omitted (no floor)omitted
    Enterprise10000omitted (no floor)omitted

    history_days is omitted on a paid plan because there is no floor to report. The field appearing at all is what tells you one applies to you, and denied_groups works the same way.

    Read denied_groups before rendering navigation rather than after a 403. The group names are subtrees, and two of them cover more than their name suggests: power_grid also withholds /geo/nearby/power-grid/** and /signals/renewable, and tariffs also withholds /geo/zip/{postal_code}/utility-rates. The v2 folder documentation has the full table.

    The whole object is omitted only if the limits cannot be read — this is the route you come to in order to find out why you were throttled, so it answers even then rather than failing. Treat its absence as "unknown", not as "unlimited".

    Omitted when they do not apply, rather than sent empty:

    • clerk_user_id, oauth_provider — an account that predates Clerk has neither
    • last_login_at — a user who has never signed in
    • trial_ends_at, rate_limit, token_scope — these three describe the caller's newest non-revoked, unexpired token, and are omitted together when there is no such token. They are not account fields; with no token there is nothing for them to describe.

    Worth knowing

    • the record is under item, with meta alongside
    • disabled is included
    • a failure reading the token count is a 500 with a request_id. Swallowing it and reporting active_tokens: 0 gives the one value certain to be wrong — the caller is holding a token as it asks.
    curl "https://utility-api-86672132515.us-east1.run.app/api/v2/account/profile" \
      -H "Authorization: $GRIDBASE_API_KEY"
    Try it in the Explorer

    Update Profile

    PATCH/api/v2/account/profile

    Updates the caller's own preferences and returns the full profile.

    PATCH on the profile. There is one account, and a partial write to it is a PATCH of that account — "preferences" would name a body with one field in it rather than a resource.

    Body: allow_email (boolean). A body that sets no updatable field is refused rather than treated as a no-op write:

    // 400
    {
      "code": "invalid_param",
      "message": "request body must set at least one updatable field",
      "field": "allow_email",
      "request_id": "..."
    }

    The response is byte-for-byte the shape Get Profile returns, including quotas and the token fields — two endpoints returning the same resource return the same fields, so a client can render the result of its write without a follow-up GET.

    curl -X PATCH "https://utility-api-86672132515.us-east1.run.app/api/v2/account/profile" \
      -H "Authorization: $GRIDBASE_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
      "allow_email": true
    }'

    List Request Logs

    GET/api/v2/account/request-logs

    The caller's own API request history, newest first.

    Query parameters

    • limitrequirede.g. 50
    • offsetrequirede.g. 0
    • token_idoptional

    Example response (captured, redacted, truncated to 2 items): { "meta": { "source": "auth_token_request_log", "as_of": "2026-10-30T10:54:46.7054Z", "count": 2, "limit": 50, "offset": 0, "total": 3085129 }, "items": [ { "at": "2026-10-30T10:54:46.7054Z", "token_id": "81bb7015-0000-0000-0000-000000000000", "endpoint": "/api/power-grid/us/nyiso/load-forecast", "method": "GET", "status_code": 200, "response_time_ms": 0, "cached": true, "client_ip": "203.0.113.7" }, { "at": "2026-10-30T10:54:46.489288Z", "token_id": "81bb7015-0000-0000-0000-000000000000", "endpoint": "/api/power-grid/us/nyiso/load-forecast", "method": "GET", "status_code": 200, "response_time_ms": 63, "cached": false, "client_ip": "203.0.113.7" } ] }

    at is a real RFC3339 time value, not a pre-formatted string — formatting it server-side truncates the sub-second precision the column holds.

    token_id and dir, snake_case like the fields they filter and sort on.

    response_time_ms and client_ip are null, not omitted, when unrecorded. The question applies to every request and the answer is genuinely unknown; omitting them reads as "instant" and "no address" rather than "not measured". Make them nullable in any generated schema.

    cached reports a response-cache hit, not a token-cache hit. It is set by middleware.ResponseCache and is the more useful of the two signals, but the name does not say which — noted here because it is not guessable.

    meta.total is the real row count behind the filter, so a caller comparing it against offset + count knows whether more pages exist.

    No meta.coverage: the endpoint takes no from/to, so there is no requested window for a served window to differ from, and the field-presence rule omits what does not apply. meta.as_of carries the freshness of the page.

    Filtering by a token_id the caller does not own is 404 not_found, not an empty page — an empty page reads as "that token made no requests" rather than "that is not your token".

    limit defaults to 50, maximum 1000. Above that:

    // 400
    {
      "code": "limit_exceeded",
      "message": "requested more rows than this endpoint serves in one page",
      "field": "limit",
      "request_id": "...",
      "detail": { "requested": 5000, "max": 1000 }
    }

    Refused, not clamped: silently returning 1000 rows to a caller who asked for 5000 cannot be told apart from there being only 1000.

    curl "https://utility-api-86672132515.us-east1.run.app/api/v2/account/request-logs?limit=50&offset=0" \
      -H "Authorization: $GRIDBASE_API_KEY"
    Try it in the Explorer

    Get Roles

    GET/api/v2/account/roles

    The caller's roles.

    {meta, items}, like every other collection here — a bare {"roles": [...]} has nowhere to put a count or a source.

    Each item is an object, not a bare string, so a role can gain a field later (when it was granted, by whom) without the element type changing from string to object underneath clients already reading it. A list of one-key objects looks redundant today; changing items[0] from "admin" to {"role": "admin"} after release does not.

    items is [] for a user with no roles, never null.

    curl "https://utility-api-86672132515.us-east1.run.app/api/v2/account/roles" \
      -H "Authorization: $GRIDBASE_API_KEY"
    Response200
    {
      "meta": { "source": "user_roles", "count": 2 },
      "items": [
        { "role": "admin" },
        { "role": "contributor" }
      ]
    }
    Try it in the Explorer

    List Tokens

    GET/api/v2/account/tokens

    Both are always present. A token that has never been narrowed reports the default rather than omitting the fields, so "what can this key do" is answerable from the record instead of by making a request and reading the refusal. Filled for the whole page in one query.

    Query parameters

    • limitrequirede.g. 100
    • offsetrequirede.g. 0
    • sortrequirede.g. created_at
    • dirrequirede.g. desc

    Every token reports its capability

    • api_versions: which API versions it may call (default ["v1","v2"])
    • access: "read" or "write" on /api/v2 (default "read")

    Both are always present. A token that has never been narrowed reports the default rather than omitting the fields, so "what can this key do" is answerable from the record instead of by making a request and reading the refusal. Filled for the whole page in one query.

    The caller's API tokens.

    ** The token secret is not in this response. **

    No token secret is returned by any read. Listing the full token string for every token a user owns makes a request log, a browser cache, a proxy, or a screenshot of that response equivalent to the credentials themselves — and one such capture yields all of them at once.

    v2 returns token_prefix (first 8 characters) and token_last4, which is enough to match a row against a token someone is holding and not enough to use it. The secret is returned exactly once, by Create Token, which is the only moment it cannot be recovered any other way.

    The secret is shown once, by Create Token, and never again.

    Example response (captured, redacted): { "meta": { "source": "auth_token", "count": 2, "limit": 100, "offset": 0 }, "items": [ { "id": "81bb7015-0000-0000-0000-000000000000", "token_prefix": "xxxxxxxx", "token_last4": "xxxx", "description": null, "scope": "api", "rate_limit": 10000, "revoked": false, "expired": false, "expires_at": "2029-09-09T12:04:01.547Z", "created_at": "2024-09-07T12:04:01.703262Z", "allowed_cidrs": [] }, { "id": "9e1134bc-0000-0000-0000-000000000000", "token_prefix": "xxxxxxxx", "token_last4": "xxxx", "description": "Clerk token for someone@example.com", "scope": "clerk_auth", "rate_limit": 250, "revoked": false, "expired": true, "expires_at": "2025-11-30T19:23:51.661897Z", "created_at": "2025-10-31T19:23:51.72435Z", "allowed_cidrs": [] } ] }

    items[].id is the token's uuid, and it is the value every other token route takes in its path — one name for it on every route.

    expired is computed from expires_at against the server clock, so three clients do not each derive it and disagree at the boundary. A token can be revoked: false, expired: true — see Get Token Usage for usable, which combines them.

    allowed_cidrs is always present and [] when unrestricted — null there reads as "unknown" where it means "no restriction".

    description is null, not omitted: every token has the field and the answer here is genuinely unset.

    No meta.total. The only count available counts live tokens while items includes revoked and expired ones, so reporting it would send count: 2, total: 1 for the account above. A total that disagrees with the page is worse than no total, and this collection does not paginate in practice — max_tokens is single digits for every account.

    sort: created_at (default), expires_at, rate_limit, revoked. dir: asc | desc (default asc).

    Deliberately not sortable: id, the internal int32 key that is not exposed — ordering by a field the client cannot see is an ordering it cannot verify — and token, which orders by the secret and is unobservable as well as meaningless.

    An empty page is 200 with items: []. A 404 says the collection does not exist when the truth is that it is empty, and makes a caller paging past the end special-case a 404 as success.

    curl "https://utility-api-86672132515.us-east1.run.app/api/v2/account/tokens?limit=100&offset=0&sort=created_at&dir=desc" \
      -H "Authorization: $GRIDBASE_API_KEY"
    Try it in the Explorer

    Create Token

    POST/api/v2/account/tokens

    Both default rather than inheriting the creating token's capability, which is how a privilege propagates without anyone deciding to grant it. A token created with no capability fields is read-only on v2.

    Capability (new)

    • api_versions: ["v1","v2"] by default. Which API versions the new token may call. Only "v1" and "v2" are accepted.
    • access: "read" by default. "read" permits GET/HEAD; "write" also permits POST/PUT/PATCH/DELETE on /api/v2.

    Both default rather than inheriting the creating token's capability, which is how a privilege propagates without anyone deciding to grant it. A token created with no capability fields is read-only on v2.

    Note that a v2 write also requires the caller to hold the contributor role. Token capability and role are intersected: granting a token "write" does not grant the user permission, and holding the role does not make a read-only token writable.

    Issues a new API token. Returns 201.

    ** This is the only response in all of v2 that contains a token secret, and the only chance to read it. ** No read route returns it; see List Tokens.

    Example response (captured from production with a throwaway token that was revoked and deleted immediately afterwards; the secret is not reproduced, and the request that produced it used the description below rather than the illustrative body above): { "item": { "id": "7c4f1a2b-0000-0000-0000-000000000000", "token": "<44 characters, base64url — store this now>", "description": "zz-revocation-test (delete me)", "scope": "api", "rate_limit": 5, "expires_at": "2026-10-31T11:10:50.569194Z" }, "meta": { "source": "auth_token", "warnings": [ "this is the only response that contains the token secret; store it now" ] } }

    item.id is the uuid the other token routes take in their path, read back after creation so a client never has to list the collection to learn the id of the thing it just made.

    Body, all optional:

    • description — defaults to "User-created API token"
    • rate_limit — defaults to the account's max_rate_limit; must be >= 1 and <= max_rate_limit
    • expiry_days — defaults to 30; must be 1..365
    • scope — defaults to "api"; must be "api" or "service"

    scope is validated against that set. Passed through as free text, a token can be created with any label at all, including "admin". Scope grants no privilege today — authorization runs off user_roles — but a field whose values are unconstrained cannot later be made to mean something without auditing whatever is already in the column.

    // 403
    {
      "code": "quota_exceeded",
      "message": "all of your token slots are in use; revoke one to create another",
      "request_id": "...",
      "detail": { "used": 5, "allowed": 5 }
    }
    // 403
    {
      "code": "quota_exceeded",
      "message": "requested rate limit is above your account maximum",
      "request_id": "...",
      "detail": { "used": 999999, "allowed": 50 }
    }
    // 400
    {
      "code": "invalid_param",
      "message": "expiry_days is outside the permitted range",
      "field": "expiry_days",
      "request_id": "...",
      "detail": { "min": 1, "max": 365 }
    }
    // 400
    {
      "code": "invalid_param",
      "message": "unknown scope",
      "field": "scope",
      "request_id": "...",
      "detail": { "allowed": ["api", "service"] }
    }

    quota_exceeded is deliberately distinct from limit_exceeded. The difference matters to a client: a page that is too large is fixed by asking for less, a quota is fixed by an account change, and only one of those is worth retrying with different parameters. Collapsing them into one 403 with a machine code in a field named error gives a caller neither the right status nor a shape it already parses.

    curl -X POST "https://utility-api-86672132515.us-east1.run.app/api/v2/account/tokens" \
      -H "Authorization: $GRIDBASE_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
      "description": "terminal on the trading desk",
      "rate_limit": 25,
      "expiry_days": 30,
      "scope": "api"
    }'

    Delete Token

    DELETE/api/v2/account/tokens/{token_id}

    Permanently removes a token row. Prefer `Revoke Token` — revoking stops the token working and keeps the record.

    Path parameters

    • token_idrequired

    Example response (captured from production, deleting a throwaway token): { "item": { "id": "81bb7015-0000-0000-0000-000000000000", "deleted": true }, "meta": { "source": "auth_token" } }

    The id is echoed so a client issuing several deletes can match responses to requests, and deleted: true is there because a bare {} reads as a response that failed to populate. No prose a client would have to match on.

    The caller's cached credentials are evicted on delete, as on revoke — a deleted row the auth cache still holds is a credential with no record behind it. See Revoke Token.

    auth_token_request_log keeps its own token_id, so deleting a token does not erase its history; List Request Logs will still show rows for it, and Get Token on that id will 404.

    curl -X DELETE "https://utility-api-86672132515.us-east1.run.app/api/v2/account/tokens/{token_id}" \
      -H "Authorization: $GRIDBASE_API_KEY"

    Get Token

    GET/api/v2/account/tokens/{token_id}

    One of the caller's tokens, in the same shape `List Tokens` returns its items.

    Path parameters

    • token_idrequired

    Reads one token. Without it, a client holding an id from a create call has to fetch the whole collection to see the record it just made.

    Set TOKEN_ID from List Tokens (items[].id).

    Example response (captured, redacted): { "item": { "id": "81bb7015-0000-0000-0000-000000000000", "token_prefix": "xxxxxxxx", "token_last4": "xxxx", "description": null, "scope": "api", "rate_limit": 10000, "revoked": false, "expired": false, "expires_at": "2029-09-09T12:04:01.547Z", "created_at": "2024-09-07T12:04:01.703262Z", "allowed_cidrs": [] }, "meta": { "source": "auth_token" } }

    A token belonging to someone else returns 404 not_found, the same as one that does not exist:

    404 { "code": "not_found", "message": "token not found", "request_id": "..." }

    A 403 "this token does not belong to you" would confirm the id is a live token on the platform and turn the route into an oracle for probing uuids.

    A malformed id is 400 invalid_param with field: "token_id".

    curl "https://utility-api-86672132515.us-east1.run.app/api/v2/account/tokens/{token_id}" \
      -H "Authorization: $GRIDBASE_API_KEY"
    Try it in the Explorer

    Update Token

    PATCH/api/v2/account/tokens/{token_id}

    Both are optional like every other field here, so taking write access off a token is a one-field request:

    Path parameters

    • token_idrequired

    Capability (new)

    • api_versions: replace the version list, e.g. ["v1"] to stop a token calling v2. [] means it may call neither. null is refused.
    • access: "read" or "write". null is refused.

    Both are optional like every other field here, so taking write access off a token is a one-field request:

    PATCH /api/v2/account/tokens/{token_id}
    {"access": "read"}

    A capability change is effective immediately on the instance that served the PATCH, and within 60 seconds everywhere. The cache is per process and the service runs several instances, so "immediately" is not the guarantee -- the 60-second ceiling is. If a narrowing has to be instant, revoke the token instead: revocation is enforced by the auth layer ahead of this check.

    The contributor role is not cached at all, so granting or removing it takes effect on the very next request.

    Setting one of the two leaves the other alone; the new value is resolved against what the token has now, not against the default.

    Changes a token's description, CIDR allow-list or expiry. Returns the updated token in the List Tokens item shape.

    PATCH. The body is a partial update: the fields you send are written and the ones you omit are left alone. Calling that PUT invites a client to send a whole resource and have most of it silently ignored.

    Body, at least one of:

    • description (string, or null to clear it)
    • allowed_cidrs (array of CIDR strings; [] means unrestricted)
    • expires_at (RFC3339; must be in the future)

    ** Absent and null mean different things. ** Omitting description leaves it; sending "description": null clears it. A token always has an expiry and always has an allow-list, so those two have no cleared state and null on either is refused:

    400 { "code": "invalid_param", "message": "expires_at cannot be null", "field": "expires_at", ... } 400 { "code": "invalid_param", "message": "allowed_cidrs cannot be null; send [] to remove all restrictions", "field": "allowed_cidrs", ... }

    A body setting none of them is refused rather than performing a write that changes nothing:

    // 400
    {
      "code": "invalid_param",
      "message": "request body must set at least one of allowed_cidrs, description, expires_at",
      "field": "body",
      "request_id": "..."
    }
    // 400
    {
      "code": "invalid_param",
      "message": "one or more entries are not valid CIDR notation",
      "field": "allowed_cidrs",
      "request_id": "...",
      "detail": { "invalid": "banana" }
    }
    // 400
    {
      "code": "invalid_param",
      "message": "expires_at must be in the future",
      "field": "expires_at",
      "request_id": "..."
    }

    ** expires_at is capped at 365 days from now ** — the same ceiling Create Token applies to expiry_days. Enforcing it only at create would make it advisory: mint a one-day token, then extend it indefinitely. Checking only that the date is in the future does not close that.

    // 400
    {
      "code": "invalid_param",
      "message": "expires_at is further ahead than a token may be extended",
      "field": "expires_at",
      "request_id": "...",
      "detail": { "max_days_from_now": 365, "latest": "2027-10-30T11:10:32Z" }
    }

    Editing a revoked or expired token is 409 conflict — the request is well formed and the token's state is what refuses it:

    // 409
    {
      "code": "conflict",
      "message": "this token is revoked and can no longer be edited",
      "request_id": "..."
    }
    // 409
    {
      "code": "conflict",
      "message": "this token has expired and can no longer be edited; create a new one",
      "request_id": "..."
    }

    The request is well-formed in both cases; it is the token's state that makes it impossible, and a 400 sends the caller looking for a mistake in a request that does not have one.

    Refusing to edit an expired token also closes a quota bypass. max_tokens counts only live tokens, so a user at their limit whose token has lapsed could create a replacement and then PATCH the lapsed one back to life — ending up with more live credentials than the quota allows, without ever failing a check.

    A successful update evicts the caller's cached credentials, because expires_at and allowed_cidrs are both cached by the auth middleware — otherwise narrowing a CIDR allow-list would not take effect until the token expired. See Revoke Token for the detail.

    curl -X PATCH "https://utility-api-86672132515.us-east1.run.app/api/v2/account/tokens/{token_id}" \
      -H "Authorization: $GRIDBASE_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
      "description": "renamed from the desk terminal",
      "allowed_cidrs": ["203.0.113.0/24"]
    }'

    Revoke Token

    POST/api/v2/account/tokens/{token_id}/revoke

    Disables a token without deleting it or its history. Returns the token in the `List Tokens` item shape, with `revoked: true`.

    Path parameters

    • token_idrequired

    Idempotent. Revoking an already-revoked token returns 200 with the same body as revoking a live one, because the caller's intent — "this token must not work" — holds either way, and a client retrying after a timeout should not have to distinguish the two.

    Revoking an already-revoked token is the same 200 and the same body as the first call — one success shape for one outcome.

    ** The token stops working immediately. ** Worth stating because it is not free.

    The auth middleware caches tokens in a 5,000-entry LRU, and TokenCache.Get returns a cached entry whenever the token's own expiry is still in the future — it never re-reads revoked. So a token that has served one authenticated request keeps working until it expires on its own, which for a long-lived key is years. Revoke, update and delete all call InvalidateByUserID to evict the entry.

    Verified end to end against production with a throwaway token: created, used twice so the middleware cached it, revoked, and the next call with it returned 401 rather than 200. The eviction is logged:

    token cache invalidated after credential change entries_evicted=2
      path="/api/v2/account/tokens/:token_id/revoke" request_id=... user_id=...

    entries_evicted is often more than one: InvalidateByUserID is the only invalidation the cache exposes, so every token the user holds is evicted, including the one making the request. That costs its next call one DB round trip. The alternative is a credential that outlives its own revocation.

    Revoke is almost always what is wanted over Delete Token: the token stops working immediately and its request history stays attributable.

    curl -X POST "https://utility-api-86672132515.us-east1.run.app/api/v2/account/tokens/{token_id}/revoke" \
      -H "Authorization: $GRIDBASE_API_KEY"

    Get Token Usage

    GET/api/v2/account/tokens/{token_id}/usage

    Current rate-limit consumption for one token.

    Path parameters

    • token_idrequired

    Example response (captured, redacted): { "item": { "token_id": "81bb7015-0000-0000-0000-000000000000", "current_usage": 2, "rate_limit": 10000, "remaining": 9998, "resets_at": "2026-10-30T10:57:00Z", "expires_at": "2029-09-09T12:04:01.547Z", "scope": "api", "revoked": false, "expired": false, "usable": true }, "meta": { "source": "rate_limiter", "coverage": { "from": "2026-10-30T10:56:00Z", "to": "2026-10-30T10:57:00Z" } } }

    usable is !revoked && !expired — the one field a caller actually branches on, computed server-side so three clients do not each derive it from two booleans and a clock and disagree at the boundary.

    meta.coverage is the limiter's current minute bucket, not a window the caller asked for. A usage reading is only meaningful alongside the window it was taken in, and resets_at is that window's end.

    ** A revoked or expired token still reports its usage. ** Answering HTTP 200 with {"error": "token is revoked"} and no usage fields at all puts an error inside a success and withholds the history a caller is asking for — which is exactly what you want to read after revoking something.

    A 200 carrying an error key is the worst of both: a client checking the status code sees success, and a client checking for an error field has to check it on every 200 from every endpoint in case this one is the exception.

    A revoked or expired token is not an error here. The resource exists and its state is exactly what was asked about, so the full usage object is returned either way (constructed example):

    current_usage and remaining are 0 for an unusable token because nothing may be spent through it — the limiter is not consulted at all.

    curl "https://utility-api-86672132515.us-east1.run.app/api/v2/account/tokens/{token_id}/usage" \
      -H "Authorization: $GRIDBASE_API_KEY"
    Response200
    {
      "item": {
        "token_id": "...",
        "current_usage": 0,
        "rate_limit": 250,
        "remaining": 0,
        "resets_at": "...",
        "expires_at": "2025-11-30T19:23:51.661897Z",
        "scope": "clerk_auth",
        "revoked": false,
        "expired": true,
        "usable": false
      },
      "meta": { "source": "rate_limiter", "coverage": { ... } }
    }
    Try it in the Explorer

    List Workspaces

    GET/api/v2/account/workspaces

    Every workspace the caller owns or has been given access to.

    Query parameters

    • limitrequirede.g. 100
    • offsetrequirede.g. 0
    • sortrequirede.g. name
    • dirrequirede.g. asc

    Example response (captured, redacted and truncated to 1 of 6 items): { "meta": { "source": "workspace", "count": 6, "limit": 100, "offset": 0 }, "items": [ { "id": "6276014a-0000-0000-0000-000000000000", "name": "NYISO", "description": "NYISO Vitals", "settings": { "period": "previous-period", "sensors": ["67aa1607-...", "0e6c8eeb-..."], "dateRange": { "from": "...", "to": "..." } }, "is_owner": true, "can_write": true, "created_at": "2025-08-12T10:10:03.028989Z", "updated_at": "2025-09-10T09:53:58.054761Z" } ] }

    is_owner and can_write describe the caller's access, not the workspace: the same workspace has different values here for two different users. That is why the response is a projection and not the table row — returning the raw sqlc row makes the response shape change whenever the query does.

    settings is always an object, {} when nothing is configured — null there forces a client merging defaults into it to test for null first.

    description is null rather than omitted: the field applies to every workspace and is genuinely unset here.

    sort: created_at, name (default). dir: asc (default) | desc.

    Deliberately not sortable: id. Ordering by a uuid is an ordering no caller can predict, and the query's deterministic fallback already keeps paging stable.

    Note for anyone comparing against production data: at least one existing workspace has an empty name, created before v2. The v2 create and update routes refuse an empty or whitespace-only name, but existing rows are served as they are — this is a read path and v2 does not rewrite stored data.

    curl "https://utility-api-86672132515.us-east1.run.app/api/v2/account/workspaces?limit=100&offset=0&sort=name&dir=asc" \
      -H "Authorization: $GRIDBASE_API_KEY"
    Try it in the Explorer

    Create Workspace

    POST/api/v2/account/workspaces

    Creates a workspace owned by the caller. Returns **201** and the workspace in the `Get Workspace` shape, including `is_owner` and `can_write`.

    Body

    • name — required, non-empty after trimming
    • description — optional
    • settings — optional, defaults to {}; an explicit null is also stored as {}, so settings is an object in every later read of the row rather than null for whoever created it that way

    ** The body is an explicit request type, not the sqlc params struct. ** Binding straight onto db.CreateWorkspaceParams makes the accepted body whatever that generated struct happens to contain — user_id included. A caller could then send user_id and have it silently overwritten with their own, which is safe but means the API accepts a field that looks like it does something and does not. This route accepts the three fields above and nothing else.

    // 400
    {
      "code": "missing_param",
      "message": "name is required",
      "field": "name",
      "request_id": "..."
    }

    A duplicate name is 409 conflict, not a 400 — the request is well formed and the collision is a state conflict:

    // 409
    {
      "code": "conflict",
      "message": "you already have a workspace with this name",
      "field": "name",
      "request_id": "..."
    }

    Names are unique per user, so this is a collision with existing state rather than a malformed request — the same body succeeds for a different user, and succeeds for this user once the other workspace is renamed.

    The response is read back through the access query rather than projected from the insert, because the insert returns the table row, which has no is_owner or can_write. A create response missing fields the GET returns is a create response a client cannot reuse.

    curl -X POST "https://utility-api-86672132515.us-east1.run.app/api/v2/account/workspaces" \
      -H "Authorization: $GRIDBASE_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
      "name": "PJM desk",
      "description": "zonal LMP watchlist",
      "settings": {}
    }'

    Delete Workspace

    DELETE/api/v2/account/workspaces/{workspace_id}

    Deletes a workspace the caller may write.

    Path parameters

    • workspace_idrequired

    Example response (constructed from the handler; the delete path was not run against production): { "item": { "id": "6276014a-0000-0000-0000-000000000000", "deleted": true }, "meta": { "source": "workspace" } }

    Same {id, deleted} item as Delete Token, so a client handling both does not need two code paths, and both carry the id.

    ** Requires ownership, not write access. **

    // 403
    {
      "code": "forbidden",
      "message": "only the workspace owner can delete it",
      "request_id": "..."
    }

    can_write is true for any collaborator who is not read-only, and "may edit the contents" is not "may destroy the container" — otherwise a shared workspace is deletable out from under its owner by anyone they shared it with. The query is DELETE FROM workspace WHERE id = $1 with no user predicate, so this check is the only thing between a collaborator and someone else's row.

    Owner only, which is what "only the owner can delete the workspace" means — gating it on can_write would let anyone the workspace is shared with destroy it.

    Contrast Update Workspace, which is gated on can_write: editing a shared workspace is the point of sharing it.

    404 not_found when the caller cannot see the workspace at all.

    Verified for the owner path only — the test account has no shared workspaces, so the 403 above is from reading the code, not from a captured response.

    curl -X DELETE "https://utility-api-86672132515.us-east1.run.app/api/v2/account/workspaces/{workspace_id}" \
      -H "Authorization: $GRIDBASE_API_KEY"

    Get Workspace

    GET/api/v2/account/workspaces/{workspace_id}

    One workspace, in the same shape `List Workspaces` returns its items.

    Path parameters

    • workspace_idrequired

    Set WORKSPACE_ID from List Workspaces (items[].id).

    Example response (captured, redacted): { "item": { "id": "6276014a-0000-0000-0000-000000000000", "name": "NYISO", "description": "NYISO Vitals", "settings": { "period": "previous-period", "sensors": [] }, "is_owner": true, "can_write": true, "created_at": "2025-08-12T10:10:03.028989Z", "updated_at": "2025-09-10T09:53:58.054761Z" }, "meta": { "source": "workspace" } }

    404 { "code": "not_found", "message": "workspace not found", "request_id": "..." }

    A workspace the caller cannot see is indistinguishable from one that does not exist — the underlying query filters by access, so there is nothing to disclose and nothing to special-case.

    {meta, item}, like every other single object here.

    curl "https://utility-api-86672132515.us-east1.run.app/api/v2/account/workspaces/{workspace_id}" \
      -H "Authorization: $GRIDBASE_API_KEY"
    Try it in the Explorer

    Update Workspace

    PATCH/api/v2/account/workspaces/{workspace_id}

    Changes a workspace the caller may write. Returns the updated workspace.

    Path parameters

    • workspace_idrequired

    Body, at least one of:

    • name (non-empty after trimming)
    • description (string or null — null clears it)
    • settings (object)

    ** Absent and null mean different things. ** {"settings": {...}} leaves the description alone; {"description": null} clears it. Both were verified against production:

    PATCH {"settings":{"a":1}}   -> description unchanged
    PATCH {"description":null}   -> description becomes null
    PATCH {"description":"x"}    -> description becomes "x"

    The second needs absent and null to be distinguishable. A plain *string cannot do it: encoding/json leaves one nil for an absent key and for an explicit null alike, so substituting the stored value whenever it is nil means a description can never be cleared by any request.

    name and settings have no cleared state to ask for: a workspace always has a name, and its settings are {} when empty. Null on either is refused rather than read as "leave it alone", which would make the request look honoured:

    400 { "code": "invalid_param", "message": "name cannot be null", "field": "name", ... } 400 { "code": "invalid_param", "message": "settings cannot be null; send {} to clear", "field": "settings", ... }

    // 400
    {
      "code": "invalid_param",
      "message": "request body must set at least one of name, description, settings",
      "field": "body",
      "request_id": "..."
    }

    400 { "code": "invalid_param", "message": "name cannot be empty", "field": "name", ... }

    409 conflict on a duplicate name, as Create Workspace.

    Read-only access is 403 forbidden, not 404:

    // 403
    {
      "code": "forbidden",
      "message": "you have read-only access to this workspace",
      "request_id": "..."
    }

    403 rather than 404 here because read access already proved the workspace exists — there is nothing left to conceal, and the caller needs to tell "no such workspace" from "ask the owner". Contrast Get Workspace, where a workspace the caller cannot see is 404.

    curl -X PATCH "https://utility-api-86672132515.us-east1.run.app/api/v2/account/workspaces/{workspace_id}" \
      -H "Authorization: $GRIDBASE_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
      "description": "zonal LMP watchlist, east"
    }'