# Dify (https://inference.net/docs/integrations/dify)

Connect Dify Cloud or self-hosted Dify to Inference.net through Dify's **OpenAI-API-compatible** model provider using `https://api.inference.net/v1` and your `INFERENCE_API_KEY`. You can run fast open-weight models (`deepseek-v4.1-flash-1017`, `glm-5.3`, and `moonshotai/kimi-k3.1-pro`) across Dify Chatflows, Workflows, and Agents, or extract strict JSON from HTML using `inference-net/schematron-v2-small`.

## Shared connection settings

Create an account at [/register](/register/?model=deepseek-v4-1-flash-1017) and generate a project key in [API keys](/dashboard/api-keys/). Verify your key and inspect live model IDs before adding models in Dify:

| Setting | Value |
| --- | --- |
| Provider plugin | **OpenAI-API-compatible** |
| API endpoint URL | `https://api.inference.net/v1` |
| US-only endpoint URL | `https://us.api.inference.net/v1` |
| API key | `INFERENCE_API_KEY` (`inf_sk_...`) |
| Completion mode | `Chat` |

```bash
export INFERENCE_API_KEY="inf_sk_..."
curl -sS https://api.inference.net/v1/models \
  -H "Authorization: Bearer $INFERENCE_API_KEY" | jq '.data[].id'
```

## Configure Inference.net in Dify

<Steps>
  <Step title="Install the OpenAI-API-compatible provider plugin">

In Dify Cloud or self-hosted Dify v1.0+, open **Settings > Model Provider**. Locate **OpenAI-API-compatible** (install it from the Dify Marketplace if it is not enabled yet) and click **Add Model**.

  </Step>
  <Step title="Register a flagship Inference.net model">

Fill in the **Add Model** dialog with the exact values from `GET https://api.inference.net/v1/models`:

| Field | Example value (`deepseek-v4.1-flash-1017`) |
| --- | --- |
| Model Type | `LLM` |
| Model Name | `deepseek-v4.1-flash-1017` |
| Model Display Name | `DeepSeek V4.1 Flash (Inference.net)` |
| API Key | Your `INFERENCE_API_KEY` |
| API endpoint URL | `https://api.inference.net/v1` |
| Completion mode | `Chat` |
| Model context size | `1040000` |
| Upper bound for max tokens | `393216` |
| Function calling | `Tool Call` |
| Vision support | `Yes` |

Repeat **Add Model** for any additional model you want in Dify's picker, such as `glm-5.3` (`1048576` context, text only) or `moonshotai/kimi-k3.1-pro` (`1048576` context, text and image).

  </Step>
  <Step title="Assign the model in a Workflow or Chatflow">

Open any Dify **LLM** or **Agent** node, select your registered Inference.net model, and click **Run** to test a prompt. Dify streams tokens directly from `https://api.inference.net/v1/chat/completions`.

  </Step>
</Steps>

<Callout title="Do not append /chat/completions to the API endpoint URL" tone="info">

Enter `https://api.inference.net/v1` (or `https://us.api.inference.net/v1` for US-only models). Dify appends `/chat/completions` automatically; pasting the full path returns `404 Not Found`.

</Callout>

## Self-hosted Dify configuration

When running self-hosted Dify via Docker Compose, verify outbound connectivity and request timeouts for long-context or reasoning models (`glm-5.3`, `moonshotai/kimi-k3.1-pro`):

- **Outbound HTTPS:** Allow egress from the `api` and `plugin_daemon` containers to `api.inference.net:443` (and `us.api.inference.net:443` if you pin US-only routes).
- **Streaming and plugin timeouts:** In your Dify `.env` file, raise `PLUGIN_MAX_EXECUTION_TIMEOUT` and `HTTP_REQUEST_MAX_READ_TIMEOUT` (for example, to `300` seconds) when running long-context reasoning steps so Dify does not cut off active streams.
- **Data retention:** Inference.net-hosted US serverless models listed in the table below operate under default [Zero Data Retention](/docs/data-retention/). External passthrough and ad-supported model variants have different retention terms; review [Data retention](/docs/data-retention/) before sending sensitive payloads.

## JSON extraction with Schematron

For scraping and document ingestion pipelines in Dify, use [`inference-net/schematron-v2-small`](/models/inference-net-schematron-v2-small/) (highest extraction accuracy on complex schemas) or [`inference-net/schematron-v2-turbo`](/models/inference-net-schematron-v2-turbo/) (lowest cost at scale). Schematron models accept raw or pre-cleaned HTML in the user message with a strict JSON Schema in `response_format` and do not require a system prompt.

In a Dify Workflow, add an **HTTP Request** node configured as `POST https://api.inference.net/v1/chat/completions` with `Authorization: Bearer <INFERENCE_API_KEY>`, `Content-Type: application/json`, and the JSON body below:

```json
{
  "model": "inference-net/schematron-v2-small",
  "temperature": 0,
  "messages": [
    {
      "role": "user",
      "content": "{{#fetch_page.body#}}"
    }
  ],
  "response_format": {
    "type": "json_schema",
    "json_schema": {
      "name": "product_record",
      "strict": true,
      "schema": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "price": { "type": "number" },
          "currency": { "type": "string" },
          "in_stock": { "type": "boolean" }
        },
        "required": ["name", "price", "currency", "in_stock"],
        "additionalProperties": false
      }
    }
  }
}
```

Pass the HTTP Request node's JSON response into a downstream Dify **Code** or **Variable Assigner** node. See the [Schematron guide](/docs/api/models/schematron/) for HTML preprocessing tips.

## Verified models and live rates

All model IDs, limits, and per-1M-token rates below are verified against `GET https://api.inference.net/v1/models` (**2026-12-06**):

| Model ID | Context / max output | Input / cached / output (per 1M) | Tools | Modalities | Model page |
| --- | --- | --- | --- | --- | --- |
| `deepseek-v4.1-flash-1017` | 1,040,000 / 393,216 | `$0.08` / `$0.007` / `$0.635` | Yes | Text, image | [DeepSeek V4.1 Flash](/models/deepseek-v4-1-flash-1017/) |
| `glm-5.3` | 1,048,576 / 943,718 | `$0.084` / `$0.079` / `$3.00` | Yes | Text | [GLM-5.3](/models/glm-5-3/) |
| `glm-5.3-flash` | 1,048,576 / 262,144 | `$0.10` / `$0.03` / `$0.35` | Yes | Text, image, video | [GLM-5.3 Flash](/models/glm-5-3-flash/) |
| `moonshotai/kimi-k3.1-pro` | 1,048,576 / 1,048,576 | `$1.80` / `$0.198` / `$9.00` | Yes | Text, image | [Kimi K3.1 Pro](/models/kimi-k3-1-pro/) |
| `inference-net/schematron-v2-small` | 128,000 / 4,096 | `$0.05` / `$0.05` / `$0.23` | No | Text | [Schematron V2 Small](/models/inference-net-schematron-v2-small/) |
| `inference-net/schematron-v2-turbo` | 128,000 / 8,192 | `$0.03` / `$0.03` / `$0.15` | No | Text | [Schematron V2 Turbo](/models/inference-net-schematron-v2-turbo/) |

## Prompt caching tips for Dify workflows

Dify Chatflows and Knowledge Retrieval workflows frequently send a large static system prompt before dynamic user variables. Place static instructions and reference schemas first and append dynamic variables (`{{#sys.query#}}`, retrieved chunks) at the end so prefix caching triggers automatically on `deepseek-v4.1-flash-1017` and `moonshotai/kimi-k3.1-pro`. Do **not** pass `prompt_cache_key` to `deepseek-v4.1-flash-1017`. Estimate your workflow savings with the [Prompt cache calculator](/tools/prompt-cache-calculator/).

## Troubleshooting

- **`401 Unauthorized`:** Confirm your API key starts with `inf_sk_` and has no leading or trailing spaces in Dify's **Model Provider** settings.
- **`404 Not Found` or HTML error page:** Set **API endpoint URL** to `https://api.inference.net/v1`, not `https://inference.net/v1` and not `https://api.inference.net/v1/chat/completions`.
- **Model not found:** Keep exact owner prefixes from `GET https://api.inference.net/v1/models`, including `moonshotai/kimi-k3.1-pro` and `inference-net/schematron-v2-small`.
- **Agent node fails to invoke tools:** Select a model with `supports_tools: true` (`deepseek-v4.1-flash-1017`, `glm-5.3`, `glm-5.3-flash`, or `moonshotai/kimi-k3.1-pro`) and set **Function calling** to `Tool Call` in Dify's model settings. Do not assign Schematron models to tool-calling Agent nodes.
- **Timeouts on self-hosted Dify:** Increase `PLUGIN_MAX_EXECUTION_TIMEOUT` and reverse-proxy read timeouts when generating long outputs with `glm-5.3` or `moonshotai/kimi-k3.1-pro`.

Browse all supported editors, workflow builders, gateways, and SDKs in the [Integrations hub](/docs/integrations/).