---
title: Getting started
description: From zero to your first AI API call.
url: https://developers.wpengine.com/docs/ai/api/getting-started/
image: https://developers.wpengine.com/og/docs/ai/api/getting-started.png
---

# Getting started

This guide walks you from browsing the catalog to a working chat completion.

## 1. List available models

The catalog is public — no API key is required. Use it to discover model identifiers you will pass as the `model` field later.

Terminal window

```sh
curl https://api.ai.wpengine.com/v1/models
```

Truncated response:

```json
{
  "object": "list",
  "data": [
    {
      "id": "google/gemini-3.5-flash",
      "object": "model",
      "owned_by": "google",
      "provider": "google",
      "display_name": "Gemini 3.5 Flash",
      "context_window": 1048576,
      "pricing": {
        "input_per_million": "1.5",
        "output_per_million": "9",
        "pricing_version": "2026-05-01",
        "unit": "credits"
      }
    }
  ]
}
```

Pick a model `id` from the response — you will pass it as the `model` field when you make a chat completion.

## 2. Create an API key

[Create a key](https://developers.wpengine.com/docs/ai/api/authentication/#creating-a-key) and copy the secret somewhere safe — it is shown **once**.

For this guide, an **Account** key with **Full access** is the quickest option; any key with **Chat** set to **Write** will do. Put it in an environment variable so the commands below can use it without pasting the secret:

Terminal window

```sh
export AI_API_KEY="wpe_xxx"
```

## 3. Make a chat completion

Terminal window

```sh
curl https://api.ai.wpengine.com/v1/chat/completions \
  -H "Authorization: Bearer $AI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "google/gemini-3.5-flash",
    "messages": [
      {"role": "system", "content": "You are concise."},
      {"role": "user", "content": "What is the speed of light in km/s?"}
    ]
  }'
```

Truncated response:

```json
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1716240000,
  "model": "google/gemini-3.5-flash",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Approximately 299,792 km/s."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 15,
    "completion_tokens": 9,
    "completion_tokens_details": {
      "reasoning_tokens": 120
    },
    "total_tokens": 144
  }
}
```

On reasoning models, `total_tokens` also includes the tokens the model spent reasoning before it answered, reported separately in `completion_tokens_details.reasoning_tokens`, so it can be larger than `prompt_tokens` plus `completion_tokens`.

## Streaming

Set `"stream": true` in the request body to receive a stream of Server-Sent Events. Each event is a JSON chunk shaped like `chat.completion.chunk`; the stream terminates with `data: [DONE]`.

See [streaming a chat completion](https://developers.wpengine.com/docs/ai/api/stream-chat-completions/) for a complete walkthrough.

---

> #### Now that you have made a call
>
> - [Authentication — key scopes, rotation, and revocation](https://developers.wpengine.com/docs/ai/api/authentication/)
> - [Errors — handle 400, 401, 403, 429, and 502 responses](https://developers.wpengine.com/docs/ai/api/errors/)
> - [API reference — every operation, with generated curl, PHP, Go, and JavaScript examples](https://developers.wpengine.com/docs/ai/api/reference/)

## Was this helpful?

Thanks for the feedback!

```json
{"@context":"https://schema.org","@graph":[{"@type":"WebSite","@id":"https://developers.wpengine.com/#website","name":"WP Engine Product Documentation","url":"https://developers.wpengine.com/","description":"Resources for developing, deploying, and scaling on WP Engine.","inLanguage":"en-US","keywords":["API documentation","product documentation","headless WordPress","managed WordPress hosting"],"publisher":{"@id":"https://wpengine.com/#organization"}}]}
```
