# Dify

Dify is a platform for LLM apps and workflows. Its model providers are plugins. Install the OpenAI-API-compatible plugin, add the key and the endpoint, and Dify sends its requests to the exchange.

## Before you start

- A workspace with a balance and a `spend` key. See [API keys](https://inference.ai.exchange/docs/keys.md).
- A Dify workspace where you can install plugins.

## 1. Install the plugin

```
OpenAI-API-compatible
```

## 2. Add the key and the endpoint

Choose **Add Model** and set the type to **LLM**. Dify adds `/chat/completions` to the endpoint URL.

```
sk-liquid-...
```

```
https://router.inference.ai.exchange/v1
```

The URL ends in `/v1`.

## 3. Set the model

Enter the model by name. To get the current names, use `GET /v1/models`. See [Market data](https://inference.ai.exchange/docs/market.md).

```
liquid.auto
```

Set the context size and the features of the model. Turn on function calling for an agent that uses tools.

## Notes

- Dify sends `X-Title: Dify` with each request. The receipts name Dify as the client.
- The exchange sets a cap on each request. It is in the `x-liquid-cap-usd` response header. To limit total spend, set a spending limit on the key. See [API keys](https://inference.ai.exchange/docs/keys.md).
- A workflow can make many requests. Set a spending limit on the key for the workflow.
- Use a preset for other purchasing rules. See [Purchasing rules](https://inference.ai.exchange/docs/rules.md).

## Troubleshooting

| Symptom                                 | Cause and fix                                                                  |
| --------------------------------------- | ------------------------------------------------------------------------------ |
| `401`                                   | The key is wrong, revoked or expired. Paste it again.                          |
| `404`                                   | Keep `/v1` at the end of the endpoint URL.                                     |
| `model_not_found`                       | The model is not on the book. Use an exact name from `GET /v1/models`.         |
| A request is refused for lack of funds. | The workspace balance cannot cover the cap. Add funds on the **Credits** page. |

See [Errors](https://inference.ai.exchange/docs/errors.md) for the error codes.

## Next steps

- [Dify plugin](https://inference.ai.exchange/docs/plugin-dify.md): the Liquid Inference plugin, which needs only the key.
- [n8n](https://inference.ai.exchange/docs/connect-n8n.md): the same setup for workflow automation.
- [Purchasing rules](https://inference.ai.exchange/docs/rules.md): models, strategy and limits, and presets.
- [Errors](https://inference.ai.exchange/docs/errors.md): the error format and what each code means.
