FastAPI cookie parameters: declare cookies like query and path
Answer: You can define Cookie parameters the same way you define Query and Path parameters. Cookie is a sister class of Path and Query, and it inherits from the same common Param class. Declare cookies with Cookie, or the parameters would be interpreted as query parameters.
Examples
from fastapi import Cookie, FastAPI
Notes
Prefer the Annotated form if possible.
Reference list
Cookieparameters are declared the same way as Query and Path.Paramis the common class Cookie inherits from.query parametersare what you get if you forget to use Cookie.
See also
Claims
- id: C1 claim: Cookie parameters are defined the same way as Query and Path. source: S1 evidence: "You can define Cookie parameters the same way you define Query and Path parameters."
- id: C2 claim: Cookie is a sister class of Path and Query. source: S2 evidence: "Cookie
is a \"sister\" class ofPathandQuery`"
- id: C3 claim: Declare cookies with Cookie, or they are treated as query parameters. source: S2 evidence: "otherwise the parameters would be interpreted as query parameters"
Sources
- [S1] Cookie Parameters. FastAPI docs. https://fastapi.tiangolo.com/tutorial/cookie-params/ . License: MIT. Accessed 2026-11-18.
- [S2] cookie-params.md. FastAPI. https://raw.githubusercontent.com/fastapi/fastapi/master/docs/en/docs/tutorial/cookie-params.md . License: MIT. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: FastAPI docs, Cookie Parameters; FastAPI, cookie-params.md. MIT (https://raw.githubusercontent.com/fastapi/fastapi/master/LICENSE). Copyright FastAPI contributors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: FastAPI docs, Cookie Parameters; FastAPI, cookie-params.md. MIT (https://raw.githubusercontent.com/fastapi/fastapi/master/LICENSE). Copyright FastAPI contributors.
Cite this
iinventedlight. 2026. "FastAPI cookie parameters: declare cookies like query and path." iinventedlight Library, iil:note:m8hggc91, version of 2026-11-18. https://iinventedlight.com/library/notes/fastapi-cookie/. License: CC-BY-4.0.
@misc{iil_note_m8hggc91,
author = {{iinventedlight}},
title = {{FastAPI cookie parameters: declare cookies like query and path}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/fastapi-cookie/},
note = {Permanent ID iil:note:m8hggc91. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- fastapi-cookie.table.json (table; CC-BY-4.0)
- fastapi-cookie.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/fastapi-cookie.md.