Subject: Urgent: Repeated ClientResponseError 400 Bad Request on Perplexity API

Subject: Urgent: Repeated ClientResponseError 400 Bad Request on Perplexity API

Dear Perplexity AI Support Team,

I am reaching out regarding a critical issue with the Perplexity API that is affecting my application hosted @sportsomega.com. Starting around 2025-07-04T09:28:11Z, my application began encountering consistent “400 Bad Request” errors when making asynchronous requests to the /chat/completions endpoint, specifically with the models llama-3.1-sonar-large-128k-online and llama-3.1-sonar-small-128k-online.

The errors are logged as follows:

  • ClientResponseError: 400, message=‘Bad Request’, url=‘api.perplexity.ai/chat/completions’
  • Accompanied by: “Invalid AI response received: {‘error’: ‘Unexpected system error: ClientResponseError’}”
  • This has caused sentiment analysis failures for multiple game IDs (e.g., 1ab8d1ee4a6057da8977923a8b5ecb58, 1df5e69dc10e70f99b35d471d0689466, etc.) and disrupted prediction functionality.

The issue appears across multiple requests with response times ranging from 121ms to 1704ms, all returning HTTP 200 despite the internal API errors. The application uses aiohttp for async requests and expects JSON responses, with a semaphore limit of 5 concurrent requests. No recent changes were made to the codebase that would explain this sudden issue, as the system was functioning perfectly prior to this.

Could you please investigate the cause of these errors? Specifically:

  1. Is there an issue with the Perplexity API servers or the specified models?
  2. Are there any changes in the API request format or authentication requirements that could trigger a 400 Bad Request?
  3. Can you provide guidance on debugging or resolving this issue?

Attached are relevant log excerpts for your reference. I can provide additional logs or request payloads if needed. This issue is impacting our service, and a prompt response would be greatly appreciated.

Thank you for your assistance.

Best regards,
Hans Johannes Schulte
pastsmartlink@gmail.com
SportsOmega Team

Subject: Amendment to Bug Report: Additional Information for Perplexity API 400 Bad Request Issue

Dear Sam,

Following up on my previous email regarding the Perplexity API 400 Bad Request errors, I wanted to provide additional information to assist with troubleshooting. The codebase for my application is hosted at https://github.com/PastSmartLink/render, and I have added pplx-judges · GitHub as a collaborator per the hackathon requirements, granting your team direct access to the code.

Key details about the implementation:

  • The relevant code for API requests is located in ai_service.py (path: /src/ai_service.py), specifically the ask_async function.
  • The application is deployed on Render, and the errors started occurring around 2025-07-04T09:28:11Z, as noted in the logs provided earlier.
  • No changes were made to the request logic or payload structure prior to the errors, suggesting a potential issue on the API server side or an undocumented change in the API requirements.

Could your team review the code directly in the repository to identify any potential issues with the request format or handling? If needed, I can provide specific line references or additional logs. Please let me know if there’s anything else I can do to expedite the resolution, as this issue is impacting our service @sportsomega.com

Thank you for your continued support.

Best regards,
Hans Johannes Schulte
SportsOmega Team

Additional Log Excerpts

2025-07-04T10:41:05.328495643Z 2025-07-04 10:41:05,328 - shared.caching:69 - INFO - CACHE HIT for odds for sport baseball_mlb
2025-07-04T10:41:05.328936835Z 2025-07-04 10:41:05,328 - app:216 - INFO - CACHE MISS for sentiment on game 0a71aa25c5a06a81d5fface3760c6f03
2025-07-04T10:41:05.328964216Z 2025-07-04 10:41:05,328 - app:167 - INFO - Flask app.py: API Semaphore created/retrieved. Limit: 5.
2025-07-04T10:41:05.328976926Z 2025-07-04 10:41:05,328 - app:199 - INFO - App.py PPLX Call: Model: llama-3.1-sonar-small-128k-online. Sem acquired.
2025-07-04T10:41:05.32911406Z 2025-07-04 10:41:05,329 - ai_service:110 - INFO - Sending ASYNC request to Perplexity API. Model: llama-3.1-sonar-small-128k-online. Expect JSON: True. Messages: 2
2025-07-04T10:41:05.486827491Z 2025-07-04 10:41:05,486 - ai_service:178 - ERROR - Unexpected non-retryable error in ask_async for model llama-3.1-sonar-small-128k-online.
2025-07-04T10:41:05.486873882Z aiohttp.client_exceptions.ClientResponseError: 400, message='Bad Request', url='https://api.perplexity.ai/chat/completions'
2025-07-04T10:41:05.487069647Z 2025-07-04 10:41:05,486 - app:201 - WARNING - Invalid AI response received: {'error': 'Unexpected system error: ClientResponseError'}
2025-07-04T10:41:05.487089618Z 2025-07-04 10:41:05,487 - app:225 - ERROR - Sentiment error for 0a71aa25c5a06a81d5fface3760c6f03: {'error': 'Unexpected system error: ClientResponseError'}
2025-07-04T10:41:05.611393642Z 2025-07-04 10:41:05,610 - ai_service:178 - ERROR - Unexpected non-retryable error in ask_async for model llama-3.1-sonar-small-128k-online.
2025-07-04T10:41:05.611475004Z aiohttp.client_exceptions.ClientResponseError: 400, message='Bad Request', url='https://api.perplexity.ai/chat/completions'
2025-07-04T10:41:05.611719741Z 2025-07-04 10:41:05,611 - app:201 - WARNING - Invalid AI response received: {'error': 'Unexpected system error: ClientResponseError'}
2025-07-04T10:41:05.611749782Z 2025-07-04 10:41:05,611 - app:225 - ERROR - Sentiment error for 0a71aa25c5a06a81d5fface3760c6f03: {'error': 'Unexpected system error: ClientResponseError'}
2025-07-04T10:41:05.724732108Z 2025-07-04 10:41:05,724 - ai_service:178 - ERROR - Unexpected non-retryable error in ask_async for model llama-3.1-sonar-large-128k-online.
2025-07-04T10:41:05.724766759Z aiohttp.client_exceptions.ClientResponseError: 400, message='Bad Request', url='https://api.perplexity.ai/chat/completions'
2025-07-04T10:41:05.724948114Z 2025-07-04 10:41:05,724 - app:201 - WARNING - Invalid AI response received: {'error': 'Unexpected system error: ClientResponseError'}


I’ve conquered the 400 Bad Request challenge like a true PRO, and my application is now performing better than ever! This journey taught me invaluable lessons that have sharpened my need for more coffee and hours in the day! :hot_beverage: :tada: :timer_clock: :partying_face: