langchain
langchain copied to clipboard
Unable to pass headers to Completion, ChatCompletion, Embedding endpoints
OpenAI python client supports passing additional headers when invoking the following functions
openai.ChatCompletion.create
or
openai.Completion.create
For example: I can pass the headers as shown in the sample code below.
completion = openai.Completion.create(deployment_id=deployment_id,
prompt=payload_dict['prompt'], stop=payload_dict['stop'], temperature=payload_dict['temperature'], headers=headers, max_tokens=1000)
Langchain does not surface the capability to pass the headers when we need to include custom HTTPS headers from the client. It would very useful to include this capability especially when you have custom authentication scheme where the model is exposed as an endpoint.
This feature would be useful for my org as well. We need to put an API Gateway in front of the Azure OpenAI resource which requires additional headers to direct traffic.
This feature would be useful for my org as well. We need to put an API Gateway in front of the Azure OpenAI resource which requires additional headers to direct traffic.
For those using AWS API Gateway, you can work around these limitations by using a custom lambda authorizer to pass the "api-key" header as the usageIdentifierKey
back to the API, and setting the API Key Source to "AUTHORIZER".
This AWS example is a good start (they use the api-key in the query string, but this is easy to modify): https://aws.amazon.com/blogs/compute/accepting-api-keys-as-a-query-string-in-amazon-api-gateway/ And here is information on how to set the source of the api key: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-api-key-source.html
@hwchase17 - it appears this issue and https://github.com/hwchase17/langchain/issues/3992 are resolved, at least as of version 0.0.173.
cc @suman724
Hi, @suman724. I'm Dosu, and I'm helping the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.
From what I understand, the issue is that the Langchain library currently does not support passing headers when invoking the openai.ChatCompletion.create
or openai.Completion.create
functions. There have been some discussions in the comments about the importance of this feature, with users like headchem mentioning the need for additional headers for their organization's API Gateway. Another user, nkrumm, suggested a workaround for those using AWS API Gateway.
However, I also noticed that jcbartle mentioned that this issue and another related issue have been resolved in version 0.0.173.
Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.
Thank you for your understanding and contribution to the LangChain project. Let us know if you have any further questions or concerns.