Skip to content

Perplexity API Internal Server Error (500) on sonar-deep-research with Large File Upload (~518k Tokens), Works Fine on sonar-pro #22

@mkrzywda

Description

@mkrzywda

When I use sonar-pro:

import os
import base64
from perplexity import Perplexity

client = Perplexity(api_key=os.getenv("PERPLEXITY_API_KEY"))
file_path = "data.csv"

# Read and encode file as base64
with open(file_path, "rb") as f:
    file_bytes = f.read()
file_b64 = base64.b64encode(file_bytes).decode("utf-8")

response = client.chat.completions.create(
    model="sonar-pro",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "Analyze this document and extract key insights."},
                {
                    "type": "file_url",
                    "file_url": {"url": file_b64},
                    "file_name": os.path.basename(file_path),  # Optional but recommended
                },
            ],
        }
    ],
)

print(response.choices[0].message.content)

all works correctly, but when I change to sonar-deep-research I recieve:

perplexity.InternalServerError: Error code: 500 - {'error': {'message': 'An internal server error has occurred.', 'type': 'internal_server_error', 'code': 500}}

my file size using tiktoken:

File size      : 1,386,973 characters
Token count    : 517,913 tokens
               ≈ 517.9k tokens

Why it's happen?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions