# fastapi.exceptions.FastAPIError: Invalid type for query parameter 'age': <class 'str'> is not a valid type for a query parameter.

- **ID:** `python/fastapi-query-param-type-error`
- **Domain:** python
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

FastAPI query parameters must have a type that can be parsed from strings; using unsupported types like str for a parameter that expects int causes this error.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **Use proper type hints like int, float, or str** (95% success)
   ```
   from fastapi import FastAPI, Query
app = FastAPI()
@app.get('/items')
def read_items(age: int = Query(...)):
    return {'age': age}
   ```
2. **Use Pydantic models for complex types** (90% success)
   ```
   from pydantic import BaseModel
class Item(BaseModel):
    age: int

@app.get('/items')
def read_items(item: Item = Query(...)):
    return item
   ```

## Dead Ends

- **Using a custom class without type conversion** — FastAPI cannot automatically convert custom types. (90% fail)
- **Setting default value as string but type hint as int** — Mismatch between default and type hint causes validation issues. (80% fail)
