# Getting continuously internal server error 500 while calling the sonar api

**URL:** <https://community.perplexity.ai/t/getting-continuously-internal-server-error-500-while-calling-the-sonar-api/2025>\
**Category:** General\
**Tags:** sonar-api\
**Created:** [October 13, 2025, 8:28am UTC](https://community.perplexity.ai/t/getting-continuously-internal-server-error-500-while-calling-the-sonar-api/2025 "2025-10-13T08:28:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prakhyat\_Bhartiya](https://sea1.discourse-cdn.com/flex001/user_avatar/community.perplexity.ai/prakhyat_bhartiya/32/895_2.png) [@Prakhyat\_Bhartiya](https://community.perplexity.ai/u/Prakhyat_Bhartiya)\
**Post date:** [October 13, 2025, 8:28am UTC](https://community.perplexity.ai/t/getting-continuously-internal-server-error-500-while-calling-the-sonar-api/2025/1 "2025-10-13T08:28:56Z")

</div>

Steps to Reproduce

class AnswerFormat(BaseModel):  
title: str  
url: str  
date: str  
summary: str

class AnswerList(BaseModel):  
search\_query: str  
results: List[AnswerFormat]

dt = datetime.now()  
if user\_prompt and system\_prompt:  
system\_prompt = system\_prompt  
user\_query = user\_prompt  
else:  
system\_prompt = SYSTEM\_PROMPT\_FOR\_WEB\_AGENT  
user\_query = f"user\_query: {question}\n" + “client\_categories:\n” + “\n”.join(  
f"{k}: {v}" for k, v in bucket\_company\_map.items()  
)

try :

```
headers = {
    "Authorization": f'Bearer {PERPLEXITY_CONF\["PERPLEXITY_API_KEY"\]}',
    "Content-Type": "application/json"
}

payload = {
    "search_mode": "web",
    "reasoning_effort": "medium",
    "temperature": 0,
    "top_p": 0.95,
    "return_images": False,
    "return_related_questions": False,
    "top_k": 0,
    "stream": False,
    "presence_penalty": 0,
    "frequency_penalty": 0,
    "web_search_options": {
        "search_context_size": "high"
    },
    "model": PERPLEXITY_CONF\["PERPLEXITY_MODEL"\],
    "messages": \[
        {
            "content": system_prompt,
            "role": "system"
        },
        {
            "content": user_query,
            "role": "user"
        }
    \],
    "response_format": {
        "type": "json_schema",
        "json_schema": {
            "schema": AnswerList.model_json_schema()
        }
    }
}

response = requests.post(PERPLEXITY_CONF\["PERPLEXITY_API_URL"\], headers=headers, json=payload).json()

```

Some of the times I am getting correct results but mostly i am getting server error as 500

---

<div class="post-metadata">

**Author:** ![Kesku](https://sea1.discourse-cdn.com/flex001/user_avatar/community.perplexity.ai/kesku/32/898_2.png) [@Kesku](https://community.perplexity.ai/u/Kesku)\
**Post date:** [October 22, 2025, 2:13am UTC](https://community.perplexity.ai/t/getting-continuously-internal-server-error-500-while-calling-the-sonar-api/2025/2 "2025-10-22T02:13:32Z")

</div>

Hey @Prakhyat_Bhartiya — I’ve just tested this on my end using your same payload structure, and the API is responding correctly. Are you still experiencing this?

---

<div class="post-metadata">

**Author:** ![Prakhyat\_Bhartiya](https://sea1.discourse-cdn.com/flex001/user_avatar/community.perplexity.ai/prakhyat_bhartiya/32/895_2.png) [@Prakhyat\_Bhartiya](https://community.perplexity.ai/u/Prakhyat_Bhartiya)\
**Post date:** [November 6, 2025, 10:54am UTC](https://community.perplexity.ai/t/getting-continuously-internal-server-error-500-while-calling-the-sonar-api/2025/3 "2025-11-06T10:54:37Z")

</div>

No it was resolved the day after I commented here.
