Communityコーディング&開発github.com

SystemTce/dify-skills

Dify 参考资料 - DSL構文、APIドキュメント、SDKリファレンス、CLIコマンド

dify-skills とは?

このスキルは、AIエージェント(Claude Code、Cursor、Codexなど)向けに、Difyプラットフォームの包括的なリファレンス情報を提供します。DSL構文リファレンスでは、ワークフローYAMLの構造、ノードタイプ(start、llm、agent、knowledge-retrievalなど)、変数参照の構文を網羅しています。APIリファレンスでは、チャットメッセージ、ワークフロー、データセットの各エンドポイントと、リクエスト/レスポンスのJSON形式、認証方法(Bearerトークン)、エラーコードを説明しています。SDKリファレンスでは、Python SDK(dify-client)のインストール、基本的な使い方、ストリーミング応答、ワークフロー実行のコード例を提供します。CLIリファレンスでは、dify-cliのプラグイン管理、ワークフロー操作、アプリ管理、環境変数設定の各コマンドとそのオプションを解説しています。このスキールは、Difyの開発や運用において、構文、API、SDK、CLIの詳細を素早く参照する必要がある開発者やAIエージェントユーザーにとって非常に有用です。

対応✓Claude Code✓Codex CLI~Cursor
npx skills add https://github.com/SystemTce/dify-skills/tree/main/06-reference

Installed? Explore more コーディング&開発 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Dify リファレンス SKILL

構文、API、CLIなどのリファレンス情報を検索します

クイックナビゲーション


DSL 構文リファレンス

ワークフロー DSL 構造

version: 0.0.1
graph:
  nodes:
    - id: node_id
      data:
        type: node_type
        # ノード設定
  edges:
    - source: source_node_id
      target: target_node_id

ノードタイプ

タイプ説明必須フィールド
start開始ノードvariables
llmLLM ノードmodel, prompt_template
agentエージェントノードagent_parameters
knowledge-retrievalナレッジ検索dataset_ids, query_variable_selector
http-requestHTTP リクエストurl, method, headers
codeコード実行code_type, code
toolツールノードprovider_type, tool_name
if-else条件分岐conditions
iterationイテレーションiterator_variable_name
loopループmax_loop_count
answer応答ノードanswer

変数参照

# システム変数
{{#sys.query#}}           # ユーザークエリ
{{#sys.files#}}           # アップロードされたファイル
{{#sys.conversation_id#}} # 会話ID

# ノード出力
{{#node_id.output_field#}}

# 配列アクセス
{{#items[0]#}}           # 配列の最初の要素
{{#items[-1]#}}          # 配列の最後の要素

# オブジェクトプロパティ
{{#object.field#}}       # オブジェクトのプロパティ

完全な例

workflow:
  graph:
    nodes:
      - id: start
        data:
          type: start
          variables:
            - name: query
              type: text
              required: true

      - id: classify
        data:
          type: question-classifier
          instruction: "ユーザーの質問を分類してください"
          categories:
            - name: technical
              description: 技術的な質問
            - name: general
              description: 一般的な質問

      - id: llm
        data:
          type: llm
          model:
            provider: openai
            name: gpt-4
          prompt_template:
            - role: system
              text: "あなたはアシスタントです"
            - role: user
              text: "{{#start.query#}}"
          context:
            enabled: false

      - id: answer
        data:
          type: answer
          answer: "{{#llm.text#}}"

    edges:
      - source: start
        target: classify
      - source: classify
        target: llm
        source_handle: general
      - source: llm
        target: answer

API リファレンス

認証

すべてのAPIリクエストは、ヘッダーにAPI Keyを含める必要があります:

Authorization: Bearer YOUR_API_KEY

エンドポイント概要

アプリケーション API

エンドポイントメソッド説明
/v1/chat-messagesPOSTチャットメッセージの送信
/v1/completionsPOSTテキスト補完
/v1/parametersGETアプリケーションパラメータの取得
/v1/file-uploadPOSTファイルアップロード

ワークフロー API

エンドポイントメソッド説明
/v1/workflows/runPOSTワークフローの実行
/v1/workflows/runGET実行状態の取得
/v1/workflows/tasksGETタスク一覧の取得

データセット API

エンドポイントメソッド説明
/v1/datasetsGETデータセット一覧
/v1/datasetsPOSTデータセットの作成
/v1/datasets/{id}/documentsGETドキュメント一覧
/v1/datasets/{id}/retrievePOSTナレッジ検索

リクエスト/レスポンス形式

チャットメッセージリクエスト

{
  "query": "ユーザークエリ",
  "user": "user_123",
  "conversation_id": "オプションの会話ID",
  "response_mode": "blocking | streaming",
  "files": [
    {
      "type": "image",
      "transfer_method": "remote_url",
      "url": "https://example.com/image.jpg"
    }
  ],
  "retrieval_model": {
    "query": "{{#sys.query#}}",
    "top_k": 3
  }
}

チャットメッセージレスポンス

{
  "message_id": "msg_xxx",
  "conversation_id": "conv_xxx",
  "answer": "AIの応答内容",
  "metadata": {
    "usage": {
      "prompt_tokens": 100,
      "completion_tokens": 50,
      "total_tokens": 150
    },
    "retrieval_resources": [
      {
        "position": 1,
        "document_id": "doc_xxx",
        "content": "関連ドキュメントの内容..."
      }
    ]
  }
}

エラーレスポンス

{
  "code": "invalid_api_key",
  "message": "Invalid API key",
  "status_code": 401
}

よくあるエラーコード:

エラーコードHTTP ステータスコード説明
invalid_api_key401API Key が無効
invalid_parameter400パラメータエラー
quota_exceeded403割り当て超過
rate_limit_exceeded429レート制限
internal_server_error500サーバーエラー

SDK リファレンス

Python SDK

インストール

pip install dify-client

基本的な使い方

from dify_client import DifyClient

# クライアントの初期化
client = DifyClient(
    api_key="app-xxx",
    base_url="https://api.dify.ai/v1"
)

# チャットメッセージの送信
response = client.chat.messages.create(
    query="こんにちは",
    user="user_123"
)
print(response.answer)

ストリーミング応答

from dify_client import DifyClient

client = DifyClient(api_key="app-xxx")

# ストリーミングチャット
for event in client.chat.messages.stream(
    query="話を聞かせて",
    user="user_123"
):
    if event.event == "message":
        print(event.data.answer, end="")

ワークフロー実行

# ワークフローの実行
response = client.workflows.run(
    inputs={"query": "テスト"},
    user="user_123",
    response_mode="blocking"
)
print(response.data.output)

SDK クラスリファレンス

DifyClient

class DifyClient:
    def __init__(self, api_key: str, base_url: str = "https://api.dify.ai/v1"):
        """クライアントを初期化"""
        pass

    @property
    def chat(self) -> ChatClient:
        """チャットクライアント"""
        pass

    @property
    def workflows(self) -> WorkflowClient:
        """ワークフロークライアント"""
        pass

    @property
    def datasets(self) -> DatasetClient:
        """データセットクライアント"""
        pass

ChatClient

class ChatClient:
    def create(self, query: str, user: str, **kwargs) -> ChatMessage:
        """チャットメッセージを送信(ブロッキング)"""
        pass

    def stream(self, query: str, user: str, **kwargs) -> Iterator[ChatEvent]:
        """チャットメッセージを送信(ストリーミング)"""
        pass

CLI リファレンス

インストール

pip install dify-cli

コマンド概要

プラグインコマンド

# プラグインの初期化
dify plugin init [options]

# プラグインの実行
dify plugin run [options]

# プラグインのパッケージ化
dify plugin package [options]

# プラグインの公開
dify plugin publish [options]

# インストール済みプラグインの一覧
dify plugin list

ワークフローコマンド

# ワークフローのエクスポート
dify workflow export <workflow_id> [options]

# ワークフローのインポート
dify workflow import <file> [options]

# ワークフローの検証
dify workflow validate <file>

# ワークフローの実行
dify workflow run <workflow_id> --inputs '{}'

アプリケーションコマンド

# アプリケーション一覧
dify app list

# アプリケーション情報の取得
dify app info <app_id>

# アプリケーションのデプロイ
dify app deploy <app_id>

環境変数コマンド

# 環境変数一覧
dify env list

# 環境変数の設定
dify env set <key> <value>

# 環境変数の取得
dify env get <key>

# 環境変数の削除
dify env delete <key>

オプション説明

オプション省略形説明デフォルト値
--api-key-kAPI Key環境変数 DIFY_API_KEY
--base-url-bベースURLhttps://api.dify.ai/v1
--output-o出力形式json
--quiet-qサイレントモードfalse
--debug-dデバッグモードfalse

使用例

# API Key の設定
export DIFY_API_KEY="app-xxx"

# プラグインプロジェクトの初期化
dify plugin init my-plugin --template tool

# プラグインの実行
dify plugin run --port 5000

# ワークフローのエクスポート
dify workflow export wf_xxx -o workflow.yaml

# ワークフローのインポート
dify workflow import workflow.yaml

よくある質問

API 関連

Q: API Key を取得するには? A: Dify コンソール -> 設定 -> API で作成します。

Q: リクエスト頻度制限は? A: デフォルトは60リクエスト/分で、引き上げを申請できます。

Q: ストリーミング応答を処理するには? A: response_mode=streaming を使用し、SSE イベントを解析します。

ワークフロー関連

Q: 変数を参照するには? A: {{#node_id.field#}} 構文を使用します。

Q: どのノードタイプがサポートされていますか? A: 詳細はノードタイプの表を参照してください。

Q: ループを処理するには? A: iteration または loop ノードを使用します。

プラグイン関連

Q: カスタムプラグインを開発するには? A: 02-plugin SKILL を参照してください。

Q: プラグインはどのようにして資格情報を取得しますか? A: self.runtime_credentials を使用します。


関連 SKILL


関連リソース


バージョン情報: v1.0.0 | 最終更新: 2026-03-05

Individual skills in this repo

This repo contains 5 individual skills — each has its own dedicated page.

関連スキル