FastAPI "orjson"/"ujson" not installed for the response class in CI
FastAPI can serialize responses with orjson or ujson, but those are optional extras. If your app sets default_response_class=ORJSONResponse without installing orjson, importing or serving fails in CI.
What this error means
App import or a request fails with "orjson must be installed to use ORJSONResponse" or "ujson must be installed to use UJSONResponse".
AssertionError: orjson must be installed to use ORJSONResponseCommon causes
The optional JSON extra is not installed in CI
orjson and ujson are not FastAPI runtime dependencies; using their response classes requires installing them explicitly.
A local machine had it while CI did not
orjson was present locally as a transitive dependency but never declared, so the fresh CI environment lacks it.
How to fix it
Declare and install the JSON library
Add orjson (or ujson) to your dependencies so the response class can import it on every runner.
python -m pip install orjson
# or install the FastAPI extra that bundles it
python -m pip install "fastapi[all]"Fall back to the default JSON response
If you do not need the faster serializer, drop the custom response class and use the built-in JSONResponse.
from fastapi import FastAPI
app = FastAPI() # default JSONResponse needs no extra depsHow to prevent it
- Declare orjson/ujson explicitly when you use their response classes.
- Pin optional extras in requirements so CI matches local.
- Do not rely on transitive presence of optional serializers.