Custom API tool sends unset optional header and cookie parameters as empty values or "None"

Open Beginner friendly
#46,010 0 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

@TemitopeKadri is already working on this.

Since Nov 10, 2026.

  • #46011 by @TemitopeKadri — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
77/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
api, backend

Research direction

Start in api/core/tools/custom_tool/tool.py at ApiTool.do_http_request and trace how get_parameter_value handles optional query, header, and cookie parameters with missing or null defaults. Check the related custom tool tests and add coverage for omitted optional values and boolean headers. Done means empty and None values are omitted for optional parameters, while a boolean header is sent as lowercase true.

Written by the indexing model from the issue text.

Description

Self Checks
  • I have read the Contributing Guide and Language Policy.
  • 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, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.
Dify version

main (b63ed037d0)

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce
  1. Create a custom tool (Tools → Custom → Create Custom Tool) from this schema:
openapi: 3.0.0
info: {title: demo, version: "1"}
servers: [{url: https://httpbin.org}]
paths:
  /anything:
    get:
      operationId: listItems
      parameters:
        - {name: X-Request-Id, in: header, required: false, schema: {type: string}}
        - {name: X-Tenant, in: header, required: false, schema: {type: string, default: null}}
        - {name: X-Dry-Run, in: header, required: false, schema: {type: boolean}}
        - {name: session, in: cookie, required: false, schema: {type: string}}
  1. Test the listItems tool with only X-Dry-Run = true filled in (leave the other parameters empty).
✔️ Expected Behavior

Optional header and cookie parameters that have no value are left out, as optional query parameters already are. A boolean header is sent as true, which is how the tool already sends a boolean query parameter (?flag=true).

X-Dry-Run: true
❌ Actual Behavior

Every declared header and cookie is sent, even when it has no value. A default: null is sent as the text None, and a boolean is sent as Python's True:

X-Request-Id:
X-Tenant: None
X-Dry-Run: True
Cookie: session=

APIs that validate these headers then reject the call or treat the value as real, for example a tenant named None or an empty session cookie that replaces the anonymous one.

In ApiTool.do_http_request (api/core/tools/custom_tool/tool.py), query parameters are skipped when get_parameter_value returns "". Header parameters are always set to str(value), and cookie parameters are always set to the raw value. get_parameter_value returns "" for an optional parameter without a default, and returns the schema default (here None) otherwise. A default: null query parameter is affected too: None is not "", so it is sent as ?q=.

Dominant language
Python
Stars
160k
Forks
25.4k
Avg merge
1d 1h
Merged PRs (30d)
608

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from langgenius/dify

All issues in langgenius/dify

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.