[Python] Perplexity User Location filter dont work

Discussão em 'Python' iniciado por Stack, Junho 7, 2025.

  1. Stack

    Stack Membro Participativo

    I have a simple question for people used to Perplexity, this is what appears in the perplexity documentation: https://docs.perplexity.ai/guides/user-location-filter-guide#examples

    import requests

    url = "https://api.perplexity.ai/chat/completions"
    headers = {"Authorization": "Bearer YOUR_API_KEY"}
    payload = {
    "model": "sonar-pro",
    "messages": [
    {"role": "system", "content": "You are a helpful local guide."},
    {"role": "user", "content": "What are some good coffee shops nearby?"}
    ],
    "web_search_options": {
    "user_location": {
    "latitude": 37.7749,
    "longitude": -122.4194
    }
    }
    }

    response = requests.post(url, headers=headers, json=payload)
    print(response.json())


    but if a run that code this error appears:

    {'error': {'message': "Validation error: For localization, latitude and longitude must be provided together alongside the 'country' parameter.", 'type': 'lat_long_without_country', 'code': 400}}

    so.. what should I do? is this a bug?

    Continue reading...

Compartilhe esta Página