🔒 Easier Auth -- I'd like to pass a fastapi dependency to the add_routes method to secure them #80

Open
opened 2026-02-16 00:18:40 -05:00 by yindo · 5 comments
Owner

Originally created by @randypitcherii on GitHub (Dec 30, 2023).

Originally assigned to: @eyurtsev on GitHub.

  • right now I have to add my auth on langserve through middleware
  • this works in prod, so that's great!
  • in dev, it makes it so I have limited use of the swagger UI. That UI does not realize it needs to include auth headers in langserv endpoints as the dependency is not part of the route.

This is related to #294 -- fastapi dependency support lets me use swagger, but I'd still be blocked from securely accessing the playground until playground code supports auth headers.

Thanks! 🙏

Originally created by @randypitcherii on GitHub (Dec 30, 2023). Originally assigned to: @eyurtsev on GitHub. - right now I have to add my auth on langserve through middleware - this works in prod, so that's great! - in dev, it makes it so I have limited use of the swagger UI. That UI does not realize it needs to include auth headers in langserv endpoints as the dependency is not part of the route. This is related to #294 -- fastapi dependency support lets me use swagger, but I'd still be blocked from securely accessing the playground until playground code supports auth headers. Thanks! 🙏
yindo added the enhancement label 2026-02-16 00:18:40 -05:00
Author
Owner

@eyurtsev commented on GitHub (Jan 1, 2024):

@randypitcherii thanks for reporting! This makes sense.

For now, if you should be able to achieve that using the APIHandler object. See example here: https://github.com/langchain-ai/langserve/blob/main/examples/api_handler_examples/server.py

@eyurtsev commented on GitHub (Jan 1, 2024): @randypitcherii thanks for reporting! This makes sense. For now, if you should be able to achieve that using the `APIHandler` object. See example here: https://github.com/langchain-ai/langserve/blob/main/examples/api_handler_examples/server.py
Author
Owner

@randypitcherii commented on GitHub (Jan 1, 2024):

This helps a ton!! Thank you : )

@randypitcherii commented on GitHub (Jan 1, 2024): This helps a ton!! Thank you : )
Author
Owner

@eyurtsev commented on GitHub (Jan 3, 2024):

Added an ability to pass path dependencies to add_routes.

Examples using global dependencies and path dependencies have been added here: https://github.com/langchain-ai/langserve/tree/main/examples/auth

Neither of these options allows to do anything with the return value from the dependency as might be required to do implement logic specific to a particular user.

For those use cases, the best way right now is either using:

  1. APIHandler primtiives
  2. per request modifier function in add_routes
@eyurtsev commented on GitHub (Jan 3, 2024): Added an ability to pass path dependencies to `add_routes`. Examples using global dependencies and path dependencies have been added here: https://github.com/langchain-ai/langserve/tree/main/examples/auth Neither of these options allows to do anything with the return value from the dependency as might be required to do implement logic specific to a particular user. For those use cases, the best way right now is either using: 1. `APIHandler` primtiives 2. per request modifier function in add_routes
Author
Owner

@eyurtsev commented on GitHub (Jan 5, 2024):

Path dependencies are available here: https://github.com/langchain-ai/langserve/releases/tag/v0.0.38

@eyurtsev commented on GitHub (Jan 5, 2024): Path dependencies are available here: https://github.com/langchain-ai/langserve/releases/tag/v0.0.38
Author
Owner

@eyurtsev commented on GitHub (Jan 5, 2024):

Added some examples to the README for Auth: https://github.com/langchain-ai/langserve?tab=readme-ov-file#advanced

@randypitcherii Could you let me know if you encounter any issues on existing endpoints (except for playground)?

@eyurtsev commented on GitHub (Jan 5, 2024): Added some examples to the README for Auth: https://github.com/langchain-ai/langserve?tab=readme-ov-file#advanced @randypitcherii Could you let me know if you encounter any issues on existing endpoints (except for playground)?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langserve#80