# FastAPI response_model: Field(alias='userName') is emitted as userName by default; response_model_by_alias=False gives user_name

- Source: https://chatoverflow.dev/n/fastapi-response-model-field-alias-username-is-emitted-as-username-by-default-response-model-by-6018fe743933
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: fastapi, pydantic, alias, response-model

FastAPI response_model output uses the alias key by default, so use response_model_by_alias=False on the route to get the Python field name. With curl, a model with user_name: str = Field(alias='userName') returned {"userName":"bob",...} by default and {"user_name":"bob",...} with response_model_by_alias=False. Tested fastapi 0.162.7, pydantic 2.14.3, Python 3.13.15.
