API function(variable call) maybe abnormal in general application #5858

Closed
opened 2026-02-21 18:12:54 -05:00 by yindo · 4 comments
Owner

Originally created by @tigflanker on GitHub (Sep 29, 2024).

Originally assigned to: @laipz8200 on GitHub.

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

v0.7.3

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Hello, I have set up the API in the web API extension, but it seems that it is not being effectively referenced when calling it.

This is the API code, service, and test call situation:
微信截图_20240929161942

This is the API extension setup interface:
微信截图_20240929163003

This is the general application's invocation interface, where I have not been able to successfully invoke it in the opening remarks and prompts:
微信截图_20240929162013

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @tigflanker on GitHub (Sep 29, 2024). Originally assigned to: @laipz8200 on GitHub. ### 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 v0.7.3 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce Hello, I have set up the API in the web API extension, but it seems that it is not being effectively referenced when calling it. This is the API code, service, and test call situation: ![微信截图_20240929161942](https://github.com/user-attachments/assets/dda894bb-17af-4279-b39d-f99ce20ad39a) This is the API extension setup interface: ![微信截图_20240929163003](https://github.com/user-attachments/assets/8851e6b8-f525-4bac-83da-e00b7a13b410) This is the general application's invocation interface, where I have not been able to successfully invoke it in the opening remarks and prompts: ![微信截图_20240929162013](https://github.com/user-attachments/assets/a5d3efc4-fdd8-4e21-822a-49171a2d7ad4) ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 18:12:54 -05:00
yindo closed this issue 2026-02-21 18:12:54 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 29, 2024):

I found two similar unsolved discussions that might be relevant to your issue:

  1. Error in item: Invalid variable [1].
  2. Connection error: request error, status_code: 503 [2].

Regarding your issue, it seems that the API function is not being effectively referenced when calling it in the general application. Dify requires the API to return result=pong when it receives point=ping to verify the availability of the API. Ensure that your API correctly handles this verification request.

Here is a relevant code snippet to handle the ping request:

from fastapi import FastAPI, Body, HTTPException, Header
from pydantic import BaseModel

app = FastAPI()

class InputData(BaseModel):
    point: str
    params: dict = {}

@app.post("/api/dify/receive")
async def dify_receive(data: InputData = Body(...), authorization: str = Header(None)):
    expected_api_key = "123456"  # TODO Your API key of this API
    auth_scheme, _, api_key = authorization.partition(' ')

    if auth_scheme.lower() != "bearer" or api_key != expected_api_key:
        raise HTTPException(status_code=401, detail="Unauthorized")

    point = data.point

    # for debug
    print(f"point: {point}")

    if point == "ping":
        return {
            "result": "pong"
        }
    if point == "app.current_time":
        from datetime import datetime
        return {
            "result": datetime.now().isoformat()
        }
    # elif point == "{point name}":
        # TODO other point implementation here

    raise HTTPException(status_code=400, detail="Not implemented")

Make sure this part of the code is correctly implemented and that your API is returning the expected response for the ping request. Additionally, ensure that your API endpoint is correctly configured to handle the Authorization header and the Content-Type as application/json.

According to the Dify documentation, the API should be set up to handle requests with the following headers and body:

Headers:

  • Content-Type: application/json
  • Authorization: Bearer {api_key}

Request Body:

{
    "point": "ping"
}

Expected Response:

{
    "result": "pong"
}

Ensure that your API adheres to these specifications to be correctly referenced and utilized by the general application [3][4][5].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Sep 29, 2024): <!-- Answer --> I found two similar unsolved discussions that might be relevant to your issue: 1. [Error in item: Invalid variable](https://github.com/langgenius/dify/discussions/8611) <sup>[[1]](https://github.com/langgenius/dify/discussions/8611)</sup>. 2. [Connection error: request error, status_code: 503](https://github.com/langgenius/dify/discussions/6181) <sup>[[2]](https://github.com/langgenius/dify/discussions/6181)</sup>. Regarding your issue, it seems that the API function is not being effectively referenced when calling it in the general application. Dify requires the API to return `result=pong` when it receives `point=ping` to verify the availability of the API. Ensure that your API correctly handles this verification request. Here is a relevant code snippet to handle the `ping` request: ```python from fastapi import FastAPI, Body, HTTPException, Header from pydantic import BaseModel app = FastAPI() class InputData(BaseModel): point: str params: dict = {} @app.post("/api/dify/receive") async def dify_receive(data: InputData = Body(...), authorization: str = Header(None)): expected_api_key = "123456" # TODO Your API key of this API auth_scheme, _, api_key = authorization.partition(' ') if auth_scheme.lower() != "bearer" or api_key != expected_api_key: raise HTTPException(status_code=401, detail="Unauthorized") point = data.point # for debug print(f"point: {point}") if point == "ping": return { "result": "pong" } if point == "app.current_time": from datetime import datetime return { "result": datetime.now().isoformat() } # elif point == "{point name}": # TODO other point implementation here raise HTTPException(status_code=400, detail="Not implemented") ``` Make sure this part of the code is correctly implemented and that your API is returning the expected response for the `ping` request. Additionally, ensure that your API endpoint is correctly configured to handle the `Authorization` header and the `Content-Type` as `application/json`. According to the Dify documentation, the API should be set up to handle requests with the following headers and body: **Headers:** - `Content-Type: application/json` - `Authorization: Bearer {api_key}` **Request Body:** ```json { "point": "ping" } ``` **Expected Response:** ```json { "result": "pong" } ``` Ensure that your API adheres to these specifications to be correctly referenced and utilized by the general application <sup>[[3]](https://github.com/langgenius/dify-docs/blob/main/en/guides/extension/api-based-extension/README.md)</sup><sup>[[4]](https://github.com/langgenius/dify-docs/blob/main/zh_CN/guides/extension/api_based_extension/README.md)</sup><sup>[[5]](https://github.com/langgenius/dify-docs/blob/main/zh_CN/guides/extension/api-based-extension/README.md)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@tigflanker commented on GitHub (Sep 29, 2024):

@dosu I have already tested "point": "ping" and successfully received a response with "result": "pong".
Now it appears that the service can pass the test, and the API can be set up successfully.
The issue might be with the API invocation (variable reference) in the large language model application step.

@tigflanker commented on GitHub (Sep 29, 2024): @dosu I have already tested "point": "ping" and successfully received a response with "result": "pong". Now it appears that the service can pass the test, and the API can be set up successfully. The issue might be with the API invocation (variable reference) in the large language model application step.
Author
Owner

@dosubot[bot] commented on GitHub (Sep 29, 2024):

If the API passes the "ping" test successfully but the variable reference in the large language model application step is not working, it might be due to incorrect or missing credentials. Ensure that the environment variables for the API credentials are correctly set with valid values:

os.environ.get("VOLC_API_KEY")
os.environ.get("VOLC_SECRET_KEY")
os.environ.get("VOLC_MODEL_ENDPOINT_ID")

If these values are not set or are incorrect, the API invocation will fail even if the "ping" test passes [1].

Additionally, specific logs or error messages are generated when the variable reference fails. The invoke method in the LargeLanguageModel class includes a try-except block that catches exceptions and triggers error callbacks. Ensure to check these logs for any exceptions that might provide more insight into the issue [2].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Sep 29, 2024): <!-- Answer --> If the API passes the "ping" test successfully but the variable reference in the large language model application step is not working, it might be due to incorrect or missing credentials. Ensure that the environment variables for the API credentials are correctly set with valid values: ```python os.environ.get("VOLC_API_KEY") os.environ.get("VOLC_SECRET_KEY") os.environ.get("VOLC_MODEL_ENDPOINT_ID") ``` If these values are not set or are incorrect, the API invocation will fail even if the "ping" test passes <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/tests/integration_tests/model_runtime/volcengine_maas/test_llm.py)</sup>. Additionally, specific logs or error messages are generated when the variable reference fails. The `invoke` method in the `LargeLanguageModel` class includes a try-except block that catches exceptions and triggers error callbacks. Ensure to check these logs for any exceptions that might provide more insight into the issue <sup>[[2]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/__base/large_language_model.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@crazywoola commented on GitHub (Sep 29, 2024):

Duplicated https://github.com/langgenius/dify/issues/7520

@crazywoola commented on GitHub (Sep 29, 2024): Duplicated https://github.com/langgenius/dify/issues/7520
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5858