> ## Documentation Index
> Fetch the complete documentation index at: https://docs.evermind.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Count tag usage

> Count how many documents use each of the given tags, within one knowledge base.

Send the tag ids you are interested in. The response returns those actually in use, sorted by id, each with a count of the distinct documents carrying it.

Counts are read across several queries rather than from one snapshot, so a tag added or removed at that exact moment may be counted either way.



## OpenAPI

````yaml /api-reference/openapi.json post /api/v2/knowledge_bases/{kb_id}/tags
openapi: 3.1.0
info:
  title: EverOS Cloud Memory API
  version: 2.0.0
  license:
    name: Apache-2.0
    identifier: Apache-2.0
  contact:
    name: EverMind AI
    email: service@evermind.ai
    url: https://github.com/EverMind-AI/everos-cloud-sdk-python
  description: >-
    Official Python client for the EverOS Cloud Memory API. Add, search,
    retrieve, and manage long-term memory for your AI applications over a typed
    interface (pydantic v2, with full type hints). Install and usage guides:
    https://github.com/EverMind-AI/everos-cloud-sdk-python
servers:
  - url: https://api.evermind.ai
    description: Production
security:
  - BearerAuth: []
paths:
  /api/v2/knowledge_bases/{kb_id}/tags:
    post:
      tags:
        - Knowledge
      summary: Count tag usage
      description: >-
        Count how many documents use each of the given tags, within one
        knowledge base.


        Send the tag ids you are interested in. The response returns those
        actually in use, sorted by id, each with a count of the distinct
        documents carrying it.


        Counts are read across several queries rather than from one snapshot, so
        a tag added or removed at that exact moment may be counted either way.
      operationId: queryRelatedTags
      parameters:
        - name: kb_id
          in: path
          required: true
          schema:
            type: string
            title: Kb Id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RelatedTagUsageBody'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SuccessEnvelope_RelatedTagUsageListData_'
        '401':
          description: Missing or invalid bearer token.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GatewayError'
        '403':
          description: >-
            Authenticated but not permitted — either rejected by the auth
            service, or the account's memory API version does not match the
            interface version implied by the path (a v1 account calling an
            /api/v2 route).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GatewayError'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
        '429':
          description: Rate limit or quota exceeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GatewayError'
        '503':
          description: >-
            The gateway could not reach the authentication service. Transient —
            retry with backoff.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GatewayError'
components:
  schemas:
    RelatedTagUsageBody:
      properties:
        tag_ids:
          items:
            type: string
            maxLength: 128
            minLength: 1
            description: Opaque semantic tag id
          type: array
          maxItems: 10000
          minItems: 1
          title: Tag Ids
          description: Candidate opaque tag ids to check against the current live tree
      additionalProperties: false
      type: object
      required:
        - tag_ids
      title: RelatedTagUsageBody
      description: Candidate tag ids for ``POST /knowledge_bases/{kb_id}/tags``.
    SuccessEnvelope_RelatedTagUsageListData_:
      properties:
        request_id:
          type: string
          title: Request Id
          description: Request trace id (peer to data)
        data:
          $ref: '#/components/schemas/RelatedTagUsageListData'
          description: Endpoint-defined business result
      type: object
      required:
        - request_id
        - data
      title: SuccessEnvelope[RelatedTagUsageListData]
    GatewayError:
      type: object
      additionalProperties: true
      description: >-
        Gateway error body. NOTE: shape is not yet uniform across auth/quota/
        rate-limit paths — treat fields as best-effort. Commonly includes a
        `code`/`message` (flat) or an `error` object/string with a `message`.
      title: GatewayError
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
          description: One entry per field that failed validation.
      type: object
      title: HTTPValidationError
    RelatedTagUsageListData:
      properties:
        items:
          items:
            $ref: '#/components/schemas/RelatedTagUsageItem'
          type: array
          title: Items
          description: >-
            One entry per requested tag id that is actually in use, sorted by
            id.
        total:
          type: integer
          minimum: 0
          title: Total
          description: Number of returned distinct tag ids
      additionalProperties: false
      type: object
      required:
        - items
        - total
      title: RelatedTagUsageListData
      description: Complete non-zero usage result for the requested candidate tag ids.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
          description: Path to the offending field, from the body root.
        msg:
          type: string
          title: Message
          description: What is wrong with it.
        type:
          type: string
          title: Error Type
          description: Machine-readable validation-error kind.
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    RelatedTagUsageItem:
      properties:
        id:
          type: string
          maxLength: 128
          minLength: 1
          title: Id
          description: Opaque semantic tag id
        document_count:
          type: integer
          exclusiveMinimum: 0
          title: Document Count
          description: Distinct live documents using this tag
      additionalProperties: false
      type: object
      required:
        - id
        - document_count
      title: RelatedTagUsageItem
      description: >-
        One opaque tag id and its distinct live-document usage in the current
        KB.
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: 'API key issued by EverOS, sent as `Authorization: Bearer <api_key>`.'

````