Obtain the API key for Dify on DMS

Updated at:

The API key of Data Management (DMS) Dify authenticates your requests to the DMS Dify service. Get this key before you call applications published in Dify Studio or integrate private LLM, Embedding, or Rerank model services on the Model Provider page.

Prerequisites

Before you begin, ensure that you have:

  • A DMS workspace with the O&M engineer, workspace administrator, or developer role

Permissions

Role

Create an API key

View an API key

O&M engineer

Yes

Yes

Workspace administrator

Yes

Yes

Developer

No

Yes

Visitor

No

No

Get an API key

  1. Log in to the workspace as an O&M engineer, workspace administrator, or developer.

  2. In the left-side navigation pane, choose image > Dify Resources.

  3. On the Dify Resources page, click API KEY to view existing API keys or create one.

Note

Created API keys cannot be deleted.

Use the API key

After you get the API key, include both headers in every request to meet security compliance requirements:

Header

Value

Description

Authorization

Bearer app-xxxx

The app token from the published Dify application

DifyApiKey

xxxx-xxxxxxx

The API key obtained in this topic

Important
  • This API is for testing purposes only. It does not support high-concurrency calls or connections longer than 90 seconds. This API will be gradually deprecated. Do not use it in production environments.

  • To use the API in production, create an internal or public endpoint for the instance when you create a Dify on DMS instance. Then, call the API through this endpoint. You can obtain the internal and public endpoints on the Dify Resources page in your workspace.

Example request:

curl -X POST 'https://dify-{region_id}-dms.aliyuncs.com/v1' \
--header 'Authorization: Bearer app-xxxx' \
--header 'DifyApiKey: xxxx-xxxxxxx' \
--header 'Content-Type: application/json' \
--data '{
    "inputs": {},
    "query": "What are the specs of the iPhone 13 Pro Max?",
    "response_mode": "streaming",
    "conversation_id": "",
    "user": "abc-123"
}'

For a full list of API endpoints and parameters, see Developing with APIs.

Third-party tool integration

The DMS Dify API supports both the OpenAI compatible protocol and the native Dify protocol:

  • OpenAI compatible: POST /v1/chat/completions

  • Native Dify: POST /v1/chat-messages

To configure a custom model provider for the DMS Dify API in a third-party tool, use the following parameters:

Parameter

Description

API compatibility mode

OpenAI chat.completions

Base URL

https://dify-{region_id}-dms.aliyuncs.com/v1

API key

Obtain from the API KEY page under Dify Resources in your workspace

Model ID

Send a GET /v1/models request to retrieve the list of available models

The API domain for the cn-hangzhou region is not reachable. Use a domain from an available region, such as cn-beijing, cn-shanghai, or cn-shenzhen.

The standard Dify Authorization: Bearer authentication method does not apply to the DMS Dify API. You must authenticate using the credentials obtained from the DMS console workspace.

Example: To add the DMS Dify API as a custom model provider in qwenpaw, add a custom provider with a provider ID of your choice (for example, dms-dify) and a display name of your choice (for example, DMS Dify). Set Base URL to the Dify API address of an available region followed by /v1. Set API key to the DMS API key. When adding a model, obtain the model ID by sending a GET /v1/models request.

Limitations

  • Each Dify instance supports only one API key.