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

# API

> API reference for PerplexityAi: every `perplexityai.api.*` operation with input and output types.

Every `perplexityai.api.*` operation is listed below with parameter shapes and return types from the plugin Zod schemas.

<Info>
  **New to Corsair?** See [API access](/concepts/api), [authentication](/concepts/auth), and [error handling](/concepts/error-handling).
</Info>

## Chat

### completions

`chat.completions`

Create a chat completion

**Risk:** `read`

```ts theme={null}
await corsair.perplexityai.api.chat.completions({});
```

**Input**

| Name                | Type       | Required | Description |
| ------------------- | ---------- | -------- | ----------- |
| `model`             | `string`   | Yes      | —           |
| `messages`          | `object[]` | Yes      | —           |
| `max_tokens`        | `number`   | No       | —           |
| `temperature`       | `number`   | No       | —           |
| `top_p`             | `number`   | No       | —           |
| `top_k`             | `number`   | No       | —           |
| `return_citations`  | `boolean`  | No       | —           |
| `return_images`     | `boolean`  | No       | —           |
| `stream`            | `boolean`  | No       | —           |
| `presence_penalty`  | `number`   | No       | —           |
| `frequency_penalty` | `number`   | No       | —           |

<AccordionGroup>
  <Accordion title="messages full type">
    ```ts theme={null}
    {
      role: system | user | assistant,
      content: string
    }[]
    ```
  </Accordion>
</AccordionGroup>

**Output**

| Name        | Type       | Required | Description |
| ----------- | ---------- | -------- | ----------- |
| `id`        | `string`   | Yes      | —           |
| `model`     | `string`   | Yes      | —           |
| `object`    | `string`   | No       | —           |
| `created`   | `number`   | No       | —           |
| `choices`   | `object[]` | Yes      | —           |
| `usage`     | `object`   | No       | —           |
| `citations` | `string[]` | No       | —           |
| `images`    | `string[]` | No       | —           |

<AccordionGroup>
  <Accordion title="choices full type">
    ```ts theme={null}
    {
      index: number,
      finish_reason?: string | null,
      message?: {
        role: string,
        content: string
      },
      delta?: {
        role?: string,
        content?: string
      }
    }[]
    ```
  </Accordion>

  <Accordion title="usage full type">
    ```ts theme={null}
    {
      prompt_tokens: number,
      completion_tokens: number,
      total_tokens: number
    }
    ```
  </Accordion>
</AccordionGroup>

***
