> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.singularityapi.dev/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.singularityapi.dev/_mcp/server.

# OpenAI Compatibility

## The contract

`/v1/chat/completions`, `/v1/responses`, `/v1/images/generations`, and `/v1/images/edits` speak the same request and response wire format as the OpenAI API. If your code already uses the official `openai` SDK, it keeps working — change the `base_url` and the API key, nothing else.

**`Python`**

```python title="Python"
client = OpenAI(
    base_url="https://api.singularityapi.dev/v1",
    api_key="YOUR_API_KEY",
)
```

**`JavaScript`**

```javascript title="JavaScript"
const client = new OpenAI({
  baseURL: "https://api.singularityapi.dev/v1",
  apiKey: "YOUR_API_KEY",
});
```

## What differs from OpenAI

* **Unsupported parameters fail loudly.** Unknown or reserved fields are rejected with a 400 `invalid_request` error, never silently dropped. What you send is exactly what runs.
* **`max_tokens` and `max_completion_tokens` are interchangeable on chat completions.** Every chat model accepts either spelling; the gateway normalizes to the model's canonical field and records the rewrite in the receipt's `transformed_fields`. Sending both in one request is a 400. The responses surface accepts only `max_output_tokens`. Omit the field and the per-model default applies — see the table on [Models & Pricing](/get-started/models-pricing).
* **`model` must be a catalog slug or `contract/{slug}`.** See [Contracts](/platform/contracts) for how contract slugs resolve to a served model.
* **Duplicate JSON keys and `NaN`/`Infinity` literals are rejected** with a 400.
* **Context overflow is rejected before any tokens are spent.** If your estimated input plus the requested output limit exceeds the model's context window, the request fails with a 400.
* **Three extra response headers** appear on every response: `x-singularity-request-id`, `x-singularity-receipt-id`, and — on contract calls — `x-singularity-contract-revision`.

> **Note**
>
> Everything else in the OpenAI request schema passes through unmodified to the model.