#!/usr/bin/env bash # Connect Dify to exe.dev's LLM gateway, from https://exe.dev/deploy/dify # Run on the VM: DIFY_EMAIL=you@example.com bash setup-models.sh # It signs in to the console on localhost:8080 with the password in # ~/dify-admin-password, then: # 1. installs the OpenAI and Anthropic model plugins from Dify's marketplace, # 2. points both at https://llm.int.exe.xyz with a placeholder key # (the gateway needs none), # 3. makes gpt-5.4-mini the default chat model and text-embedding-3-small # the default embedding model. # Run it again any time; finished steps are skipped. set -euo pipefail : "${DIFY_EMAIL:?set DIFY_EMAIL to the admin account email}" PASSWORD_FILE=${PASSWORD_FILE:-$HOME/dify-admin-password} CONSOLE=http://localhost:8080/console/api GATEWAY=https://llm.int.exe.xyz MARKETPLACE=https://marketplace.dify.ai/api/v1/plugins jar=$(mktemp) trap 'rm -f "$jar"' EXIT # Console requests need the session cookies and the CSRF token. api() { local method=$1 path=$2; shift 2 curl -fsS -X "$method" -b "$jar" -H 'Content-Type: application/json' \ -H "X-CSRF-Token: $(awk '$6 ~ /csrf_token$/ {print $7}' "$jar")" \ "$CONSOLE$path" "$@" } echo "Signing in as $DIFY_EMAIL" password=$(tr -d '\n' < "$PASSWORD_FILE" | base64 -w0) curl -fsS -c "$jar" -H 'Content-Type: application/json' "$CONSOLE/login" \ -d "{\"email\":\"$DIFY_EMAIL\",\"password\":\"$password\",\"remember_me\":true}" >/dev/null installed=$(api GET /workspaces/current/plugin/list?page=1\&page_size=100 | jq -r '.plugins[].plugin_id') for plugin in langgenius/openai langgenius/anthropic; do if grep -qx "$plugin" <<<"$installed"; then echo "Plugin $plugin: already installed" continue fi id=$(curl -fsS "$MARKETPLACE/$plugin" | jq -r .data.plugin.latest_package_identifier) echo "Plugin $plugin: installing $id" task=$(api POST /workspaces/current/plugin/install/marketplace \ -d "{\"plugin_unique_identifiers\":[\"$id\"]}") if [ "$(jq -r .all_installed <<<"$task")" != true ]; then task_id=$(jq -r .task_id <<<"$task") for _ in $(seq 60); do status=$(api GET "/workspaces/current/plugin/tasks/$task_id" | jq -r .task.status) [ "$status" = success ] && break [ "$status" = failed ] && { api GET "/workspaces/current/plugin/tasks/$task_id" | jq .; exit 1; } sleep 5 done [ "$status" = success ] || { echo "Plugin $plugin: still installing; run this again"; exit 1; } fi done # Add a credential unless the provider already has one. connect() { local provider=$1 credentials=$2 if api GET "/workspaces/current/model-providers/$provider/credentials" \ | jq -e '.credentials // empty | length > 0' >/dev/null; then echo "Provider $provider: already connected" else echo "Provider $provider: connecting to $GATEWAY" api POST "/workspaces/current/model-providers/$provider/credentials" \ -d "{\"name\":\"exe.dev gateway\",\"credentials\":$credentials}" >/dev/null fi } connect langgenius/openai/openai \ "{\"openai_api_key\":\"exe-llm-gateway\",\"openai_api_base\":\"$GATEWAY/v1\",\"validate_model\":\"gpt-5.4-mini\",\"api_protocol\":\"responses\"}" connect langgenius/anthropic/anthropic \ "{\"anthropic_api_key\":\"exe-llm-gateway\",\"anthropic_api_url\":\"$GATEWAY\"}" echo "Default models: gpt-5.4-mini, text-embedding-3-small" api POST /workspaces/current/default-model -d '{"model_settings":[ {"model_type":"llm","provider":"langgenius/openai/openai","model":"gpt-5.4-mini"}, {"model_type":"text-embedding","provider":"langgenius/openai/openai","model":"text-embedding-3-small"}]}' >/dev/null api GET /workspaces/current/model-providers | jq -r '.data[] | select(.provider | test("openai/openai$|anthropic/anthropic$")) | "\(.provider): \(.custom_configuration.status)"'