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

# Migrate from OpenAI

> Point OpenAI-compatible clients and libraries at SynapsAI Cloud with minimal code changes

SynapsAI Cloud exposes OpenAI-compatible endpoints for chat, completions, embeddings, images, and audio. In many cases you can migrate by changing the base URL, API key, and model ID.

## Before you begin

1. [Create an account](/quickstart) and [deploy a model](/guides/deploy-model) on SynapsAI Cloud.
2. [Create an API key](/manage/api-keys) scoped to that deployment.
3. Copy the **model ID** from the [Models](https://platform.synapsai.cloud/models) page — this replaces OpenAI model names like `gpt-4o`.

## Environment variables

Set these in your shell or deployment environment:

```bash theme={null}
export SYNAPSAI_API_KEY="your-synapsai-api-key"
export OPENAI_API_BASE="https://api.synapsai.cloud/v1"
export OPENAI_API_KEY="$SYNAPSAI_API_KEY"
```

Libraries that read `OPENAI_API_BASE` and `OPENAI_API_KEY` (LangChain, LlamaIndex, many community tools) will route requests to SynapsAI automatically.

## Python SDK

The official `synapsai` package mirrors the OpenAI Python client:

```python theme={null}
from synapsai import SynapsAI

client = SynapsAI()

response = client.chat.completions.create(
    model="your-model-id",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)
```

Install with:

```bash theme={null}
pip install --upgrade synapsa-python
```

## Endpoint mapping

| OpenAI endpoint                 | SynapsAI endpoint               | Compatible                            |
| ------------------------------- | ------------------------------- | ------------------------------------- |
| `POST /v1/chat/completions`     | `POST /v1/chat/completions`     | Yes — streaming, tools, `tool_choice` |
| `POST /v1/completions`          | `POST /v1/completions`          | Yes                                   |
| `POST /v1/embeddings`           | `POST /v1/embeddings`           | Yes                                   |
| `POST /v1/images/generations`   | `POST /v1/images/generations`   | Yes                                   |
| `POST /v1/images/edits`         | `POST /v1/images/edits`         | Yes                                   |
| `POST /v1/audio/speech`         | `POST /v1/audio/speech`         | Yes                                   |
| `POST /v1/audio/transcriptions` | `POST /v1/audio/transcriptions` | Yes                                   |
| `GET /v1/models`                | `GET /v1/models`                | Yes — lists your deployed models      |

SynapsAI also exposes additional endpoints for classification, reranking, video, and other Hugging Face pipeline tasks. See [Supported tasks](/resources/tasks).

## cURL example

```bash theme={null}
curl https://api.synapsai.cloud/v1/chat/completions \
  -H "Authorization: Bearer $SYNAPSAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "your-model-id",
    "messages": [{"role": "user", "content": "Summarize unit testing in three sentences."}],
    "max_tokens": 150
  }'
```

## Streaming

Add `"stream": true` to receive Server-Sent Events, the same as OpenAI:

```python theme={null}
stream = client.chat.completions.create(
    model="your-model-id",
    messages=[{"role": "user", "content": "Hello"}],
    stream=True,
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")
```

See [Streaming](/guides/streaming) for full details.

## Key differences from OpenAI

| Topic         | OpenAI                          | SynapsAI Cloud                                                     |
| ------------- | ------------------------------- | ------------------------------------------------------------------ |
| Model names   | Shared catalog (`gpt-4o`, etc.) | Your deployed **model ID** per deployment                          |
| Hosting       | Shared multi-tenant API         | [Multi-tenant deployment on shared GPU infrastructure](/isolation) |
| Billing       | Per-token or subscription       | Credits — memory-based compute + optional storage                  |
| Cold starts   | Managed by OpenAI               | You control via [readiness level](/core-concepts)                  |
| Custom models | Fine-tunes on OpenAI            | Any supported Hugging Face model you deploy                        |

## Framework integrations

* [LangChain](/guides/integrations-langchain)
* [LlamaIndex](/guides/integrations-llamaindex)
* [Embeddings + FAISS](/guides/integrations-embeddings-faiss)
* [Gradio / FastAPI](/guides/integrations-gradio-fastapi)

## Troubleshooting migration issues

* **`Model not found`** — Use the SynapsAI model ID, not an OpenAI model name.
* **`Endpoint not supported`** — Confirm the pipeline task matches the endpoint. See [Supported tasks](/resources/tasks).
* **`401` / `InvalidAPIKeyError`** — Verify the key is scoped to the model and passed as `Bearer` auth.
* **Library still hits `api.openai.com`** — Confirm `OPENAI_API_BASE` is set before the client initializes.

For more errors, see [Troubleshooting](/support/troubleshooting).
