k0rdent AI Docs

Common Structures

API conventions, data types, and common patterns

Standard structures and conventions used across all k0rdent APIs

This page describes the common patterns, data types, and conventions used throughout the k0rdent API to ensure consistency and predictability.

Response Envelope

All API responses use a consistent discriminated union envelope structure with a success boolean discriminator.

Type Definition

Success Response

Error Response

Meta Object

The meta object is always present in responses and contains request tracking information.

Base Meta Fields

FieldTypeDescription
requestIdstringUnique request identifier for log correlation
timestampstringISO 8601 timestamp (UTC) for distributed debugging

Extended Meta Types

Success responses can extend meta with additional context:

Pagination Meta:

Workflow Meta:

Resource Identifiers

Resources use globally unique, opaque IDs that do NOT contain region information. This decouples resource identity from physical location.

ID Format

Format: {prefix}_{base62}

Resource ID Prefixes

ResourcePrefixExample
Organizationorg_org_8TcVx2WkZddNmK3Pt9JwX7BzWrLM
Serversrv_srv_3KpQm9WnXccFjH2Ls8DkT6VzRqYU
Clustercls_cls_6NZtkvWLBbbmHfPi7L6oz7KZpqET
Stackstk_stk_5MfRp4WjYbbHmG8Nt2LvS9CxPqZK
Workflow Runrun_run_7NhTq6WlAbbKmF5Rt3MxU8DzSqWJ
Poolpool_pool_2LgPn8WmXccGjE7Mt4KwV9BySrTL
Allocationalloc_alloc_9QjSr3WnZddMmH6Pt5LxW2CzUrYK
API Keykey_key_4KfQm7WkYccJmG3Nt8MvX9BzSqWL
Eventevt_evt_6MgRp2WlXbbKmF9Rt5NxU3DzTqZJ

Resource IDs are 26 characters after the prefix, using base62 encoding (case-sensitive).

Request Identifiers

Every API request gets a unique Request ID for tracing, debugging, and correlation across services.

Format

Format: req_{region}-{timestamp}-{entropy}

Example

Components

  • req_ - Platform prefix for easy grepping in logs
  • sfo1 - Region code where request was processed
  • 1770564159296 - Unix timestamp in milliseconds
  • 7d4b9e1f3a5b - Random entropy (12 hex characters)

Request IDs are returned in the X-Request-Id response header and meta.requestId field.

Naming Conventions

URL Paths

RuleExample
Lowercase, hyphenated/ai-services
Plural nouns for collections/servers, /clusters
Singular for singletons/me, /health
Colon-prefixed route params/clusters/:clusterId

Field Names

RuleExample
camelCasecreatedAt, nodeCount
Suffix IDs with IdclusterId, organizationId
Past tense for timestampscreatedAt, updatedAt, deletedAt

Dates and Timestamps

All temporal fields use ISO 8601 format and are always treated as UTC.

Common Fields

FieldDescription
createdAtWhen the object was created
updatedAtWhen the object was last updated
deletedAtWhen the object was deleted (soft delete)

Example

Use of HTTP

HTTP Methods

The k0rdent API uses standard HTTP methods:

MethodPurpose
GETRetrieve resources (read-only)
POSTCreate new resources
PATCHUpdate existing resources (partial)
DELETEDelete resources

Content Type

All requests and responses use Content-Type: application/json unless otherwise specified.

Example Request

Pagination

All list endpoints support two pagination modes: cursor-based and offset-based. The appropriate mode depends on how frequently the underlying data changes.

Choosing a Mode

CursorOffset
Best forFrequently updated dataStable, rarely changing data
ConsistencyNo skipped or duplicated items across pagesItems may shift if data changes between requests
UI patternsInfinite scroll, "load more"Page numbers, jump-to-page
total fieldNot returnedReturned

Cursor mode is recommended for resources that change frequently — active sessions, servers, API keys, clusters, instances, networks. Because the cursor anchors to a stable position in the dataset, inserting or deleting records between requests does not cause items to be skipped or duplicated on subsequent pages.

Offset mode is recommended for stable resources — roles, organizations, projects, providers, policies, groups. Offset allows UIs to display total counts and navigate directly to a page, which is useful when the dataset is bounded and predictable.

pageToken and offset are mutually exclusive. Include one or the other, not both.

Query Parameters

ParameterTypeDefaultDescription
pageTokenstringCursor token from the previous response's nextPageToken. Use for cursor-based pagination. Mutually exclusive with offset.
pageSizeinteger50Maximum number of items to return. Applies to both modes. Range: 1–500.
offsetinteger0Number of items to skip before returning results. Use for offset-based pagination. Mutually exclusive with pageToken.

Cursor-Based Example

Use for frequently updated resources (sessions, servers, API keys, clusters):

Response:

nextPageToken is absent when there are no more results. total is not returned in cursor mode.

Offset-Based Example

Use for stable resources (roles, organizations, providers, policies):

Response:

total reflects the full count of matching items, regardless of pageSize. Use it to compute page counts and display "showing X–Y of Z" UI. nextPageToken is not returned in offset mode.

total Field Caveat

total requires a COUNT(*) query on the backend and is only populated when using offset-based pagination. It is omitted (or null) in cursor mode. For large datasets, avoid relying on total in performance-critical paths — consider caching or approximate counts where precision is not required.

Filtering

You can filter resources by most attributes using query parameters:

Simple Filter

Multiple Values

Example Response

All filtered results still use the standard response envelope with pagination.

Sorting

Sort resources in ascending or descending order:

Sort Ascending

Sort Descending

Use - prefix for descending:

Multiple Sort Fields

Field Design Rules

Use Objects Over Primitives

Always wrap values that might grow into objects:

Never Use Booleans for State

States often grow beyond two values:

Use IDs with Optional Expansion

Don't embed full objects - use IDs and let clients request expansion:

Optional Fields

Unpopulated optional data is returned as follows:

  • Arrays and Objects may be returned as empty ([], {})
  • Number, String, and Boolean types may be returned as null

Clients should handle both null and empty values gracefully.

Last updated on

How is this guide?

On this page