# Move an OpenAI-compatible chat integration to MandAPI

Change the chat connection boundary while preserving the application's existing messages, response handling and interface.

## Choose the boundary to change

Start with an application that already sends OpenAI-compatible Chat Completions. Keep its UI, message storage, tool execution, timeouts and streaming protocol. The basic connection settings are the endpoint, API key and model ID. A provider change does not automatically make every provider-specific feature compatible.

This recipe covers chat requests. Handle embeddings, images, audio, assistants and Responses API calls separately when you have verified their endpoint, model and request shape.

## Record the current behavior

Before editing, identify the package manager, client initialization, environment variables and model selection. Find all callers, including background summaries and classification jobs. Record whether each call streams, uses tools or expects structured JSON. Keep one example input and expected response behavior without personal data or secrets.

Create a separate MandAPI key in your [dashboard](https://app.mandapi.com/console). Select a real model ID from the [catalog](https://mandapi.com/en/pricing) and your account's available model list. Do not carry over another platform's model alias.

## Make the smallest connection change

A Python connection can look like this:

```python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["MANDAPI_API_KEY"],
    base_url="https://api.mandapi.com/v1",
)
model_id = os.environ["MANDAPI_MODEL_ID"]
```

Pass `model_id` to the existing Chat Completions call. Update your secret settings and configuration example, but keep real keys out of the repository. In another framework, use its documented custom OpenAI-compatible provider option rather than replacing the entire application.

## Verify before switching traffic

Run existing local checks first. Compare a complete response and a streamed response with the original UI contract. Test any tool and JSON path actually used by the application. If a model does not support a feature, leave that integration on its existing route until you choose a suitable replacement.

When you authorize a small live check, confirm content and usage in your account. Keep the previous provider configuration available for rollback. Do not copy balances or assume the two providers use the same billing fields.

## Copy instructions for your coding assistant

Use the accompanying prompt at your project's root. It asks the assistant to inspect before editing and to identify unsupported paths explicitly. A successful result is a narrow chat migration with checks and setup instructions, not a rewrite of unrelated features.

## References

- [https://mandapi.com/en/docs/quickstart](https://mandapi.com/en/docs/quickstart)
- [https://mandapi.com/es/docs/quickstart](https://mandapi.com/es/docs/quickstart)
- [https://github.com/openai/openai-python](https://github.com/openai/openai-python)
