khoj-ai/khoj · warning · HTTPException

Those images are way too large for me! I can handle up to {s

Error message

Those images are way too large for me! I can handle up to {self.max_combined_size_mb}MB of images per message.

What it means

A 429 raised when the total decoded size of all base64 images in one chat message exceeds `max_combined_size_mb` MB. Each image is base64-decoded server-side and the summed byte sizes compared against the cap.

Source

Thrown at src/khoj/routers/helpers.py:2249

            )

        # Check total size of images
        total_size_mb = 0.0
        for image in body.images:
            # Unquote the image in case it's URL encoded
            image = unquote(image)
            # Assuming the image is a base64 encoded string
            # Remove the data:image/jpeg;base64, part if present
            if "," in image:
                image = image.split(",", 1)[1]

            # Decode base64 to get the actual size
            image_bytes = base64.b64decode(image)
            total_size_mb += len(image_bytes) / (1024 * 1024)  # Convert bytes to MB

        if total_size_mb > self.max_combined_size_mb:
            logger.info(f"Data limit: {total_size_mb}MB/{self.max_combined_size_mb}MB size not allowed per message.")
            raise HTTPException(
                status_code=429,
                detail=f"Those images are way too large for me! I can handle up to {self.max_combined_size_mb}MB of images per message.",
            )

    def check_websocket(self, websocket: WebSocket, body: ChatRequestBody):
        """WebSocket-specific image rate limiting method"""
        if state.billing_enabled is False:
            return

        # Rate limiting is disabled if user unauthenticated.
        if not websocket.scope.get("user") or not websocket.scope["user"].is_authenticated:
            return

        if not body.images:
            return

        # Check number of images
        if len(body.images) > self.max_images:

View on GitHub (pinned to ae229ca894)

Solutions

  1. Compress/resize images client-side (e.g. re-encode as JPEG at reduced quality/dimensions) before sending
  2. Send large images across multiple messages under the per-message cap
  3. Check the deployment's max_combined_size_mb configuration
  4. Remove duplicate or unnecessary images from the payload

Example fix

// before
const images = await Promise.all(files.map(f => fileToBase64(f)))
// after
const images = await Promise.all(files.map(f => compressToUnder(f, 1_000_000)))  // ~1MB each
Defensive patterns

Strategy: validation

Validate before calling

import base64
MAX_MB = 10
total = sum(len(base64.b64decode(img or '')) for img in body.images) / (1024*1024)
if total > MAX_MB:
    images = compress_until_under(body.images, MAX_MB)

Type guard

def under_size_cap(images: list[str] | None, cap_mb: float) -> bool:
    if not images:
        return True
    total = sum(len(base64.b64decode(i)) for i in images)
    return total <= cap_mb * 1024 * 1024

Try / catch

try:
    resp = await client.post('/api/chat', json=body)
except HTTPStatusError as e:
    if e.response.status_code == 429 and 'too large' in e.response.text:
        body['images'] = await recompress(body['images'])
        resp = await client.post('/api/chat', json=body)
    else:
        raise

Prevention

When it happens

Trigger: Sending a message whose images, after base64 decoding, sum to more than `self.max_combined_size_mb` megabytes (e.g. several high-res phone photos in one request).

Common situations: Modern phone photos (3-8MB each) easily exceeding a small combined cap; clients sending originals without compression; forgetting that base64 inflates payloads ~33% and that the limit applies to decoded bytes.

Related errors


AI-assisted analysis of khoj-ai/khoj@ae229ca894 (2026-08-27). Data as JSON: /api/errors/b97060719f7b8623. Report an issue: GitHub.