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

enh: Propagate bearer token from header if one exists for OpenAI-compatible endpoints #278

Merged
merged 8 commits into from
Feb 26, 2024

Conversation

jeffreyftang
Copy link
Contributor

@jeffreyftang jeffreyftang commented Feb 23, 2024

Since the OpenAI client doesn't include an API token or authentication key as part of the request payload, it's useful to propagate the bearer token from the incoming request headers so that downstream calls can use it to authenticate.

Alternatively, we could support passing such a token more explicitly via an additional header, which the OpenAI client does support. This is more expressive, but would require the user to take more action.

@jeffreyftang jeffreyftang changed the title enh: Grab API token from header if exists for OpenAI-compatible endpoints enh: Propagate bearer token from header if one exists for OpenAI-compatible endpoints Feb 24, 2024
req: Json<CompletionRequest>,
) -> Result<Response, (StatusCode, Json<ErrorResponse>)> {
let req = req.0;
let mut gen_req = CompatGenerateRequest::from(req);

// If a bearer token was present in this request, pass the associated token along.
let _ = headers.get("authorization").map_or((), |x| {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should do this for the generate and generate_stream endpoints as well (if the user did not pass a token explicitly).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@tgaddair tgaddair marked this pull request as ready for review February 24, 2024 20:52
@jeffreyftang jeffreyftang merged commit 740fa0b into main Feb 26, 2024
1 check passed
@jeffreyftang jeffreyftang deleted the api-token-from-header branch February 26, 2024 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants