Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global variables in API key field of OpenAi component not working properly when called via cURL #6268

Open
avatsaev opened this issue Feb 11, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@avatsaev
Copy link

avatsaev commented Feb 11, 2025

Bug Description

Global variables are not applied in API KEY field of open ai chat & embeddings components when calling workflows via API
Works properly in the editor playground
Global variable is properly set as a credential

Reproduction

  • Create a workflow that contains OpenAI chat component with the key value set from a global variable
  • Call the workflow via CURL

Error message:

❯ curl -X POST \
    "[REDACTED]/api/v1/run/7209dd18-ca3f-47ad-bf81-5e65f7dd5e7e?stream=false" \
    -H 'Content-Type: application/json'\
  -H 'x-api-key: [REDACTED]'\
    -d '{"input_value": "what is this document about",
    "output_type": "chat",
    "input_type": "chat"}'

{"detail":"{\"message\":\"Error running graph: Error building Component OpenAI: \\n\\nError code: 401 - {'error': {'message': \\\"Authentication Error, LiteLLM Virtual Key expected. Received=dummy, expected to start with 'sk-'.\\\", 'type': 'auth_error', 'param': 'None', 'code': '401'}}\",\"traceback\":null,\"description\":null,\"code\":null,\"suggestion\":null}"}%  
  • Replace the global variable in the openai component's API key field with a raw value
  • Call the curl again
❯ curl -X POST \
    "[REDACTED]/api/v1/run/7209dd18-ca3f-47ad-bf81-5e65f7dd5e7e?stream=false" \
    -H 'Content-Type: application/json'\
  -H 'x-api-key: [REDACTED]'\
    -d '{"input_value": "what is this document about",
    "output_type": "chat",
    "input_type": "chat"}'

{"session_id":"7209dd18-ca3f-47ad-bf81-5e65f7dd5e7e","outputs":[{"inputs":{"input_value":"what is this document about"},"outputs":[{"results":{"message":{"text_key":"text","data":{"timestamp":"2025-02-11T17:13:25+00:00","sender":"Machine","sender_name":"AI","session_id":"7209dd18-ca3f-47ad-bf81-5e65f7dd5e7e","text":"This document is a ...

Expected behavior

The call should succeed when using a global variable in the API key field of Open AI component

Who can help?

No response

Operating System

Docker deployment

Langflow Version

1.1.4.post1

Python Version

None

Screenshot

No response

Flow File

No response

@avatsaev avatsaev added the bug Something isn't working label Feb 11, 2025
@avatsaev avatsaev changed the title Global variables in API key field not working properly when called via cURL Global variables in API key field of OpenAi component not working properly when called via cURL Feb 11, 2025
Copy link

dosubot bot commented Feb 11, 2025

Hello @avatsaev! I'm here to help you with any bugs, questions, or contributions you have. Let's work together to solve the issue you're facing!

It seems that there is an issue with global variables not being applied correctly in the API key field of the OpenAI component when workflows are called via cURL in Langflow version 1.1.4.post1. This results in an authentication error.

To address this, you might want to check the following:

  1. Global Variable Configuration: Ensure that the global variable for the OpenAI API key is correctly configured and saved in the Langflow UI. Verify that it is of type Credential and that it is applied to the correct field.

  2. Environment Variables: If you are using environment variables to set global variables, make sure that LANGFLOW_STORE_ENVIRONMENT_VARIABLES is set to true in your .env file, and that the variable OPENAI_API_KEY is included in LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT [1].

  3. Encryption and Decryption: Ensure that the LANGFLOW_SECRET_KEY is correctly set and consistent across your deployment, as it is used for encrypting and decrypting global variables [1][2].

If these steps do not resolve the issue, it might be necessary to investigate further into how global variables are being substituted in API requests, as there might be a bug in the current implementation.

To continue talking to Dosu, mention @dosu.


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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant