Railway

Deploy Dify2Openai

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

Deploy Dify2Openai

Just deployed

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

DependencyRequiredPurpose
Dify APIYesBackend service that processes AI requests.

Deployment Dependencies

ResourceLink
GitHub Repositoryhttps://github.com/fatwang2/dify2openai
Docker Imagehttps://hub.docker.com/r/fatwang2/dify2openai
Dify Documentationhttps://docs.dify.ai

Implementation Details

Docker

Railway automatically builds the application from the included Dockerfile.

Alternatively, you can deploy the official Docker image:

fatwang2/dify2openai:latest

Public Networking

SettingValue
Proxy TypeHTTP Proxy
Target Port3000

Environment Variables

Configure the following Railway Variables before deployment.

VariableRequiredDescription
DIFY_API_URLYesBase URL of your Dify API.
API_KEYNoDify Application API Key. Can also be supplied per request.
BOT_TYPEYesApplication type: Chat, Completion, Agent, or Workflow.
INPUT_VARIABLENoWorkflow input variable name.
OUTPUT_VARIABLENoWorkflow output variable name.
MODELS_NAMENoModel name returned by the /v1/models endpoint. Defaults to dify.

Raw Editor example:

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 & 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:
https:///v1

Using the API

D2O supports three methods for passing your Dify configuration.

Method 1 — All Configuration in the Authorization Header

Authorization header:

Authorization: Bearer DIFY_API_URL|API_KEY|BOT_TYPE

Example:

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

Use the default model:

{
  "model": "dify"
}

Example request:

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:

Authorization: Bearer app-xxxx

Configure the remaining values in the model parameter:

dify|BOT_TYPE|DIFY_API_URL|INPUT_VARIABLE|OUTPUT_VARIABLE

Chat example:

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

Workflow example:

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

Example request:

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:

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

Configure the remaining values in the model parameter:

dify|API_KEY|BOT_TYPE|INPUT_VARIABLE|OUTPUT_VARIABLE

Chat example:

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

Workflow example:

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

Example request:

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:

{
  "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.


Template Content

More templates in this category

View Template
Chat Chat
Chat Chat, your own unified chat and search to AI platform.

okisdev
113
View Template
stella
Self-host stella with web, API, Postgres, Redis, and object storage.

Jan Kubica
1
View Template
Hermes Agent | OpenClaw Alternative with Dashboard
Self-Hosted Hermes AI Agent for Telegram, Discord & Slack

codestorm
56