# Dify

> Register MirAPI as an OpenAI-API-compatible model provider in Dify, add chat, embedding, and rerank models, and use them in your apps.

Dify is an LLM app platform that calls any OpenAI-compatible API as a model provider. Register MirAPI once, then add the models your apps need — Dify does not auto-discover them, so you add each model by its exact catalogue name.

## What you need

| Element | Value |
|---|---|
| Base URL | `https://api.mirapi.ai/v1` |
| API key | A MirAPI key (`sk-...`) created in the console |
| Model | `deepseek-chat` (added per model) |

## Register MirAPI as a provider

1. In Dify, open **Settings → Model Provider**.
2. Click **Add model provider** and choose **OpenAI-API-compatible**.
3. Fill in the provider:

```text
Provider name: MirAPI
Base URL: https://api.mirapi.ai/v1
API key: sk-...
```

Dify appends `/chat/completions` itself, so leave the base URL as `https://api.mirapi.ai/v1` — do not add the endpoint path. Dify sends the key in the `Authorization: Bearer` header, which is what MirAPI's OpenAI-compatible endpoints expect.

## Add models

Dify does not list MirAPI models automatically. Add each model under the provider, using the exact `id` from the catalogue (`GET /v1/models`):

```text
Model name: deepseek-chat
Model type: LLM
```

- Use the `id` exactly as returned by `GET /v1/models`. Skip the `vendor/` prefix — it only exists for browsing the console catalogue and is not part of the API model name.
- Take the context size from the model's `context_length` on the [models page](/docs/models).

MirAPI endpoints map to Dify model types as follows:

| Dify model type | MirAPI endpoint | Typical use |
|---|---|---|
| LLM | `/v1/chat/completions` | Chat and completion apps |
| Text Embedding | `/v1/embeddings` | Knowledge-base retrieval (RAG) |
| Rerank | `/v1/rerank` | Re-scoring retrieval candidates |

Save and test each model from the provider list before wiring it into an app.

## Verify with a message

1. Create or open an app that uses the MirAPI model.
2. Open the debug panel and send:

```text
Reply with exactly: connected to MirAPI
```

3. The output should contain `connected to MirAPI`.

:::note
Streaming works out of the box: MirAPI returns standard SSE (`data:` lines ending with `data: [DONE]`), and Dify renders the response as it arrives.
:::

## Errors and billing

- **401** — Dify is sending a missing or invalid key; check the provider's API key field.
- **403** with a valid key — the model is not on your key's allowlist, the balance is exhausted, or the key hit a quota or IP limit. Top up to restore an empty balance immediately.
- **429** — you hit a rate limit; retry with exponential backoff. The gateway does not retry for you and sends no `Retry-After` header.
- Billing is per token for chat, per image, or per second of video. Usage and spend are in the console billing log and the `/api/log/token` detail endpoint — see [Billing & top-ups](/docs/billing).

## Related links

- [Quickstart](/docs/quickstart)
- [OpenAI compatibility](/docs/openai-compat)
- [Embeddings & rerank](/docs/guides/embeddings-rerank)
- [Models & pricing](/docs/models)