TencentCloud/TencentDB-Agent-Memory · error · MetadataError

key_limit_exceeded

key_limit_exceeded

Error message

active user key limit ${this.maxActiveUserKeys} reached

What it means

MetadataError code 'key_limit_exceeded' thrown when creating a user API key if the user already has the maximum allowed active keys. The service counts the user's non-revoked, non-expired keys via countActiveUserKeys and compares against this.maxActiveUserKeys; at or above the limit, new key creation is refused. This is a quota guard against unbounded key proliferation.

Source

Thrown at MemoryCore/src/metadata/service/metadata-service.ts:692

      name: entity.name ?? null,
      status: entity.status,
      is_default: entity.is_default,
      last_used_at: entity.last_used_at ?? null,
      expires_at: entity.expires_at ?? null,
      created_at: entity.created_at,
      revoked_at: entity.revoked_at ?? null,
    };
  }

  async createUserKey(
    userId: string,
    input: { name?: string | null; expires_at?: string | null },
  ): Promise<UserKeyCreated> {
    await this.requireUser(userId);

    const active = await this.store.countActiveUserKeys(userId);
    if (active >= this.maxActiveUserKeys) {
      throw new MetadataError("key_limit_exceeded", `active user key limit ${this.maxActiveUserKeys} reached`);
    }

    const entity = await this.store.createUserKey({
      user_id: userId,
      name: input.name,
      expires_at: input.expires_at,
      is_default: false,
    });
    return { ...this.toPublicUserKey(entity), key_value: entity.key_value };
  }

  async listUserKeys(userId: string, pagination: PaginationParams = DEFAULT_PAGINATION): Promise<PaginatedResult<UserKeyPublic>> {
    await this.requireUser(userId);
    const page = await this.store.listUserKeys(userId, pagination);
    const items = page.items.map((k) => this.toPublicUserKey(k));
    return formatListResult({ items, total: page.total }, pagination);
  }

View on GitHub (pinned to 3efcd317b8)

Solutions

  1. Revoke or delete unused active keys for the user (e.g. list keys, revoke the oldest) and retry creation.
  2. Increase the maxActiveUserKeys limit in the service configuration if the quota is genuinely too low.
  3. Implement key rotation as revoke-then-create (or create-then-revoke in one flow) instead of create-only.
  4. Catch MetadataError code 'key_limit_exceeded' and prompt the user to clean up keys in the UI.

Example fix

// before
await service.createUserKeyForCaller(userId, ctx, { name: 'ci' }); // limit hit
// after
const keys = await service.listUserKeysForCaller(userId, ctx);
for (const k of keys.items.filter(k => k.name.startsWith('ci-')).slice(0, 1)) {
  await service.revokeUserKeyForCaller(k.id, ctx);
}
await service.createUserKeyForCaller(userId, ctx, { name: 'ci' });
Defensive patterns

Strategy: try-catch

Validate before calling

const active = await store.countActiveUserKeys(userId);
if (active >= maxActiveUserKeys) { /* revoke first */ }

Try / catch

try {
  await service.createUserKeyForCaller(userId, ctx, input);
} catch (e) {
  if (e instanceof MetadataError && e.code === 'key_limit_exceeded') { /* revoke oldest active key, then retry once */ }
  throw e;
}

Prevention

When it happens

Trigger: Calling the user-key creation method (guarded by requireUser) when countActiveUserKeys(userId) >= maxActiveUserKeys — i.e. creating one more key than the configured cap of active keys per user.

Common situations: Automation scripts that mint a new key on each deploy without revoking old ones; users rotating keys by creating first and forgetting to revoke; a lowered maxActiveUserKeys config that makes previously-fine key counts exceed the new limit; long-lived keys accumulating over the account's lifetime.

Related errors


AI-assisted analysis of TencentCloud/TencentDB-Agent-Memory@3efcd317b8 (2026-09-01). Data as JSON: /api/errors/b53d8a56d3e852f4. Report an issue: GitHub.