> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stigg.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Perplexity

> Wrap Perplexity's OpenAI-compatible API to meter and gate calls with Stigg.

Perplexity's Agent API combines models with built-in web search. Its API follows OpenAI's format, so you wrap it with the `OpenAI` client and the SDK meters it with the OpenAI recipe.

## Set up

Point the `OpenAI` client's `baseURL` at Perplexity and wrap it:

```typescript theme={null}
import OpenAI from 'openai';

const perplexity = stigg.wrap(
  new OpenAI({ baseURL: 'https://api.perplexity.ai/v1', apiKey: process.env.PERPLEXITY_API_KEY }),
);

const response = await perplexity.responses.create({
  model,
  input,
  stiggContext: { customerId: 'customer-acme', entitlement: { currencyId: 'credits' } },
});
```

Perplexity's Agent API follows OpenAI's **Responses** format, so call `responses.create`. Use the base URL with `/v1`.

> [!NOTE]
>
> Perplexity ended support for Sonar Chat Completions on September 27, 2026. Use the Responses format shown above.

## What is reported

Perplexity returns a `usage` object in OpenAI's format with the number of tokens each call consumed. The calls go through the `OpenAI` client, so they are reported under OpenAI event names. The wrapper reads the counts and reports them to Stigg as the metrics below.

| Method | Event name |
| - | - |
| `responses.create` | `openai.responses.create` |

**Responses**

| Metric | What it counts |
| - | - |
| `input_tokens` | Input tokens, **including** cached tokens |
| `output_tokens` | Output tokens |
| `cached_tokens` | Input tokens served from the cache, when the vendor reports them |
| `total_tokens` | All input and output tokens, as reported by the vendor |

`total_tokens` includes the other token counts, so price the total or the parts, never both. To tell Perplexity apart from other vendors on the same event name, add a dimension such as `provider` to the `stiggContext`.

Perplexity's `usage` object also includes a breakdown of what the call cost, including search and tool costs. Those fields are included under the `raw.` prefix, so you can build a meter on them.

Every usage field the provider returns is also included, with a `raw.` prefix. See [How usage is reported](/documentation/ai-agents/usage-metering#how-usage-is-reported).

For details on Perplexity's API, see Perplexity's [OpenAI compatibility docs](https://docs.perplexity.ai/docs/agent-api/openai-compatibility).


## Related topics

- [Usage metering](/documentation/ai-agents/usage-metering.md)
- [Bring your own vendor](/documentation/ai-agents/providers/custom.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.