How to add custom header parameters when requesting a model from an LLM node. #13738

Closed
opened 2026-02-21 19:13:37 -05:00 by yindo · 4 comments
Owner

Originally created by @Tingfing6 on GitHub (May 9, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.2.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

How to add custom header parameters when requesting a model from an LLM node.

Image

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @Tingfing6 on GitHub (May 9, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.2.0 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce How to add custom header parameters when requesting a model from an LLM node. ![Image](https://github.com/user-attachments/assets/388e6531-4444-435c-94e7-442690cf8717) ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo closed this issue 2026-02-21 19:13:37 -05:00
Author
Owner

@Tingfing6 commented on GitHub (May 9, 2025):

To disable content moderation when calling the Qianwen model, you need to add a custom request header.

@Tingfing6 commented on GitHub (May 9, 2025): To disable content moderation when calling the Qianwen model, you need to add a custom request header.
Author
Owner

@dosubot[bot] commented on GitHub (May 9, 2025):

To add custom header parameters when requesting a model from an LLM node in Dify, you can use the headerParams argument in the sendRequest method. This allows you to specify additional headers that will be merged with the default headers, which include Authorization and Content-Type. Here's a code snippet illustrating how this is done:

async sendRequest(
  method,
  endpoint,
  data = null,
  params = null,
  stream = false,
  headerParams = {}
) {
  const headers = {
    ...{
      Authorization: `Bearer ${this.apiKey}`,
      "Content-Type": "application/json",
    },
    ...headerParams
  };

  const url = `${this.baseUrl}${endpoint}`;
  let response;
  if (stream) {
    response = await axios({
      method,
      url,
      data,
      params,
      headers,
      responseType: "stream",
    });
  } else {
    response = await axios({
      method,
      url,
      ...(method !== "GET" && { data }),
      params,
      headers,
      responseType: "json",
    });
  }

  return response;
}

This approach allows you to add custom headers as needed for your API requests [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot[bot] commented on GitHub (May 9, 2025): <!-- Answer --> To add custom header parameters when requesting a model from an LLM node in Dify, you can use the `headerParams` argument in the `sendRequest` method. This allows you to specify additional headers that will be merged with the default headers, which include `Authorization` and `Content-Type`. Here's a code snippet illustrating how this is done: ```javascript async sendRequest( method, endpoint, data = null, params = null, stream = false, headerParams = {} ) { const headers = { ...{ Authorization: `Bearer ${this.apiKey}`, "Content-Type": "application/json", }, ...headerParams }; const url = `${this.baseUrl}${endpoint}`; let response; if (stream) { response = await axios({ method, url, data, params, headers, responseType: "stream", }); } else { response = await axios({ method, url, ...(method !== "GET" && { data }), params, headers, responseType: "json", }); } return response; } ``` This approach allows you to add custom headers as needed for your API requests <sup>[[1]](https://github.com/langgenius/dify/blob/main/sdks/nodejs-client/index.js)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/f8ab1605-4f8e-4933-b925-4fd7fddb4a5f?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/f8ab1605-4f8e-4933-b925-4fd7fddb4a5f?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/f8ab1605-4f8e-4933-b925-4fd7fddb4a5f?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/f8ab1605-4f8e-4933-b925-4fd7fddb4a5f?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/f8ab1605-4f8e-4933-b925-4fd7fddb4a5f?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/f8ab1605-4f8e-4933-b925-4fd7fddb4a5f?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/f8ab1605-4f8e-4933-b925-4fd7fddb4a5f?feedback_type=other)</sup>
Author
Owner

@Tingfing6 commented on GitHub (May 9, 2025):

To add custom header parameters when requesting a model from an LLM node in Dify, you can use the headerParams argument in the sendRequest method. This allows you to specify additional headers that will be merged with the default headers, which include Authorization and Content-Type. Here's a code snippet illustrating how this is done:要在 Dify 中从 LLM 节点请求模型时添加自定义标头参数,您可以在 sendRequest 方法中使用 headerParams 参数。这允许您指定将与默认标头(包括 AuthorizationContent-Type)合并的其他标头。下面是一个代码片段,说明了如何完成此作:

async sendRequest(
method,
endpoint,
data = null,
params = null,
stream = false,
headerParams = {}
) {
const headers = {
...{
Authorization: Bearer ${this.apiKey},
"Content-Type": "application/json",
},
...headerParams
};

const url = ${this.baseUrl}${endpoint};
let response;
if (stream) {
response = await axios({
method,
url,
data,
params,
headers,
responseType: "stream",
});
} else {
response = await axios({
method,
url,
...(method !== "GET" && { data }),
params,
headers,
responseType: "json",
});
}

return response;
}
This approach allows you to add custom headers as needed for your API requests [1].这种方法允许您根据需要为 API 请求添加自定义标头 [1]。

To continue talking to Dosu, mention @dosu.要继续与 Dosu 交谈,请提及 。

Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other帮助 Dosu 学习!给它反馈:伟大的回应 |无关紧要的答案 |不正确的来源 |太冗长 |幻觉 |Bug 报告 |其他

We are using a Docker image for deployment. In this case, how should we handle it?

@Tingfing6 commented on GitHub (May 9, 2025): > To add custom header parameters when requesting a model from an LLM node in Dify, you can use the `headerParams` argument in the `sendRequest` method. This allows you to specify additional headers that will be merged with the default headers, which include `Authorization` and `Content-Type`. Here's a code snippet illustrating how this is done:要在 Dify 中从 LLM 节点请求模型时添加自定义标头参数,您可以在 `sendRequest` 方法中使用 `headerParams` 参数。这允许您指定将与默认标头(包括 `Authorization` 和 `Content-Type`)合并的其他标头。下面是一个代码片段,说明了如何完成此作: > > async sendRequest( > method, > endpoint, > data = null, > params = null, > stream = false, > headerParams = {} > ) { > const headers = { > ...{ > Authorization: `Bearer ${this.apiKey}`, > "Content-Type": "application/json", > }, > ...headerParams > }; > > const url = `${this.baseUrl}${endpoint}`; > let response; > if (stream) { > response = await axios({ > method, > url, > data, > params, > headers, > responseType: "stream", > }); > } else { > response = await axios({ > method, > url, > ...(method !== "GET" && { data }), > params, > headers, > responseType: "json", > }); > } > > return response; > } > This approach allows you to add custom headers as needed for your API requests [[1]](https://github.com/langgenius/dify/blob/main/sdks/nodejs-client/index.js).这种方法允许您根据需要为 API 请求添加自定义标头 [[1]。](https://github.com/langgenius/dify/blob/main/sdks/nodejs-client/index.js) > > _To continue talking to [Dosu](https://dosu.dev), mention [@dosu](https://github.com/dosu).要继续与 [Dosu](https://dosu.dev) 交谈,请提及 。_ > > Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/f8ab1605-4f8e-4933-b925-4fd7fddb4a5f?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/f8ab1605-4f8e-4933-b925-4fd7fddb4a5f?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/f8ab1605-4f8e-4933-b925-4fd7fddb4a5f?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/f8ab1605-4f8e-4933-b925-4fd7fddb4a5f?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/f8ab1605-4f8e-4933-b925-4fd7fddb4a5f?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/f8ab1605-4f8e-4933-b925-4fd7fddb4a5f?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/f8ab1605-4f8e-4933-b925-4fd7fddb4a5f?feedback_type=other)帮助 Dosu 学习!给它反馈:伟大的回应 |无关紧要的答案 |不正确的来源 |太冗长 |幻觉 |Bug 报告 |其他 We are using a Docker image for deployment. In this case, how should we handle it?
Author
Owner

@crazywoola commented on GitHub (May 9, 2025):

This is only for bug report, if you would like to ask a question, please head to Discussions.

@crazywoola commented on GitHub (May 9, 2025): This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#13738