05.09

Auth: API keys, JWT, and OAuth2

skillmaxingPython with AIAuth: API keys, JWT, and OAuth2
Visual lesson

Auth: API keys, JWT, and OAuth2

Included with Pro · 4:53
Lessons · 1,198 words

Every authenticated route in Relay asks the same question: who is calling, and are they allowed? In FastAPI that question is a dependency. get_current_user reads a credential from the request, checks it, and returns a CurrentUser or raises a 401. Routes declare user: UserDep and never see the credential. What changes between schemes is only the first step: where the credential comes from and how it is verified.

A credential becomes a user
Figure 1A credential becomes a userRoutes declare user: UserDep and never see the credential.

Relay needs two schemes. Machine clients (a customer's own backend calling /chat) send an API key in a header. People using the web client sign in once and then send a short-lived token. The fastapi.security module has a helper for each that also teaches /docs how to send the credential, so the Authorize button works.

Pro

Continue reading

Pro unlocks every video lesson, the full notes and runnable code across the Python with AI course, from the language itself to agents, MCP, Langfuse and deployment.

Unlock full access to
Python with AIAI researchComplete system design
30% off with LAUNCH30ends in 7h 40m
Buy now
View all plans ·Already Pro? Sign in
124 online