GoodMemGoodMem
ReferenceSdkV2.NET

API Keys

API key lifecycle — create, list, update, soft-delete.

Namespace: Goodmem.Client.Api · Class: ApiKeysApi

Reach this surface as client.ApiKeys on a GoodmemClient. Every network method is asynchronous — it returns a Task<T> (or an IAsyncEnumerable<T> for pagination and streaming) and accepts a CancellationToken; the Async suffix marks the standard .NET Task-based async pattern.

Methods

MethodSummary
CreateAsyncCreate a new API key.
ListAsyncList API keys.
UpdateAsyncUpdate an API key.
DeleteAsyncDelete an API key.

CreateAsync

Creates a new API key for authenticating with the API. New keys start in ACTIVE status and can be used immediately for authentication. The response includes the one-time raw API key value which will not be retrievable later - clients must save this value as it cannot be recovered. Requires CREATE_APIKEY_OWN permission (or CREATE_APIKEY_ANY for admin users). Side effects include generating cryptographically secure key material, recording creation timestamp, and tracking creator ID. Returns INVALID_ARGUMENT if expires_at is set to a time in the past.

Declaration

public Task<CreateApiKeyResponse> CreateAsync(CreateApiKeyRequest request, CancellationToken ct = default)

HTTPPOST /v1/apikeys

Parameters

TypeNameDescription
CreateApiKeyRequestrequestThe request payload; the linked model lists every field and its JSON wire name.
CancellationTokenctCancellation / deadline signal for the call. (optional)

Returns

Task<CreateApiKeyResponse> — an awaitable that resolves to CreateApiKeyResponse.

Exceptions

TypeCondition
ArgumentNullExceptionrequest is null.
NetworkExceptionThe request could not reach the server (DNS, connection, or TLS failure).
ApiExceptionThe server returned a non-success (non-2xx) status. A status-specific subtype is thrown where it applies — e.g. NotFoundException (404), PermissionDeniedException (403), ConflictException (409).

Example

var key = await client.ApiKeys.CreateAsync(
    new CreateApiKeyRequest
    {
        Labels = new Dictionary<string, string>
        {
            ["env"] = "docs",
            ["purpose"] = "sdk-doc-test",
        },
    }
);
Console.WriteLine(key.RawApiKey); // returned only once, at creation


ListAsync

Retrieves a list of API keys belonging to the authenticated user. The list includes metadata about each key but not the actual key values or key hashes for security reasons. Requires LIST_APIKEY_OWN permission (or LIST_APIKEY_ANY for admin users to view keys from any user). This is a read-only operation with no side effects.

Declaration

public Task<ListApiKeysResponse> ListAsync(CancellationToken ct = default)

HTTPGET /v1/apikeys

Parameters

TypeNameDescription
CancellationTokenctCancellation / deadline signal for the call. (optional)

Returns

Task<ListApiKeysResponse> — an awaitable that resolves to ListApiKeysResponse.

Exceptions

TypeCondition
NetworkExceptionThe request could not reach the server (DNS, connection, or TLS failure).
ApiExceptionThe server returned a non-success (non-2xx) status. A status-specific subtype is thrown where it applies — e.g. NotFoundException (404), PermissionDeniedException (403), ConflictException (409).

Example

var resp = await client.ApiKeys.ListAsync();
foreach (var key in resp.Keys)
    Console.WriteLine($"{key.ApiKeyId} {key.Status}");


UpdateAsync

Updates an existing API key with new values for status or labels. IMPORTANT: Key ID, user ownership, key material, and audit fields cannot be modified - only status (ACTIVE/INACTIVE) and labels are mutable. Requires UPDATE_APIKEY_OWN permission for keys you own (or UPDATE_APIKEY_ANY for admin users to modify any user's keys). Side effects include updating the updated_at timestamp and recording the updater's user ID. This operation is idempotent - repeated identical requests have no additional effect.

Declaration

public Task<ApiKeyResponse> UpdateAsync(string id, UpdateApiKeyRequest request, CancellationToken ct = default)

HTTPPUT /v1/apikeys/&#123;id&#125;

Parameters

TypeNameDescription
stringidThe UUID of the API key to update
UpdateApiKeyRequestrequestThe request payload; the linked model lists every field and its JSON wire name.
CancellationTokenctCancellation / deadline signal for the call. (optional)

Returns

Task<ApiKeyResponse> — an awaitable that resolves to ApiKeyResponse.

Exceptions

TypeCondition
ArgumentExceptionid is null or empty.
ArgumentNullExceptionrequest is null.
NetworkExceptionThe request could not reach the server (DNS, connection, or TLS failure).
ApiExceptionThe server returned a non-success (non-2xx) status. A status-specific subtype is thrown where it applies — e.g. NotFoundException (404), PermissionDeniedException (403), ConflictException (409).

Example

var updated = await client.ApiKeys.UpdateAsync(
    "your-api-key-id",
    new UpdateApiKeyRequest
    {
        MergeLabels = new Dictionary<string, string> { ["updated"] = "true" },
    }
);
Console.WriteLine(updated.ApiKeyId);


DeleteAsync

Delete an API key

Permanently deletes an API key. This operation cannot be undone and immediately invalidates the key for all future authentication attempts. TIP: For reversible deactivation, use PUT /v1/apikeys/{id} with status=INACTIVE instead. Requires DELETE_APIKEY_OWN permission for keys you own (or DELETE_APIKEY_ANY for admin users to delete any user's keys). Side effects include permanently removing the key record from the database and immediate authentication invalidation.

Declaration

public Task DeleteAsync(string id, CancellationToken ct = default)

HTTPDELETE /v1/apikeys/&#123;id&#125;

Parameters

TypeNameDescription
stringidThe UUID of the API key to delete
CancellationTokenctCancellation / deadline signal for the call. (optional)

Returns

Task — completes when the operation finishes; there is no response body.

Exceptions

TypeCondition
ArgumentExceptionid is null or empty.
NetworkExceptionThe request could not reach the server (DNS, connection, or TLS failure).
ApiExceptionThe server returned a non-success (non-2xx) status. A status-specific subtype is thrown where it applies — e.g. NotFoundException (404), PermissionDeniedException (403), ConflictException (409).

Example

await client.ApiKeys.DeleteAsync("your-api-key-id");


Data Models

Types in the Goodmem.Client.Models namespace. Each row lists the C# property, its type, the JSON wire name, and a description.

CreateApiKeyRequest

Request parameters for creating a new API key.

PropertyTypeJSON (wire)Description
LabelsIReadOnlyDictionary<string, string>labelsKey-value pairs of metadata associated with the API key. Used for organization and filtering. (optional)
ExpiresAtDateTimeOffsetexpiresAtExpiration timestamp in milliseconds since epoch. If not provided, the key does not expire. (optional)
ApiKeyIdstringapiKeyIdOptional client-provided UUID for idempotent creation. If not provided, server generates a new UUID. Returns ALREADY_EXISTS if ID is already in use. (optional)

CreateApiKeyResponse

Response returned when creating a new API key.

PropertyTypeJSON (wire)Description
ApiKeyMetadataApiKeyResponseapiKeyMetadataMetadata for the created API key. (optional)
RawApiKeystringrawApiKeyThe actual API key value. This is only returned once and cannot be retrieved again. (optional)

ApiKeyResponse

API key metadata without sensitive information.

PropertyTypeJSON (wire)Description
ApiKeyIdstringapiKeyIdUnique identifier for the API key.
UserIdstringuserIdID of the user that owns this API key.
KeyPrefixstringkeyPrefixFirst few characters of the key for display/identification purposes.
StatusstringstatusCurrent status of the API key: ACTIVE, INACTIVE, or STATUS_UNSPECIFIED.
LabelsIReadOnlyDictionary<string, string>labelsUser-defined labels for organization and filtering.
ExpiresAtDateTimeOffsetexpiresAtExpiration timestamp in milliseconds since epoch. If not provided, the key does not expire. (optional)
LastUsedAtDateTimeOffsetlastUsedAtLast time this API key was used, in milliseconds since epoch. (optional)
CreatedAtDateTimeOffsetcreatedAtWhen the API key was created, in milliseconds since epoch.
UpdatedAtDateTimeOffsetupdatedAtWhen the API key was last updated, in milliseconds since epoch.
CreatedByIdstringcreatedByIdID of the user that created this API key.
UpdatedByIdstringupdatedByIdID of the user that last updated this API key.

ListApiKeysResponse

Response containing a list of API keys.

PropertyTypeJSON (wire)Description
KeysIReadOnlyList<ApiKeyResponse>keysList of API keys belonging to the authenticated user.

UpdateApiKeyRequest

Request parameters for updating an API key.

PropertyTypeJSON (wire)Description
StatusstringstatusNew status for the API key. Allowed values: ACTIVE, INACTIVE. (optional)
ReplaceLabelsIReadOnlyDictionary<string, string>replaceLabelsReplace all existing labels with this set. Mutually exclusive with mergeLabels. (optional)
MergeLabelsIReadOnlyDictionary<string, string>mergeLabelsMerge these labels with existing ones. Mutually exclusive with replaceLabels. (optional)