## Create a new API key `client.APIKeys.New(ctx, body) (*APIKey, error)` **post** `/v1/api_keys` Creates a new API key in the workspace. ### Parameters - `body APIKeyNewParams` - `Metadata param.Field[CreateResourceMetadata]` CreateResourceMetadata contains the user-provided fields for creating a workspace-scoped resource. Read-only fields (id, account_id, workspace_id, profile_id, created_at) are excluded since they are set by the server. - `Spec param.Field[APIKeySpec]` APIKeySpec contains the API Key-specific fields ### Returns - `type APIKey struct{…}` APIKey represents a workspace-scoped API key. Each API key belongs to exactly one workspace, ensuring workspace isolation. Authentication is handled via Cadenya-issued JWTs signed with the key's own signing secret. - `Metadata ResourceMetadata` Standard metadata for persistent, named resources (e.g., agents, tools, prompts) - `ID string` Unique identifier for the resource (prefixed ULID, e.g., "agent_01HXK...") - `AccountID string` Account this resource belongs to for multi-tenant isolation (prefixed ULID) - `CreatedAt Time` Timestamp when this resource was created - `Name string` Human-readable name for the resource (e.g., "Customer Support Agent", "Email Tool") Required for resources that users interact with directly - `ProfileID string` ID of the actor (user or service account) that created this resource - `WorkspaceID string` Workspace this resource belongs to for organizational grouping (prefixed ULID) - `ExternalID string` External ID for the resource (e.g., a workflow ID from an external system) - `Labels map[string, string]` Arbitrary key-value pairs for categorization and filtering Examples: {"environment": "production", "team": "platform", "version": "v2"} - `Spec APIKeySpec` APIKeySpec contains the API Key-specific fields - `Token string` The actual token value (only returned on creation and rotation, read-only) - `Description string` Description of what this API Key is used for - `Info APIKeyInfo` - `CreatedBy Profile` Profile represents a human user at the account level. Profiles are account-scoped resources that can be associated with multiple workspaces through the Actor model. Authentication for profiles is handled via SSO/OAuth (WorkOS). - `Metadata AccountResourceMetadata` AccountResourceMetadata is used to represent a resource that is associated to an account but not to a workspace. - `ID string` Unique identifier for the resource (prefixed ULID, e.g., "apikey_01HXK...") - `AccountID string` Account this resource belongs to for multi-tenant isolation (prefixed ULID) - `Name string` Human-readable name for the resource (e.g., "Customer Support Agent", "Email Tool") Required for resources that users interact with directly - `ProfileID string` - `ExternalID string` External ID for the resource (e.g., a workflow ID from an external system) - `Labels map[string, string]` Arbitrary key-value pairs for categorization and filtering Examples: {"environment": "production", "team": "platform", "version": "v2"} - `Spec ProfileSpec` ProfileSpec contains the profile-specific fields - `Type ProfileSpecType` Type is the type of profile. User's are humans, API keys are computers. You know the deal. - `const ProfileSpecTypeProfileTypeUser ProfileSpecType = "PROFILE_TYPE_USER"` - `const ProfileSpecTypeProfileTypeAPIKey ProfileSpecType = "PROFILE_TYPE_API_KEY"` - `const ProfileSpecTypeProfileTypeSystem ProfileSpecType = "PROFILE_TYPE_SYSTEM"` - `Email string` Email address of the user (required, unique per account) - `Name string` Display name for the user (e.g., "Bobby Tables") ### Example ```go package main import ( "context" "fmt" "github.com/cadenya/cadenya-go" "github.com/cadenya/cadenya-go/option" "github.com/cadenya/cadenya-go/shared" ) func main() { client := cadenya.NewClient( option.WithAPIKey("My API Key"), ) apiKey, err := client.APIKeys.New(context.TODO(), cadenya.APIKeyNewParams{ Metadata: cadenya.F(shared.CreateResourceMetadataParam{ Name: cadenya.F("name"), }), Spec: cadenya.F(cadenya.APIKeySpecParam{ }), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", apiKey.Metadata) } ``` #### Response ```json { "metadata": { "id": "id", "accountId": "accountId", "createdAt": "2019-12-27T18:11:19.117Z", "name": "name", "profileId": "profileId", "workspaceId": "workspaceId", "externalId": "externalId", "labels": { "foo": "string" } }, "spec": { "token": "token", "description": "description" }, "info": { "createdBy": { "metadata": { "id": "id", "accountId": "accountId", "name": "name", "profileId": "profileId", "externalId": "externalId", "labels": { "foo": "string" } }, "spec": { "type": "PROFILE_TYPE_USER", "email": "email", "name": "name" } } } } ```