Skip to content

PHP SDK drops the API path prefix when a custom base URL has no trailing slash #44568

Closed

Description

@Winoren

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is a bug report rather than a general question.
  • I searched open and closed issues/PRs for PHP base URL, trailing slash, and path-prefix fixes; I found no matching contribution.
  • This report is in English.

Dify version

Source main at 9f759255 (PHP SDK using locked Guzzle 7.15.5).

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

Configure the PHP SDK with the API directory URL without a trailing slash:

$client = new DifyClient('your-api-key', 'https://your-dify-host/dify/v1');
$response = $client->get_application_parameters('user-id');

The constructor passes that string directly to Guzzle's base_uri. Guzzle resolves the relative parameters endpoint against it as though v1 were a filename, producing /dify/parameters instead of /dify/v1/parameters. The simpler base https://your-dify-host/v1 similarly produces /parameters.

The shared constructor also affects ChatClient, CompletionClient and WorkflowClient. Appending / to the configured API directory is a workaround.

Expected Behavior

The SDK's custom API base URL preserves its complete directory prefix, with or without a trailing slash. The default cloud endpoint remains /v1/.

Actual Behavior

The last component of the base URL is dropped and requests go to the wrong endpoint, commonly returning 404.

Executed reproduction

Using PHP 8.5.10 via PHP.wasm CLI 3.1.57 and Guzzle 7.15.5, a local HTTP fixture accepts /dify/v1/parameters?user=test-user:

  • Original SDK: actual request /dify/parameters?user=test-user, HTTP 404.
  • Directory-normalized constructor: actual request /dify/v1/parameters?user=test-user, HTTP 200, expected Authorization header retained.

An offline Guzzle transport regression also fails on the original source and passes 28 cases with the fix: default URL, bare host, API prefix and nested deployment prefix, with/without trailing slash, across GET and POST methods in all four client classes. It checks exact request URI, method, authentication, payload and response status. No deployed Dify, provider/model request or production measurement is claimed.

Proposed change: ensure the shared constructor's API directory ends in /, add focused tests, and document the self-hosted URL convention. This is independent of the streaming option fix in #44271.

Investigated and verified with Codex assistance.

Activity

  1. dosubot commented on Oct 22, 2026

    @dosubot

    One additional regression case worth covering is multipart uploads: DifyClient::file_upload() and ChatClient::audio_to_text() call the shared Guzzle client directly, bypassing send_request(), with relative endpoints files/upload and audio-to-text. Constructor-level normalization would cover those paths too, so testing them with a nested base such as https://your-dify-host/dify/v1 would extend coverage beyond the GET/JSON POST cases. [1]

    To reply, just mention @dosu.


    Share context across your team and agents. Try Dosu.

    Leave Feedback Learn about dify with Dosu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions