FastAPI 0.164.0 and 0.165.0 Set Request Body and Form Limits

On 18 November 2026 the FastAPI account posted 0.164.0 for a maximum request body size and 0.165.0 for form_limits. The shared docs page says an unset body limit stays unlimited, and a parser miss returns HTTP 400 while an oversize read returns HTTP 413.

On 18 November 2026 the FastAPI account posted two notes about limits, five and a half hours apart. The first, timestamped 2026-11-18T13:17:17.000Z, said you can now set a maximum request body size in FastAPI, for the whole app or as an override on a router or a single path operation, and told readers to upgrade to FastAPI 0.164.0. The second, timestamped 2026-11-18T18:57:44.000Z, said that in FastAPI 0.165.0 you can set form_limits, and named three keys: max_fields, max_files, and max_part_size. Both notes point at the same docs page, Request Body Limits. The first post is the 13:17 UTC note. The second is the 18:57 UTC note.

Those two posts are short. They name a version, a place to set the limit, and a docs URL. They do not print a previous release number. They do not print a status code. They do not print a default. A team that stops at the posts knows that 0.164.0 is the version the account tied to a maximum request body size, and that 0.165.0 is the version the account tied to form_limits. The behavior lives on the page both posts cite. This piece stays inside that page and those two notes, plus one earlier note from the same account that is dated outside this week and is labeled as such below.

What the two posts actually assign

The 13:17 note assigns FastAPI 0.164.0 to one capability: a maximum request body size. It says the setting can cover the whole app, or override that choice for a router, or override it again for a single path operation. It does not say the upgrade itself writes a number into your app. It says you can now set the maximum, and it says to upgrade to that version and check the new docs.

The 18:57 note assigns FastAPI 0.165.0 to form_limits and lists the three names. It does not define the names. It does not say whether those three settings replace the body-size setting from the morning post, or sit beside it. Both notes send the reader to the same URL, so the page is the place that has to answer that question. Treating the afternoon post as a correction of the morning post would be a guess. The texts do not say that.

Both notes also print the same command line, uvx library-skills. The morning note says “Let your agent use it.” The afternoon note says “Teach your agent.” The docs page repeats a longer form of that instruction: use the official FastAPI skill for your installed version, and install it from your project directory with that same command. The page then points at a section titled Develop with AI. Neither post, and not the limits page, lists the files inside that skill. This article does not describe those files.

The page is the specification the posts point at

The posts are announcements. The page is where the parameters, the example numbers, the inheritance rules, and the status codes are written. Where a sentence below names FastAPI 0.164.0 or FastAPI 0.165.0, that version comes from the post that named it. Where a sentence describes what a parameter does, that description comes from the Request Body Limits page. The page itself, in the extract used here, does not stamp 0.164.0 or 0.165.0 onto individual headings. Combining the two sources is the reading. Inventing a third source is not.

The opening of the page frames the feature with a concrete split: an app that receives small JSON requests, and that also wants to let users upload larger files. That sentence is the reason the page gives for having more than one ceiling. A single app-wide number would force the JSON routes and the upload routes to share a size. The rest of the page is the mechanism for not doing that.

The documented body-size example

The page sets max_body_size in bytes when you create the FastAPI app. It then shows a different limit on an APIRouter, and a third limit on one path operation. The numbers in the example are exact. The app is created with max_body_size=1 * 1024 * 1024. The page calls that 1 MiB, and it spells the byte count as 1024 * 1024. The uploads router is created with prefix /uploads and max_body_size=100 * 1024 * 1024. The page calls that 100 MiB. One path on that router, /uploads/small, declares max_body_size=10 * 1024 * 1024. The page calls that 10 MiB.

The page then states which route uses which number. POST /items uses the app limit of 1 MiB. POST /uploads/ uses the router limit of 100 MiB. POST /uploads/small has its own limit of 10 MiB. Those three sentences are the whole mapping. They are not a suggestion that 1, 10, and 100 are recommended production values. They are the values in the example, and the page uses them to show that a path can sit under a router that sits under an app, with a different integer at each level.

A path operation can declare a smaller limit than its router, which is what /uploads/small does relative to the 100 MiB router. The same section says a path operation can always declare a smaller or larger limit of its own. Larger is allowed. The example happens to go downward, from 100 MiB to 10 MiB. The rule on the page is not “paths may only tighten.” The rule is that the path’s own declaration wins, in either direction, over the router or app that contains it.

What counts toward that one limit

The page is explicit about the unit being limited. The limit applies to the whole request body. If you upload two files in the same request, both files count. Any form fields count. The bytes used to encode the multipart form count. All of those go toward that one limit, not toward a per-file budget. A reader who treats max_body_size as “maximum size of one file” is reading a different feature. The page does not say that.

The URL and the request headers are outside the body. They do not count toward max_body_size. A long query string, or a large set of headers, is not what this parameter measures. The page does not give a separate limit for those. It only places them outside this one.

FastAPI counts the bytes it reads. That sentence matters for clients that do not send a Content-Length header and instead send the body in chunks. The page says the count still happens in that case. Absence of Content-Length is not a way around the limit, according to the page. The implementation detail the page gives is the read, not the header.

If a read exceeds the limit, FastAPI stops reading and returns an HTTP 413 Content Too Large response, if the response has not started yet. Two conditions sit in that sentence. The first is the stop: it does not keep reading past the limit. The second is conditional: the 413 is returned if the response has not started yet. The page does not describe, in this section, what the client sees if a response has already started. That case is left unstated here, so this article does not invent a status code for it.

A path operation can start before the total size is known

The page warns that if your path operation reads the body itself, it can start running before FastAPI knows the total size. The example it gives is streaming an upload to a temporary file. The instruction attached to that example is short: finish reading the upload before you publish the file. The page does not print a helper function for that ordering. It states the ordering. A handler that publishes, moves, or otherwise treats the temporary file as complete while the read is still in progress is outside the order the page states.

UploadFile gets its own sentence. With UploadFile, a file can move from memory to disk as it grows. Its contents still count toward the same limit. The spill to disk is not a second budget. A team that sees a file appear on disk and concludes that the body limit no longer applies is contradicted by that sentence. The page does not say when the spill happens, and it does not name a byte threshold for the move from memory to disk. Those details are not on the page, so they are not in this article.

Inheritance, the default of None, and the unlimited case

You can also pass max_body_size to include_router(). The included router uses that default unless it declares its own limit. A path operation can still declare its own limit on top of that. So the page describes more than one way to attach a number to a router: as an argument when the router is created, or as an argument when the router is included. If the router declares its own limit, that declaration is what the included router uses. The include_router() value is the default for a router that did not declare one.

If you leave max_body_size at its default of None, it inherits the limit from the router or app that contains it. Mounted apps inherit the parent app’s limit in the same way. Inheritance is the behavior of None. It is not a separate opt-in.

The sentence that follows is the one a deployment has to read before treating an upgrade as a cap. If you do not set a limit anywhere, FastAPI leaves the body size unlimited. The page states that as the unset case. Use a positive integer for the number of bytes, or 0 to allow only an empty body. Those are the two kinds of set values the page names. A positive integer is a byte count. Zero is not “a small body.” Zero allows only an empty body.

An app that upgrades to 0.164.0 and does not pass max_body_size anywhere is, on the page’s own terms, still in the unlimited case. The morning post says you can now set a maximum, and it says to upgrade to 0.164.0. It does not say the upgrade inserts a default ceiling. The page says the opposite of a silent ceiling: unset means unlimited. The new capability and the default are different facts. A rollout note that says “we upgraded, so bodies are capped” would be adding a claim neither source makes.

That reading is the useful one for a service that already accepts uploads. The morning post is permission to set an integer, tied to a version. The page is the statement that the integer is optional, and that omitting it leaves the old unlimited behavior in place. A team that wants the 1 MiB JSON routes and the 100 MiB upload routes from the example has to write those integers. The example does not become the framework default by being printed.

Zero is easy to misread as “disable uploads” in a looser sense. The page is tighter. Zero allows only an empty body. A JSON object, a form field, and a file are all bodies that are not empty. A route that must accept any of those cannot use 0 and still do that job. A route that must reject every non-empty body is the case the page describes for 0.

Middleware reads the app limit first

The page has a separate note for middleware that reads the body before FastAPI selects a path operation. In that case, the app’s limit applies to that read. The page applies this to the example above: middleware that calls await request.body() would reject a 2 MiB upload before it reaches the router that allows 100 MiB. The 2 MiB figure is the page’s figure. It sits above the app’s 1 MiB example limit, and below the router’s 100 MiB example limit. The rejection happens at the app ceiling, because the middleware read happens before path selection. The router limit never gets a chance to allow the upload.

That is a ordering fact, not a bug report. The page states it as the consequence of reading the body in middleware. If the middleware then passes the request to a mounted app, the mounted app’s limit also applies to the bytes already read. Two ceilings can both apply to the same already-read bytes: the app limit on the middleware read, and the mounted app’s limit on those same bytes.

The page’s own remedy is also specific. If your middleware needs to read those uploads, set the app’s limit large enough for them, and set smaller limits on the path operations that need them. The large number moves to the app, because that is the number the early read sees. The tight numbers move to the path operations, because those are selected later. Reversing that, a tight app limit and a loose router limit, is exactly the shape the 2 MiB example rejects.

A service that logs request bodies, or that hashes them, or that copies them for a later check, is in this case if that work calls request.body() before the path operation is selected. The page does not inventory logging libraries. It names the call. If that call is in middleware, the app integer is the one that governs the read.

form_limits is a second configuration, not a rename

The afternoon post names form_limits and the three keys. The page puts those keys in a configuration object, and it says each setting inherits independently. You can override just the limits you need, on the app, on a router, in include_router(), or on a single path operation. Independent inheritance means a path that sets one key does not have to restate the other two. The keys are not a single bundled integer.

The page’s example sets form_limits={"max_fields": 5} on the app. A second path, /documents, sets form_limits={"max_part_size": 2 * 1024 * 1024}. The page does not reprint max_fields on that second path. Given the independent-inheritance sentence, the second path overrides the part size and leaves the other settings to inherit. This article does not add a fourth key, and it does not claim the example changes the defaults of the keys it does not mention.

The defaults are stated in prose, not only in the example. max_fields sets the maximum number of text fields. The default is 1,000. max_files sets the maximum number of files in a multipart form. The default is 1,000. max_part_size sets the maximum size in bytes of each text field. The default is 1 MiB. Those defaults are not None. Unlike max_body_size, which the page says is unlimited when unset, the form parser limits have numeric defaults on the page. A team that never passes form_limits is not in an unlimited-fields case. It is in the 1,000 / 1,000 / 1 MiB case the page writes down.

max_part_size is the size of each text field, not the size of each uploaded file. The page says so by defining it as the maximum size in bytes of each text field. File contents are called out in a later sentence: use max_body_size to bound the whole request, including uploaded file contents. A reader who sets max_part_size to 1 MiB and expects that number to cap a file upload is using the wrong parameter for that job. The file cap the page describes is the body limit, and it counts the whole body, including every file in the request.

For URL-encoded forms, the page says Starlette counts the encoded name and value together. That is a counting rule for max_part_size on that form type, not a second parameter. The encoded name is part of the count, not only the value a user typed. The page does not give a worked example with a long field name. It states the rule. A field whose name is long consumes part of the same byte budget as its value, on a URL-encoded form, according to that sentence.

FastAPI passes these settings to Starlette when it parses a request for a Form, File, or UploadFile parameter, including parameters in dependencies. The trigger for the parser limits is the presence of those parameters, including when they are declared on a dependency rather than directly on the path function. Exceeding a parser limit returns HTTP 400. That status is different from the HTTP 413 the body-size section names. The page assigns 400 to the parser limit and 413 to the oversize read of the body. Collapsing both failures into one code would contradict the page.

If you parse a form yourself, the page says to pass your limits to the first request.form() call. Starlette caches the parsed form on that request. The first call is the one that has to carry the limits, because a later call sees the cached parse. The page does not say that a second call with different limits recomputes the form. It says the parsed form is cached on that request. A handler that calls request.form() once with no limits, and later wishes it had passed max_fields, is past the call the page identifies as the one that counts.

Two failures, two parameters

A request can trip the body limit, the parser limits, or neither. The page keeps them separate on purpose. max_body_size bounds the whole request, including uploaded file contents, and an oversize read returns 413 if the response has not started. The form limits bound field count, file count, and per-text-field size, and exceeding a parser limit returns 400. A multipart request with two large files can stay under 1,000 files and still exceed a 1 MiB body limit. A request with 1,001 text fields can exceed max_fields even if the total body is small. Those two outcomes follow from the definitions on the page. They are not extra thresholds.

The morning post did not mention form_limits. The afternoon post did not mention max_body_size. The page documents both, and it tells you to use max_body_size when you want the whole request bounded, including file contents. A deployment that sets only form_limits has set the parser ceilings, including their defaults if some keys are omitted, and has not set a body ceiling. A deployment that sets only max_body_size has set a byte ceiling on the body and has left the parser defaults at 1,000 fields, 1,000 files, and 1 MiB per text field, unless it also passes form_limits.

The independent inheritance rule is what makes a partial override safe to describe. Setting max_fields to 5 on the app, as the example does, does not by itself change the page’s stated default for max_files or max_part_size, because each setting inherits independently and you override just the limits you need. The example relies on that. This article relies on the same sentence and does not invent a reset of the unset keys.

The 14 November note is a third ceiling, dated earlier

Three days before the news window that contains the 18 November posts, the same account posted a different limit. That note is timestamped 2026-11-14T17:01:16.000Z. It is not an 18 November announcement, and it should not be folded into the pair above as if it shipped the same afternoon. It says that in FastAPI 0.163.0 you can set max_concurrency in dependencies, for example to protect connection pools and help avoid deadlocks under high load. The post points at the advanced dependencies page, at the section on limiting dependency concurrency. That page was opened for this article. The post is the 14 November note. The section is Limit dependency concurrency.

The section says you might want to limit how many requests can use a dependency at the same time. The example is a database with a limited number of connections. New requests can wait before creating a session, until another request finishes using its session. The mechanism is max_concurrency on Depends(). The documented alias is SessionDep = Annotated[Session, Depends(get_session, max_concurrency=5)]. With that alias, up to five requests can have a database session open through this dependency at the same time. If another request needs a session, it waits until one of those sessions is closed. While waiting, it does not occupy a worker thread, so those threads stay available to run other code.

The value must be a positive integer. The default is None, which means FastAPI does not limit how many times the dependency can run at the same time. As with max_body_size, an upgrade to the version named in the post does not, on the page’s terms, install a numeric cap by itself. The default is no limit. The integer 5 in the example is the example, not a framework-wide pool size. The page says to choose a limit that fits the number of database connections available to these sessions. If other parts of the application also use those connections, leave room for them too. FastAPI does not know the size of your database connection pool. A copied 5 that ignores the pool, and ignores other users of the same connections, is not what that paragraph asks for.

Sharing is about object identity, not about the function name. All the routes that use the same SessionDep alias share the limit of five, because they reuse the same Depends() object. If you write a new Depends(get_session, max_concurrency=5) for each route, each one has its own limit of five. The page says this is true even though they all use the same get_session function. Five routes written that way are not a shared cap of five. They are five separate caps of five. A reader who counts functions instead of Depends() objects will overstate how tight the limit is.

Reusing the same SessionDep in another application also shares the limit, as long as both applications run in the same event loop. The page includes mounted applications in that statement. If two applications use this SessionDep for the same database pool, together they can have up to five sessions open through this dependency. If the applications use separate pools and need independent limits, the page says to create a separate Depends() object for each application. Sharing is the default consequence of reusing the object. Independence is a new object, not a flag on the old one.

In the example, get_session uses yield. The session counts toward the limit until the exit code finishes closing it. The dependency’s scope determines when that exit code runs. With scope="request", the default, it runs after the response is sent. With scope="function", it runs after the path operation function finishes, before sending the response. A dependency without yield counts toward the limit only until the function finishes. If you use a dependency with yield in a WebSocket handler, it counts toward the limit until the handler exits and the dependency’s exit code finishes. The hold time is not “until the path function returns” in every case. For the default request scope with yield, the page says the session still counts after the function returns, until the response is sent and the exit code finishes closing it.

Reusing a cached dependency value does not count again toward the limit. If different declarations share that value, only the declaration that calls the dependency counts toward its limit. A second use of a cached session is not a second slot. That sentence is about the cache, not about raising the integer.

Each worker process has its own limit. The page’s example arithmetic is direct: two worker processes with this dependency could have up to ten sessions open between them. The limits are also separate for each event loop. Applications running in different event loops do not share a limit, even if they reuse the same Depends() object. A process count and an event-loop count are both multipliers the page states. A single integer in one module is not a cluster-wide cap.

FastAPI runs a dependency’s sub-dependencies before applying that dependency’s limit. To limit database sessions, the page says to put max_concurrency on Depends(get_session, ...), where the session is created. Putting the integer on a dependency that merely calls another dependency does not, on that sentence, apply the limit at the inner call. The limit belongs on the declaration that creates the session.

The page also says a request can get stuck if it needs another session while still holding one that will only be closed at the end of the request. The defensive lines that belong with that impact are the ones the page gives as the remedy: if your requests need several resources, acquire them in the same order. FastAPI applies each limit separately. It does not reserve all the resources a request will need in advance. The 14 November post’s own example of the feature is protecting connection pools and helping avoid deadlocks under high load. The page’s contribution is the waiting behavior, the per-object sharing rule, the per-process arithmetic, and that ordering remedy. A pool limit does not parse forms, and it does not count body bytes.

Three ceilings, three defaults

Read together, the three notes describe three different ceilings, and the pages give them three different defaults.

The body ceiling is max_body_size, tied by the 18 November morning post to FastAPI 0.164.0. It counts bytes read from the whole body, including every file, every form field, and the multipart encoding bytes. Headers and the URL are outside it. Unset, the page says the body size is unlimited. Set to a positive integer, it is a byte count. Set to 0, it allows only an empty body. An oversize read returns HTTP 413 if the response has not started yet. Middleware that reads the body early is governed by the app integer, not by a looser router integer selected later.

The form ceiling is form_limits, tied by the 18 November afternoon post to FastAPI 0.165.0. It has three keys that inherit independently. The defaults on the page are 1,000 text fields, 1,000 files in a multipart form, and 1 MiB per text field. For URL-encoded forms, Starlette counts the encoded name and value together toward max_part_size. Exceeding a parser limit returns HTTP 400. File contents are still the body limit’s job.

The dependency ceiling is max_concurrency, tied by the 14 November post to FastAPI 0.163.0. It limits how many times one Depends() object can run at the same time. The default is None, meaning no limit. The example integer is 5, and the page says that integer should fit the connections available, with room left for other users of those connections. Separate Depends() objects do not share a limit. Separate worker processes do not share a limit. Separate event loops do not share a limit. Waiting does not occupy a worker thread.

None of these replaces the others. A service can have an unlimited body, the default form parser numbers, and no dependency concurrency limit, all at once, if it upgrades and sets nothing. A service can cap bodies and leave dependency concurrency unset. A service can share one session limit across mounted apps in the same event loop and still have no max_body_size. The posts tell you the versions in which the settings exist. The pages tell you that existence is not the same as a number already chosen.

What a deployment can do with the texts in hand

The morning post’s instruction is to upgrade to FastAPI 0.164.0 and check the docs. The afternoon post’s instruction is that 0.165.0 is the version for form_limits, and to check the same docs. The skill line on both posts, and on the limits page, is uvx library-skills, run from the project directory, for the official skill that matches the installed version. This article does not add a pin file, a lockfile command, or a migration script. None of the sources print one.

If the running app has no max_body_size on the app, on any router, on include_router(), or on any path, the page says the body size is unlimited. Setting a ceiling means writing a positive integer at the level that should own it. If middleware calls request.body() before path selection, that integer has to be large enough for the uploads the middleware reads, and the tighter integers belong on the path operations. The page’s 2 MiB example is the illustration: a 1 MiB app limit rejects that upload before a 100 MiB router can accept it.

If the form defaults of 1,000 fields and 1,000 files are wider than the product needs, the page says you can override just the keys you need. The example overrides max_fields to 5 on the app and max_part_size to 2 MiB on one path. It does not require a full restatement. If you call request.form() yourself, the limits have to be on the first call, because Starlette caches the parsed form on that request.

If the goal is the connection-pool case from the 14 November post, the integer goes on the Depends() object that creates the session, not on a wrapper that calls it. Reuse that same object where the cap should be shared, including across mounted apps in the same event loop. Write a new object where the cap should be independent. Multiply by worker processes the way the page does: two processes with a limit of five can mean ten sessions. Leave room for other code that uses the same connections, because the page says FastAPI does not know the pool size. If a request needs several resources, acquire them in the same order. The page says each limit is applied separately, and that FastAPI does not reserve every resource the request will need before it starts.

What this article does not claim

It does not name a FastAPI version before 0.163.0, 0.164.0, or 0.165.0. The posts do not name one, and the limits page extract does not name one. It does not assign a CVE, a score, or a vendor advisory to these notes. The notes are feature posts. The pages are parameter docs. It does not report a timing, a throughput number, or a memory figure for the read, the spill to disk, or the wait on a dependency. Those measurements are not in the sources.

It does not claim that installing 0.165.0 removes the need to read the 0.164.0 post. The afternoon post does not say it supersedes the morning post. Both point at one page that documents both configurations. It does not claim that the 14 November concurrency limit counts request bytes, or that a body limit waits for a database session. The parameters are different, the defaults are different, and the status behavior the pages describe is different.

The two 18 November posts are the week’s notes. They are short on purpose. The page they share is where the byte counts, the field defaults, the 413, and the 400 are written. The 14 November post is a third ceiling from the same account, useful when the thing you are trying to bound is how many times a dependency runs, and not useful as a substitute for either of the later settings.

Spread The Article

Share this guide

Send this article to your network or keep a copy of the direct link.

X Facebook LinkedIn Reddit Telegram

Discussion

Leave a comment

No comments yet

Be the first to start the conversation.