API Reference / API keys
Rotate an API key's secret
Gives an existing API key a new secret while keeping its id, name and policies. The current secret keeps working for the chosen grace period (none, one hour or 24 hours) so consumers can switch over, then stops. Rotating again during a grace period ends the earlier secret at once. The new secret is returned only once. A recent two-factor re-verification is required, and the key's owner is emailed.
/ accounts. v1. Accounts/ RotateAPIKeyRequest body
application/jsonRequired
Request to give an API key in the caller's workspace a new secret, keeping its id, name and policies. Requires a two-factor step-up in the last 5 minutes, and a non-administrator can rotate only their own keys.
apiKeyId?stringOpaque 16-byte identifier of the API key to rotate, base64-encoded in JSON.
Format"byte" base64
gracestringHow long the current secret keeps working after the rotation: none, one hour or 24 hours. Required.
Value in"API_"API_"API_
Response body
application/json
Success
apiKey?APIKeyThe key after rotation, with its new key prefix and, during a grace period, when the previous secret stops working.
Show attributes
createdAt?stringWhen the key was created.
Format"date-time"
createdBy?stringOpaque 16-byte identifier of the user who created the key and owns it, base64-encoded in JSON.
Format"byte" base64
expiresAt?stringWhen the key stops authenticating. Requests at or after this time are rejected as unauthenticated. Absent when the key never expires.
Format"date-time"
id?stringOpaque 16-byte identifier of the API key, assigned on creation. Base64-encoded in JSON.
Format"byte" base64
keyPrefix?stringThe first 8 characters of the secret, kept so a key can be recognised in lists. Cannot authenticate on its own.
lastUsedAt?stringWhen the key last authenticated a request. Absent when the key has never been used.
Format"date-time"
name?stringLabel chosen when the key was created, 1 to 256 characters, to tell keys apart.
policies?array<string>Names of the policies granted to the key, at least one, such as "trading" or "steam". ListPolicies lists the valid names and the permissions each grants.
previousKeyExpiresAt?stringWhen the secret this key had before its last rotation stops authenticating. A time in the past means it has stopped. Absent when the key was never rotated with a grace period, or was last rotated with none.
Format"date-time"
revealable?booleanWhether RevealAPIKey can return this key's secret. False for a key created before secrets were stored. Rotate it to make it revealable.
workspaceId?stringOpaque 16-byte identifier of the workspace the key is confined to, base64-encoded in JSON.
Format"byte" base64
rawKey?stringThe key's new secret, sent as a Bearer token in the Authorization header. Store it securely. RevealAPIKey can return it again after a two-factor step-up.
application/json
The request was malformed, such as a missing required field or an unparseable cursor.
codestringThe Connect error code, such as "not_found".
details?array<object>Optional machine-readable error details.
messagestringA human-readable description of the error.
application/json
The request lacks a valid API key in the Authorization header.
codestringThe Connect error code, such as "not_found".
details?array<object>Optional machine-readable error details.
messagestringA human-readable description of the error.
application/json
The API key is not allowed to perform this action on this workspace.
codestringThe Connect error code, such as "not_found".
details?array<object>Optional machine-readable error details.
messagestringA human-readable description of the error.
application/json
The requested resource does not exist in this workspace.
codestringThe Connect error code, such as "not_found".
details?array<object>Optional machine-readable error details.
messagestringA human-readable description of the error.
application/json
The operation was aborted, typically because of a concurrency conflict.
codestringThe Connect error code, such as "not_found".
details?array<object>Optional machine-readable error details.
messagestringA human-readable description of the error.
application/json
The request was rate limited. Slow down and retry later.
codestringThe Connect error code, such as "not_found".
details?array<object>Optional machine-readable error details.
messagestringA human-readable description of the error.
application/json
An internal server error occurred.
codestringThe Connect error code, such as "not_found".
details?array<object>Optional machine-readable error details.
messagestringA human-readable description of the error.
curl -X POST "https://api.goldmine.to/accounts.v1.Accounts/RotateAPIKey" \
-H "Authorization: Bearer $CSTRADER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"apiKeyId": "CgsMDQ4PEBESExQVFhcYGQ==",
"grace": "API_KEY_ROTATION_GRACE_ONE_HOUR"
}'const res = await fetch("https://api.goldmine.to/accounts.v1.Accounts/RotateAPIKey", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.CSTRADER_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"apiKeyId": "CgsMDQ4PEBESExQVFhcYGQ==",
"grace": "API_KEY_ROTATION_GRACE_ONE_HOUR"
}),
});
const data = await res.json();body := strings.NewReader(`{
"apiKeyId": "CgsMDQ4PEBESExQVFhcYGQ==",
"grace": "API_KEY_ROTATION_GRACE_ONE_HOUR"
}`)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, "https://api.goldmine.to/accounts.v1.Accounts/RotateAPIKey", body)
if err != nil {
return err
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("CSTRADER_API_KEY"))
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)import os, requests
res = requests.post(
"https://api.goldmine.to/accounts.v1.Accounts/RotateAPIKey",
headers={"Authorization": f"Bearer {os.environ['CSTRADER_API_KEY']}"},
json={
"apiKeyId": "CgsMDQ4PEBESExQVFhcYGQ==",
"grace": "API_KEY_ROTATION_GRACE_ONE_HOUR"
},
)
data = res.json(){
"apiKey": {
"id": "CgsMDQ4PEBESExQVFhcYGQ==",
"name": "CI deploy key",
"keyPrefix": "9c41d07e",
"workspaceId": "AAECAwQFBgcICQoLDA0ODw==",
"createdAt": "2026-06-29T12:00:00Z",
"policies": [
"trading"
],
"previousKeyExpiresAt": "2026-11-08T13:00:00Z"
},
"rawKey": "9c41d07e5b2a8f3d6e1c0b9a8f7e6d5c4b3a2918f7e6d5c4b3a29180f7e6d5c4"
}{
"code": "invalid_argument",
"message": "The request was malformed, such as a missing required field or an unparseable cursor."
}{
"code": "unauthenticated",
"message": "The request lacks a valid API key in the Authorization header."
}{
"code": "permission_denied",
"message": "The API key is not allowed to perform this action on this workspace."
}{
"code": "not_found",
"message": "The requested resource does not exist in this workspace."
}{
"code": "aborted",
"message": "The operation was aborted, typically because of a concurrency conflict."
}{
"code": "resource_exhausted",
"message": "The request was rate limited. Slow down and retry later."
}{
"code": "internal",
"message": "An internal server error occurred."
}