# Perplexity (Sonar)

> Web-grounded answers with citations and raw web search via Perplexity Sonar.

Lets an agent ask web-grounded questions and get answers with live citations,
run long research jobs asynchronously, and run raw web searches via Perplexity Sonar.

## What it can do

| Method | What it does |
| --- | --- |
| `perplexity_chat_completion` | Ask a web-grounded question and get an answer with citations - pick a Sonar model and optional search/recency/domain filters. |
| `perplexity_create_async_chat_completion` | Submit a long-running question (e.g. deep research) to run asynchronously; returns a request_id. |
| `perplexity_get_async_chat_completion` | Get the status and result of an async chat completion by request_id. |
| `perplexity_list_async_chat_completions` | List the user's async chat completion jobs, with optional paging. |
| `perplexity_search` | Run a raw web search and get a structured list of results (title, url, snippet) with no prose answer. |
| `perplexity_embeddings` | Generate text embeddings for semantic search / RAG from one or more strings (pplx-embed-v1 models). |
| `perplexity_contextualized_embeddings` | Generate chunk-level embeddings that share document-level context for RAG over chunked documents (pplx-embed-context-v1 models). |
| `perplexity_create_agent_response` | Run an agentic workflow on Perplexity's managed runtime (retrieval, tool execution, reasoning) with web_search / fetch_url tools. |

## How to get credentials

1. Open [perplexity.ai/settings/api](https://www.perplexity.ai/settings/api).
2. Add a payment method or buy API credits (the API is pay-as-you-go).
3. Click **Generate** (or **Create Key**) to create a new API key.
4. Copy the `pplx-…` key.

## Fields to fill in FlyMyAI

| FlyMyAI field | Where it comes from |
| --- | --- |
| `PERPLEXITY_API_KEY` | Settings → API → Generate key (`pplx-…`) |

## Troubleshooting

- **`401 Unauthorized`** - the key is wrong or revoked. Generate a new one
  in the API settings.
- **`402` / credit errors** - the account is out of API credits. Top up in
  the API settings.

## Links

- [Perplexity API settings](https://www.perplexity.ai/settings/api)
- [API reference](https://docs.perplexity.ai/api-reference)
