Use this skill for response shaping, status code control, and custom response behavior.
Workflow
- Default to typed return values for standard JSON responses.
- Use
Response(...)when headers/cookies/media/status must be controlled explicitly. - Use response DTO/serialization controls where domain objects need transformation.
- Ensure error responses are consistent with exception handlers.
Core Patterns
Typed Return
from litestar import get
@get("/ping") async def ping() -> dict[str, str]: return {"message": "pong"}
### Explicit Response
```python
from litestar import Response, get
@get("/created")
async def created() -> Response[dict[str, str]]:
return Response({"result": "ok"}, status_code=201)
Response Checklist
- Use precise return types for better schema generation.
- Set explicit status codes for non-default flows.
- Keep response envelope conventions consistent across the API.
- Coordinate response contracts with exception handling.