# SyntaxError: 'await' outside async function

- **ID:** `python/asyncio-await-outside-async-function`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The await keyword was used in a regular def function or at module top level. await is only valid inside async def bodies (or in top-level await when using IPython/Jupyter).

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |
| 3.10 | active | — | — |
| 3.11 | active | — | — |
| 3.12 | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   async def handler():
    data = await fetch()
    return data
   ```
2. **** (93% success)
   ```
   async def main():
    await fetch()
if __name__ == '__main__':
    asyncio.run(main())
   ```
3. **** (90% success)
   ```
   # IPython/Jupyter supports top-level await in cells
await fetch()
   ```

## Dead Ends

- **** — If the sync function is itself called from async code, this raises 'This event loop is already running'. (75% fail)
- **** — Coroutine objects have no result() method; raises AttributeError. (95% fail)
