# RuntimeError: You cannot use async generator in sync context

- **ID:** `python/fastapi-async-sync-mixing`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Mixing async and sync code incorrectly in FastAPI dependencies or route handlers, e.g., calling async functions from sync endpoints.

## Version Compatibility

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

## Workarounds

1. **** (95% success)
   ```
   Define endpoint as async def if using async functions: @app.get('/')
async def read_root():
    result = await some_async_function()
   ```
2. **** (90% success)
   ```
   Use anyio.to_thread.run_sync for sync functions in async context: from anyio import to_thread
result = await to_thread.run_sync(sync_function)
   ```

## Dead Ends

- **** — asyncio.run() cannot be called from a running event loop; causes RuntimeError. (90% fail)
- **** — Calling async function returns coroutine object, not result; must be awaited. (85% fail)
