canonical: https://jentic.com/apis/dify.ai/dify

# Dify API

The Dify API is the application-runtime interface for Dify AI apps - chatbots, agents, and workflow apps built in the Dify console. It exposes chat-message generation, conversation management, file upload, audio transcription and synthesis, message feedback, annotations, and app metadata behind a small Bearer-authenticated surface. Eighteen endpoints cover the runtime needs of an embedded chatbot or backend AI workflow without exposing the underlying model providers directly.

## For AI agents

Run chat completions, manage conversations, transcribe and synthesize audio, and upload files for Dify-hosted AI apps and agents.

## Scope

Does not handle model fine-tuning, knowledge-base ingestion, or app authoring - use for Dify app runtime invocation only.

## Capabilities

- Send chat messages and stream responses from a Dify chatbot or agent
- Manage multi-turn conversations including renaming and deleting threads
- Upload files for use as context in chat or workflow runs
- Transcribe audio to text and synthesize text to audio through the Dify runtime
- Capture user feedback and annotations on assistant messages
- Retrieve app metadata, parameters, and suggested questions for a session

## Use cases

### Embedded Chatbot Backend

Power a website or in-app chat widget by routing user messages to a Dify app through POST /chat-messages. The endpoint streams the assistant response, threads messages into a conversation, and returns metadata such as latency and token usage. Suitable for support assistants, knowledge-base chatbots, and product-onboarding agents built in the Dify console.

Example prompt: Send the user message to /chat-messages with the current conversation id, stream tokens to the UI, and store the new message id when the stream ends

### Voice-Enabled AI Agent

Build a voice agent by chaining /audio-to-text, /chat-messages, and /text-to-audio. The user's spoken input is transcribed, sent to the Dify app, and the assistant's reply is synthesized back to audio for playback. This collapses what used to require three separate vendor integrations into a single platform with consistent auth.

Example prompt: Receive a recorded audio clip, post it to /audio-to-text, send the transcript to /chat-messages, then call /text-to-audio on the response and return the audio to the caller

### Feedback-Driven Quality Loop

Capture thumbs-up and thumbs-down feedback on assistant responses to iterate on prompts and knowledge bases. POST to `/messages/{message_id}/feedbacks` records the user verdict, and downstream analytics or review pipelines can pull underperforming messages for prompt tuning. This makes the Dify app a continuously improving product surface.

Example prompt: When the user clicks thumbs-down on assistant message msg-123, POST to `/messages/msg-123/feedbacks` with rating=dislike and the user's optional reason

### AI Agent Tool Backend

Use a Dify app as a callable tool from another AI agent through Jentic. The orchestrator searches for "send a Dify chat message", Jentic returns POST /chat-messages with its input schema, and the agent invokes it as a sub-task - for example, to summarise a document or answer a domain-specific question handled by a specialised Dify app.

Example prompt: Call the legal-summary Dify app via /chat-messages with the contract text as user input, return the structured summary, and store it in the case record

## Key endpoints

| Method | Path | Description |
| --- | --- | --- |
| POST | `/chat-messages` | Send a chat message and stream the response |
| POST | `/chat-messages/{task_id}/stop` | Stop a streaming chat task |
| GET | `/conversations` | List conversations for the current user |
| POST | `/files/upload` | Upload a file for use as context |
| POST | `/audio-to-text` | Transcribe an audio file |
| POST | `/text-to-audio` | Synthesize audio from text |
| POST | `/messages/{message_id}/feedbacks` | Submit feedback on a message |

## Key resources

- **Chat Messages** — Send chat messages and stream responses from a Dify app
- **Conversations** — List, rename, and delete conversation threads
- **Messages** — Submit feedback, annotations, and retrieve suggested follow-ups
- **Files** — Upload files used as context in chat or workflow runs
- **Audio** — Transcribe audio to text and synthesize text to audio
- **App** — Retrieve app metadata, parameters, and meta information

## Why Jentic

- **Setup:** Wiring Dify by hand means learning its app-scoped bearer auth, pointing at the api.dify.ai runtime host, and handling streaming and file-upload calls yourself. Through Jentic you install once, import the Dify API from the API Directory, store the app token once, and your agent calls it.
- **Permission scoping:** Dify carries the target in the request body rather than a resource id in the URL path, so scope your agent to the operations it needs, such as sending a chat message or transcribing audio. You choose the operations it may call, so message feedback or stopping a running task are not included unless you add them.
- **Credential handling:** Your Dify app token is stored once, encrypted, by your own Jentic One instance and injected at execution time. It never enters the agent's prompt, logs, or context.
- **Discovery method:** Agents search Jentic by intent such as 'send a chat message' or 'transcribe audio', and Jentic returns the matching Dify operation with its input schema so the agent calls the right endpoint without browsing the reference docs.

## Related APIs

- **OpenAI API** — Direct LLM access without the Dify app-builder layer
- **Anthropic API** — Claude family models direct from Anthropic
- **ElevenLabs API** — Higher-quality voice synthesis if Dify text-to-audio is not sufficient

## FAQ

### What authentication does the Dify API use?

Dify uses HTTP Bearer authentication. Each Dify app issues an app-scoped API key from the Dify console. Through Jentic the token is stored in the encrypted vault and injected at execution time only.

### Can I stream chat responses from a Dify app?

Yes. POST /chat-messages supports a streaming response mode that returns server-sent events as the assistant generates tokens. The same endpoint also supports a blocking mode if streaming is not needed.

### What are the rate limits for the Dify API?

Dify applies per-app rate limits set on the Dify console. The exact ceiling depends on the plan tier; bursty workloads should respect the limits visible in 429 response headers and retry with exponential backoff.

### How do I send a chat message through Jentic?

Run a Jentic search for "send a Dify chat message". Jentic returns POST /chat-messages with its input schema (query, conversation_id, user, response_mode). Load the schema, populate the fields, and execute.

### Does the API support file uploads as conversation context?

Yes. POST `/files/upload` accepts multipart file uploads and returns a file id that can be referenced in subsequent /chat-messages requests, so the assistant can read documents the user has attached.

### How do I install the Jentic SDK to call Dify?

Run pip install jentic, set JENTIC_AGENT_API_KEY to your ak_* key, then use Jentic with SearchRequest, LoadRequest, and ExecutionRequest. Get started with Jentic One, the self-hosted execution layer.

### Can I limit what my agent is allowed to do with the Dify API?

Yes. Because you run Jentic One yourself, your own rules decide which Dify operations and credentials the agent may use, and the Dify API selects its target through the request body rather than a resource id in the URL path. You can scope the agent to only the operations it needs, such as sending a chat message to /chat-messages or transcribing audio via /audio-to-text. Operations like submitting message feedback or stopping a running chat task stay off-limits unless you explicitly grant them.
