Skip to content

Key-Value Store API

The KV Store provides persistent key-value storage for Terrateam installations. These endpoints allow you to store, retrieve, and manage data across workflow runs.

Store or update a key-value pair.

Endpoint: PUT /api/v1/{vcs}/kv/{installation_id}/key/{key}

Path Parameters:

NameTypeRequiredDescription
vcsstringYesVCS provider: github or gitlab
installation_idstringYesThe installation identifier
keystringYesThe key name

Request Body:

Content-Type: application/json

Schema: kv-set

{
"data": "string",
"idx": 0,
"committed": false,
"read_caps": [],
"write_caps": []
}
FieldTypeRequiredDescription
datastringYesThe value to store (JSON stringified if needed)
idxintegerNoIndex for versioning (default: 0)
committedbooleanNoWhether to commit the value immediately
read_capsarrayNoArray of read capability restrictions for this key
write_capsarrayNoArray of write capability restrictions for this key

Responses:

  • 200: Success - Returns the stored record
  • 403: Forbidden

Response Schema (200):

Schema: kv-record

{
"key": "string",
"data": "string",
"idx": 0,
"version": 1,
"committed": true,
"created_at": "2025-01-15T10:30:00Z",
"size": 1024,
"read_caps": [],
"write_caps": []
}
FieldTypeRequiredDescription
keystringYesThe key name
datastringYesThe stored value
idxintegerYesIndex version
versionintegerYesRecord version for optimistic locking
committedbooleanYesWhether the record is committed
created_atstringYesISO 8601 timestamp of when the record was created
sizeintegerYesSize of the stored data in bytes
read_capsarrayNoArray of read capability restrictions for this key
write_capsarrayNoArray of write capability restrictions for this key

Example Request:

Terminal window
curl -X PUT \
https://app.terrateam.io/api/v1/github/kv/{installation_id}/key/my-key \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"data": "my-value", "idx": 0}'

Retrieve a value by key.

Endpoint: GET /api/v1/{vcs}/kv/{installation_id}/key/{key}

Path Parameters:

NameTypeRequiredDescription
vcsstringYesVCS provider: github or gitlab
installation_idstringYesThe installation identifier
keystringYesThe key name

Query Parameters:

NameTypeRequiredDescription
committedbooleanNoOnly return committed values
idxintegerNoSpecific index to retrieve
selectarray[string]NoFields to select from the record

Responses:

  • 200: Success - Returns the record
  • 403: Forbidden
  • 404: Not Found

Response Schema (200):

Schema: kv-record

Example Request:

Terminal window
curl -X GET \
"https://app.terrateam.io/api/v1/github/kv/{installation_id}/key/my-key?committed=true" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Delete a key-value pair.

Endpoint: DELETE /api/v1/{vcs}/kv/{installation_id}/key/{key}

Path Parameters:

NameTypeRequiredDescription
vcsstringYesVCS provider: github or gitlab
installation_idstringYesThe installation identifier
keystringYesThe key name

Query Parameters:

NameTypeRequiredDescription
idxintegerNoSpecific index to delete
versionintegerNoVersion number for optimistic locking

Responses:

  • 200: Success
  • 403: Forbidden

Response Schema (200):

Schema: kv-delete

{
"result": true
}
FieldTypeDescription
resultbooleanWhether the key was successfully deleted

Atomically update a value only if it matches the expected version.

Endpoint: PUT /api/v1/{vcs}/kv/{installation_id}/cas/key/{key}

Path Parameters:

NameTypeRequiredDescription
vcsstringYesVCS provider: github or gitlab
installation_idstringYesThe installation identifier
keystringYesThe key name

Request Body:

Content-Type: application/json

Schema: kv-cas

{
"data": "string",
"idx": 0,
"version": 1,
"committed": false,
"read_caps": [],
"write_caps": []
}
FieldTypeRequiredDescription
datastringYesThe new value to store
idxintegerNoIndex for versioning
versionintegerYesExpected current version (CAS will fail if version doesn’t match)
committedbooleanNoWhether to commit the value immediately
read_capsarrayNoArray of read capability restrictions for this key
write_capsarrayNoArray of write capability restrictions for this key

Responses:

  • 200: Success - Returns the updated record
  • 400: Bad Request - CAS condition failed (version mismatch)
  • 403: Forbidden

Response Schema (200):

Returns a kv-record (see Set Value endpoint for schema details)

Example Request:

Terminal window
curl -X PUT \
https://app.terrateam.io/api/v1/github/kv/{installation_id}/cas/key/my-key \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"data": "new-value", "version": 1}'

Retrieve multiple keys matching a pattern or prefix.

Endpoint: GET /api/v1/{vcs}/kv/{installation_id}/iter/{key}

Path Parameters:

NameTypeRequiredDescription
vcsstringYesVCS provider: github or gitlab
installation_idstringYesThe installation identifier
keystringYesThe key or key prefix

Query Parameters:

NameTypeRequiredDescription
committedbooleanNoOnly return committed values
idxintegerNoStarting index for iteration
limitintegerNoMaximum number of records to return
include_databooleanNoInclude record data in response
inclusivebooleanNoInclude the starting key in results
prefixbooleanNoTreat key as prefix for matching
selectarray[string]NoFields to select from records

Responses:

  • 200: Success - Returns list of records
  • 403: Forbidden

Response Schema (200):

Schema: kv-record-list

{
"records": [
{
"key": "string",
"data": "string",
"idx": 0,
"version": 1,
"committed": true
}
]
}
FieldTypeDescription
recordsarrayArray of kv-record objects (see Set Value for record schema)

Example Request:

Terminal window
curl -X GET \
"https://app.terrateam.io/api/v1/github/kv/{installation_id}/iter/my-prefix?prefix=true&limit=100" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Count the number of keys matching a pattern or prefix.

Endpoint: GET /api/v1/{vcs}/kv/{installation_id}/count/key/{key}

Path Parameters:

NameTypeRequiredDescription
vcsstringYesVCS provider: github or gitlab
installation_idstringYesThe installation identifier
keystringYesThe key or key prefix

Query Parameters:

NameTypeRequiredDescription
committedbooleanNoOnly count committed values

Responses:

  • 200: Success - Returns the count
  • 403: Forbidden

Response Schema (200):

Schema: kv-count

{
"count": 42,
"max_idx": 5
}
FieldTypeDescription
countintegerNumber of keys matching the query
max_idxintegerMaximum index value among the counted keys

Get the storage size of a key or key prefix.

Endpoint: GET /api/v1/{vcs}/kv/{installation_id}/size/key/{key}

Path Parameters:

NameTypeRequiredDescription
vcsstringYesVCS provider: github or gitlab
installation_idstringYesThe installation identifier
keystringYesThe key or key prefix

Query Parameters:

NameTypeRequiredDescription
committedbooleanNoOnly measure committed values
idxintegerNoSpecific index to measure

Responses:

  • 200: Success - Returns the size
  • 403: Forbidden
  • 404: Not Found

Response Schema (200):

Schema: kv-size

{
"size": 1024
}
FieldTypeDescription
sizeintegerSize in bytes of the stored data

Commit a batch of KV operations atomically.

Endpoint: POST /api/v1/{vcs}/kv/{installation_id}/commit

Path Parameters:

NameTypeRequiredDescription
vcsstringYesVCS provider: github or gitlab
installation_idstringYesThe installation identifier

Request Body:

Content-Type: application/json

Schema: kv-commit

{
"keys": [
{
"key": "string",
"idx": 0
}
]
}
FieldTypeRequiredDescription
keysarrayYesArray of key objects to commit
keys[].keystringYesThe key name to commit
keys[].idxintegerNoOptional index for the key

Responses:

  • 200: Success - Returns commit result
  • 403: Forbidden

Response Schema (200):

Schema: kv-commit-result

{
"keys": [
{
"key": "string",
"idx": 0
}
]
}
FieldTypeDescription
keysarrayArray of committed key objects
keys[].keystringThe key name that was committed
keys[].idxintegerThe index that was committed

Example Request:

Terminal window
curl -X POST \
https://app.terrateam.io/api/v1/github/kv/{installation_id}/commit \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"keys": [{"key": "my-key", "idx": 0}]}'

The KV Store is useful for:

  • Sharing state between workflow runs
  • Storing metadata and configuration
  • Implementing counters and locks
  • Caching expensive computations
  • Coordinating across multiple pull requests

All endpoints require authentication using a short-lived access token:

Authorization: Bearer YOUR_ACCESS_TOKEN

To get an access token:

  1. Create an API key in Settings > API Access in the Terrateam dashboard
  2. Call POST /api/v1/access-token/refresh with your API key to get an access token
  3. Use the access token for API requests

See the Authentication guide for detailed instructions.