---
title: "Deploy Dify2Openai"
description: "Convert Dify API into an OpenAI API,streaming,blocking,chat,agent & more"
category: "AI/ML"
url: https://railway.com/deploy/dify2openai
---

# Deploy Dify2Openai

Convert Dify API into an OpenAI API,streaming,blocking,chat,agent & more

**[Deploy Dify2Openai on Railway](https://railway.com/template/dify2openai)**

- **Creator:** Muhammad Bilal
- **Category:** AI/ML

## Template content

### Dify2Openai

- **Image:** fatwang2/dify2openai:latest
- **Public domain:** Yes

## Documentation

# Deploy and Host D2O (Dify2OpenAI) on Railway

D2O (Dify2OpenAI) is an open-source gateway that converts Dify applications into OpenAI-compatible APIs. It allows any OpenAI-compatible client, SDK, or application to seamlessly interact with Dify Chat, Completion, Agent, and Workflow applications without requiring code changes.

## About Hosting D2O (Dify2OpenAI)

Railway makes deploying D2O simple by automatically building the application from the included Dockerfile or deploying the official Docker image. Once deployed, D2O exposes an OpenAI-compatible API endpoint that forwards requests to your Dify application. Railway handles HTTPS, networking, deployments, and environment variables automatically, allowing you to focus on integrating AI applications. Since D2O is a stateless API gateway, no database or persistent storage is required, making deployments lightweight, scalable, and easy to maintain.

## Common Use Cases

- Connect existing OpenAI clients directly to Dify.
- Expose Dify Chat, Completion, Agent, and Workflow applications through the OpenAI API.
- Integrate Dify into AI tools, SDKs, and automation platforms that support OpenAI APIs.

## Dependencies for D2O (Dify2OpenAI) Hosting

| Dependency | Required | Purpose |
|------------|----------|---------|
| Dify API | Yes | Backend service that processes AI requests. |

### Deployment Dependencies

| Resource | Link |
|----------|------|
| GitHub Repository | https://github.com/fatwang2/dify2openai |
| Docker Image | https://hub.docker.com/r/fatwang2/dify2openai |
| Dify Documentation | https://docs.dify.ai |

### Implementation Details

## Docker

Railway automatically builds the application from the included Dockerfile.

Alternatively, you can deploy the official Docker image:

```text
fatwang2/dify2openai:latest
```

## Public Networking

| Setting | Value |
|---------|-------|
| Proxy Type | HTTP Proxy |
| Target Port | 3000 |

## Environment Variables

Configure the following Railway Variables before deployment.

| Variable | Required | Description |
|----------|----------|-------------|
| `DIFY_API_URL` | Yes | Base URL of your Dify API. |
| `API_KEY` | No | Dify Application API Key. Can also be supplied per request. |
| `BOT_TYPE` | Yes | Application type: `Chat`, `Completion`, `Agent`, or `Workflow`. |
| `INPUT_VARIABLE` | No | Workflow input variable name. |
| `OUTPUT_VARIABLE` | No | Workflow output variable name. |
| `MODELS_NAME` | No | Model name returned by the `/v1/models` endpoint. Defaults to `dify`. |

Raw Editor example:

```env
DIFY_API_URL=https://api.dify.ai/v1
API_KEY=
BOT_TYPE=Chat
INPUT_VARIABLE=
OUTPUT_VARIABLE=
MODELS_NAME=
```

## Persistent Storage

No Railway Volume is required.

D2O is a stateless API gateway and does not store application data.

## Database

No database is required.

## Build &amp; Start

Railway automatically builds the application from the included Dockerfile.

No custom build or start commands are required.

## Accessing the Application

After deployment:

1. Open your Railway service.
2. Go to **Settings → Networking**.
3. Generate a Railway Domain.
4. Your OpenAI-compatible endpoint will be available at:

```text
https:///v1
```

## Using the API

D2O supports three methods for passing your Dify configuration.

### Method 1 — All Configuration in the Authorization Header

Authorization header:

```text
Authorization: Bearer DIFY_API_URL|API_KEY|BOT_TYPE
```

Example:

```text
Authorization: Bearer https://cloud.dify.ai/v1|app-xxxx|Chat
```

Use the default model:

```json
{
  "model": "dify"
}
```

Example request:

```bash
curl https:///v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer https://cloud.dify.ai/v1|app-xxxx|Chat" \
  -X POST \
  -d '{
    "model":"dify",
    "stream":true,
    "messages":[
      {
        "role":"system",
        "content":"You are a helpful assistant."
      },
      {
        "role":"user",
        "content":"Hello"
      }
    ]
  }'
```

---

### Method 2 — API Key in Authorization Header

Authorization header:

```text
Authorization: Bearer app-xxxx
```

Configure the remaining values in the model parameter:

```text
dify|BOT_TYPE|DIFY_API_URL|INPUT_VARIABLE|OUTPUT_VARIABLE
```

Chat example:

```json
{
  "model": "dify|Chat|https://cloud.dify.ai/v1"
}
```

Workflow example:

```json
{
  "model": "dify|Workflow|https://cloud.dify.ai/v1|input|output"
}
```

Example request:

```bash
curl https:///v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer app-xxxx" \
  -X POST \
  -d '{
    "model":"dify|Chat|https://cloud.dify.ai/v1",
    "stream":true,
    "messages":[
      {
        "role":"system",
        "content":"You are a helpful assistant."
      },
      {
        "role":"user",
        "content":"Hello"
      }
    ]
  }'
```

---

### Method 3 — Dify URL in Authorization Header

Authorization header:

```text
Authorization: Bearer https://cloud.dify.ai/v1
```

Configure the remaining values in the model parameter:

```text
dify|API_KEY|BOT_TYPE|INPUT_VARIABLE|OUTPUT_VARIABLE
```

Chat example:

```json
{
  "model": "dify|app-xxxx|Chat"
}
```

Workflow example:

```json
{
  "model": "dify|app-xxxx|Workflow|input|output"
}
```

Example request:

```bash
curl https:///v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer https://cloud.dify.ai/v1" \
  -X POST \
  -d '{
    "model":"dify|app-xxxx|Chat",
    "stream":true,
    "messages":[
      {
        "role":"system",
        "content":"You are a helpful assistant."
      },
      {
        "role":"user",
        "content":"Hello"
      }
    ]
  }'
```

### Image Input Support

D2O supports image inputs for vision-capable Dify applications.

Example:

```json
{
  "model": "dify",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "Please analyze this image."
        },
        {
          "type": "image_url",
          "image_url": {
            "url": "https://example.com/image.jpg"
          }
        }
      ]
    }
  ]
}
```

### Supported Features

- OpenAI-compatible Chat Completions API
- Chat applications
- Completion applications
- Agent applications
- Workflow applications
- Streaming responses
- Blocking responses
- Image input support
- Custom workflow variables

## Why Deploy D2O (Dify2OpenAI) on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying D2O (Dify2OpenAI) on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.

## Similar templates

- [Chat Chat](https://railway.com/deploy/-WWW5r) — Chat Chat, your own unified chat and search to AI platform.
- [stella](https://railway.com/deploy/stella) — Self-host stella with web, API, Postgres, Redis, and object storage.
- [Hermes Agent | OpenClaw Alternative with Dashboard](https://railway.com/deploy/hermes-agent-or-openclaw-alternative-wit) — Self-Hosted Hermes AI Agent for Telegram, Discord & Slack

Open this page in a browser: https://railway.com/deploy/dify2openai
