# For some reason getting "400" bad request

**URL:** <https://community.perplexity.ai/t/for-some-reason-getting-400-bad-request/1175>\
**Category:** Bug Reports\
**Created:** [August 23, 2025, 5:51pm UTC](https://community.perplexity.ai/t/for-some-reason-getting-400-bad-request/1175 "2025-08-23T17:51:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Piotr\_Krol](https://sea1.discourse-cdn.com/flex001/user_avatar/community.perplexity.ai/piotr_krol/32/785_2.png) [@Piotr\_Krol](https://community.perplexity.ai/u/Piotr_Krol)\
**Post date:** [August 23, 2025, 5:51pm UTC](https://community.perplexity.ai/t/for-some-reason-getting-400-bad-request/1175/1 "2025-08-23T17:51:08Z")

</div>

## Hi folks,

Might be stupid and silly question.. but that’s my first time playing with API..

 ![image](https://us1.discourse-cdn.com/flex001/uploads/sonar1/original/1X/1bd6ddebf3e077c10bc825b29c79c6277fb4f39f.png)

I am trying to connect to API and I am getting..

“URL Called:

```auto
https://api.perplexity.ai/chat/completions

```

Full Response:

```auto
{
  "status": 400,
  "reason": "Bad Request"
}

```

What I am doing wrong?

I’ve copied the API key directly from the settings, so have no clue why it is not getting response back.

---

<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:** [April 7, 2026, 2:41pm UTC](https://community.perplexity.ai/t/for-some-reason-getting-400-bad-request/1175/2 "2026-04-07T14:41:43Z")

</div>

Hey @Piotr_Krol — welcome to the API! A 400 Bad Request usually means there is a formatting issue with your request payload.

The most common causes:

1. **Wrong endpoint or base URL** — For Sonar models, use `https://api.perplexity.ai/v1/sonar`

2. **Missing or malformed `messages` array** — The payload needs to look like:

```json
{
  "model": "sonar-pro",
  "messages": [
    {"role": "user", "content": "Your question here"}
  ]
}

```

1. **Invalid model name** — Use `sonar`, `sonar-pro`, or `sonar-reasoning-pro`. Old model names like `llama-3.1-sonar-small-128k-online` are deprecated.

2. **Auth header format** — Should be `Authorization: Bearer pplx-xxxxx` (not `Api-Key` or other formats)

Here is a minimal working curl you can test with:

```bash
curl https://api.perplexity.ai/v1/sonar \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "sonar", "messages": [{"role": "user", "content": "Hello"}]}'

```

If you are still hitting issues, share your request code (with the API key redacted) and I can spot the problem. Docs: [Sonar Quickstart](https://docs.perplexity.ai/docs/sonar/quickstart)
