# Chat Completions API

Fetch a valid model identifier, construct the messages payload, send `POST /v1/chat/completions`, parse the response and usage, and handle streaming only as documented.

## Where this lives

Use a trusted local or server-side API client.

The Foxora API provides OpenAI-compatible chat completions plus account, usage, and public model-discovery endpoints. Authenticated routes currently accept a signed-in Foxora account access token.

> **Safety:** Treat the complete account access token as a secret. Do not paste it into prompts, commit it to a repository, expose it in client-side bundles, or include it in logs, screenshots, and support messages.

## Steps

1. Use a trusted local or server-side API client.
2. Fetch a valid model identifier.
3. Construct the messages payload.
4. Send `POST /v1/chat/completions`, parse the response and usage, and handle streaming only as documented.
5. **Confirm the result.** Inspect HTTP status, response headers, request identifiers, usage fields, and the parsed response; cross-check account or usage endpoints after a small request.

## Choose the right path

- Use `/v1/chat/completions` for OpenAI-compatible generation.
- Use `/v1/me` and `/v1/me/usage` for account and usage state.
- Use `/v1/models` to discover model identifiers instead of hardcoding assumptions.

## Minimal request

Get a currently available model identifier from `/v1/models`, then send an OpenAI-compatible request:

```bash
curl https://api.foxora.ai/v1/chat/completions \
  -H "Authorization: Bearer $FOXORA_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "<model-id-from-v1-models>",
    "messages": [
      { "role": "user", "content": "Summarize this in three bullets." }
    ]
  }'
```

Read the returned choice and usage data, and preserve the request identifier when reporting an API failure.


## Confirm it worked

- Inspect HTTP status, response headers, request identifiers, usage fields, and the parsed response; cross-check account or usage endpoints after a small request.
- The screen, command, file, run, or destination named in this guide reflects the expected state.
