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

# XTRIM

> Trims the stream by removing entries to keep it at a reasonable size.

## Arguments

<ParamField body="key" type="str" required>
  The key of the stream.
</ParamField>

<ParamField body="maxlen" type="int">
  The maximum number of entries to keep in the stream. Mutually exclusive with `minid`.
</ParamField>

<ParamField body="approximate" type="bool" default="True">
  Use approximate trimming (more efficient). When `True`, Redis may keep slightly more entries than specified. Defaults to `True`.
</ParamField>

<ParamField body="minid" type="str">
  The minimum ID to keep. Entries with IDs lower than this will be removed. Mutually exclusive with `maxlen`.
</ParamField>

<ParamField body="limit" type="int">
  Limit how many entries will be trimmed at most.
</ParamField>

## Response

<ResponseField type="int">
  The number of entries removed from the stream.
</ResponseField>

<RequestExample>
  ```py Approximate trim (default) theme={"system"}
  result = redis.xtrim("mystream", maxlen=50)
  ```

  ```py Approximate trim (explicit) theme={"system"}
  result = redis.xtrim("mystream", maxlen=50, approximate=True)
  ```

  ```py Exact trim theme={"system"}
  result = redis.xtrim("mystream", maxlen=20, approximate=False)
  ```

  ```py Trim by minimum ID theme={"system"}
  result = redis.xtrim("mystream", minid="1638360173533-0")
  ```

  ```py Approximate trim with limit theme={"system"}
  result = redis.xtrim("mystream", maxlen=1000, approximate=True, limit=100)
  ```
</RequestExample>
