Skip to content

apitokens

Package github.com/emergent-company/emergent.memory/apps/server/pkg/sdk/apitokens

The apitokens client manages project-scoped API tokens (emt_* prefix). Tokens are used to authenticate SDK clients with Mode: "apitoken" or Mode: "apikey".

func (c *Client) Create(ctx context.Context, projectID string, req *CreateTokenRequest) (*CreateTokenResponse, error)
func (c *Client) List(ctx context.Context, projectID string) (*ListResponse, error)
func (c *Client) Get(ctx context.Context, projectID, tokenID string) (*APIToken, error)
func (c *Client) Revoke(ctx context.Context, projectID, tokenID string) error
type APIToken struct {
ID string
Name string
ProjectID string
Prefix string // First few chars of the token (for identification)
ExpiresAt *time.Time
LastUsedAt *time.Time
CreatedAt time.Time
}
type CreateTokenResponse struct {
Token string // Full token value — only returned on creation
APIToken
}
type CreateTokenRequest struct {
Name string
ExpiresAt *time.Time // nil for no expiration
}
type ListResponse struct {
Tokens []APIToken
}
// Create a token
resp, err := client.APITokens.Create(ctx, "proj_xyz", &apitokens.CreateTokenRequest{
Name: "CI/CD pipeline token",
})
if err != nil {
return err
}
// Save resp.Token — it won't be shown again
fmt.Printf("Created token prefix: %s\n", resp.Prefix)
// List tokens
list, err := client.APITokens.List(ctx, "proj_xyz")
for _, tok := range list.Tokens {
fmt.Printf("%s — %s\n", tok.Name, tok.Prefix)
}
// Revoke a token
err = client.APITokens.Revoke(ctx, "proj_xyz", "tok_abc123")