Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Langgenius Dify CreateApp

From Leeroopedia
Knowledge Sources Domains Last Updated
Dify LLM_Applications, Frontend, API 2026-02-12 00:00 GMT

Overview

Description

createApp is the primary frontend service function for creating new applications on the Dify platform. It sends a POST request to the apps endpoint with the application definition, including its name, mode, icon configuration, optional description, and optional initial model configuration. The function returns a promise resolving to the full application detail response.

Two alternative creation methods are also available in the same service module:

  • copyApp (lines 66-84) -- Duplicates an existing application by sending a POST to apps/{appID}/copy. It accepts the source appID along with the new application's name, icon, mode, and optional description. This preserves the source application's model and prompt configuration.
  • importDSL (lines 95-97) -- Imports an application from a YAML-based DSL definition by sending a POST to apps/imports. It supports importing from a YAML content string or a YAML URL, with an import mode that controls whether to create a new app or overwrite an existing one.

Usage

Call createApp from the frontend to initiate a new Dify application. The mode parameter is required and must be one of the five AppModeEnum values: 'completion', 'workflow', 'chat', 'advanced-chat', or 'agent-chat'. The returned AppDetailResponse contains the full application entity including its generated ID, timestamps, site configuration, and default model configuration.

Code Reference

Source Location

web/service/apps.ts, lines 23-41

Signature

export const createApp = ({
  name,
  icon_type,
  icon,
  icon_background,
  mode,
  description,
  config,
}: {
  name: string
  icon_type?: AppIconType
  icon?: string
  icon_background?: string
  mode: AppModeEnum
  description?: string
  config?: ModelConfig
}): Promise<AppDetailResponse> => {
  return post<AppDetailResponse>('apps', {
    body: { name, icon_type, icon, icon_background, mode, description, model_config: config },
  })
}

Alternative: copyApp (lines 66-84):

export const copyApp = ({
  appID, name, icon_type, icon, icon_background, mode, description,
}: {
  appID: string
  name: string
  icon_type: AppIconType
  icon: string
  icon_background?: string | null
  mode: AppModeEnum
  description?: string
}): Promise<AppDetailResponse> => {
  return post<AppDetailResponse>(`apps/${appID}/copy`, {
    body: { name, icon_type, icon, icon_background, mode, description },
  })
}

Alternative: importDSL (lines 95-97):

export const importDSL = ({
  mode, yaml_content, yaml_url, app_id, name, description,
  icon_type, icon, icon_background,
}: {
  mode: DSLImportMode
  yaml_content?: string
  yaml_url?: string
  app_id?: string
  name?: string
  description?: string
  icon_type?: AppIconType
  icon?: string
  icon_background?: string
}): Promise<DSLImportResponse> => {
  return post<DSLImportResponse>('apps/imports', {
    body: { mode, yaml_content, yaml_url, app_id, name, description, icon, icon_type, icon_background },
  })
}

Import

import { createApp, copyApp, importDSL } from '@/service/apps'

I/O Contract

Inputs (createApp)

Parameter Type Required Description
name string Yes The display name of the application.
icon_type 'emoji' | 'link') No The type of icon used for the application.
icon string No The icon value (emoji character or file ID depending on icon_type).
icon_background string No Background color for the icon (hex color string), used with emoji icons.
mode AppModeEnum Yes The application mode. One of: 'completion', 'workflow', 'chat', 'advanced-chat', 'agent-chat'.
description string No A text description of the application's purpose.
config ModelConfig No Initial model configuration including provider, model name, prompt template, completion params, and feature toggles.

Outputs

Field Type Description
(return) Promise<AppDetailResponse> Resolves to the full App entity, which includes: id, name, description, mode, enable_site, enable_api, model_config, site (SiteConfig), created_at, updated_at, tags, and all other App fields.

Usage Examples

Creating a basic chat application

import { createApp } from '@/service/apps'
import { AppModeEnum } from '@/types/app'

const newApp = await createApp({
  name: 'Customer Support Bot',
  mode: AppModeEnum.CHAT,
  icon_type: 'emoji',
  icon: '🤖',
  icon_background: '#FFEAD5',
  description: 'A chat application for handling customer inquiries.',
})

console.log(newApp.id) // the newly created application ID

Duplicating an existing application

import { copyApp } from '@/service/apps'
import { AppModeEnum } from '@/types/app'

const copiedApp = await copyApp({
  appID: 'source-app-id-123',
  name: 'Customer Support Bot (Copy)',
  icon_type: 'emoji',
  icon: '🤖',
  icon_background: '#FFEAD5',
  mode: AppModeEnum.CHAT,
})

Importing from a DSL YAML string

import { importDSL } from '@/service/apps'

const importResult = await importDSL({
  mode: 'yaml-content',
  yaml_content: yamlString,
  name: 'Imported App',
  description: 'Application imported from DSL definition.',
})

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment