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

# Migrating from OpenAI

> Point your existing code at Infery in two lines. No SDK swap.

Infery's gateway is a strict OpenAI-API superset. You keep the OpenAI SDK; you change the **base URL** and **API key**.

## The change

<CodeGroup>
  ```python python theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key=os.environ["INFERY_API_KEY"],   # was OPENAI_API_KEY
      base_url="https://api.infery.ai/v1",     # added
  )
  ```

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

  const client = new OpenAI({
    apiKey: process.env.INFERY_API_KEY,         // was OPENAI_API_KEY
    baseURL: 'https://api.infery.ai/v1',         // added
  });
  ```

  ```bash curl theme={null}
  # Before
  curl https://api.openai.com/v1/chat/completions ...

  # After
  curl https://api.infery.ai/v1/chat/completions ...
  ```
</CodeGroup>

That's it. Every existing call site keeps working.

## What stays identical

* Endpoint paths: `/v1/chat/completions`, `/v1/embeddings`, `/v1/images/generations`, `/v1/audio/*`, `/v1/files`
* Request bodies (messages, tools, response\_format, streaming)
* Response shapes (`id`, `choices`, `usage`, `system_fingerprint`)
* SSE streaming format including the final `data: [DONE]`
* Tool calling, JSON mode, structured outputs, vision, PDF
* Idempotency keys
* Error envelope (`{ "error": { "type", "code", "message" } }`)

## What's added

| Feature               | How                                                                                          |
| --------------------- | -------------------------------------------------------------------------------------------- |
| Cost per request      | Header `x-credits-used`, plus a `credits_used` SSE chunk before `[DONE]`                     |
| Multi-provider models | Use any model slug from `GET /v1/models` — Anthropic, Google, xAI, OSS — with the OpenAI SDK |
| Fallback routing      | Configure in dashboard, headers `x-model-used` / `x-fallback-from` tell you what served      |
| Usage analytics       | Per-key, per-model, per-member breakdowns                                                    |

## What changes

**Model slugs.** OpenAI models keep their names (`gpt-4o`, `gpt-4o-mini`, `text-embedding-3-large`). For Anthropic/Google/xAI, use the slug from `GET /v1/models` — for example `claude-sonnet-4-5`, `gemini-2-5-flash`, `grok-4`.

**Auth.** Use an Infery API key (`inf_...`) — your OpenAI key is not valid here. Create one in Settings → API Keys.

**Rate limits.** Per-workspace, not per-OpenAI-org. See [Rate limits](/api-reference/rate-limits).

**Billing.** Single Infery invoice covers every provider. Your OpenAI billing relationship ends.

## Checklist

* [ ] Create an Infery API key
* [ ] Replace `OPENAI_API_KEY` with `INFERY_API_KEY` in env config
* [ ] Set `base_url` / `baseURL` to `https://api.infery.ai/v1`
* [ ] Run your test suite — nothing else should change
* [ ] (Optional) Set up a [fallback chain](/workspaces/fallback-chains) for production resilience
* [ ] (Optional) Add `x-credits-used` to your request logging

## Things to watch

* **Org-level OpenAI features** (project keys, fine-tunes, batch API) aren't 1:1 yet — `batch` is on the [roadmap](/reference/changelog).
* **System fingerprints** are passed through from upstream when present, so determinism guarantees match the underlying provider.
* If your code parses error messages by string, switch to `error.code` — it's stable; messages are not.
