---
source: https://iinventedlight.com/library/notes/fastapi-websocket.md
title: "FastAPI WebSockets: accept a WebSocket endpoint"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (FastAPI docs); MIT (FastAPI); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: FastAPI docs, WebSockets; FastAPI, websockets.md. MIT (https://raw.githubusercontent.com/fastapi/fastapi/master/LICENSE). Copyright FastAPI contributors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-web: fastapi websocket"
tags: [fastapi, websocket, starlette, realtime, async]
client: Librarian
sources:
  - id: S1
    title: "WebSockets"
    publisher: FastAPI docs
    url: https://fastapi.tiangolo.com/advanced/websockets/
    accessed: 2026-11-18
    license: "MIT"
  - id: S2
    title: "websockets.md"
    publisher: FastAPI
    url: https://raw.githubusercontent.com/fastapi/fastapi/master/docs/en/docs/advanced/websockets.md
    accessed: 2026-11-18
    license: "MIT"
---
# FastAPI WebSockets: accept a WebSocket endpoint
**Answer:** You can use WebSockets with FastAPI. FastAPI provides the WebSocket class as a convenience, but it comes directly from Starlette. You can receive and send binary, text, and JSON data.

## Notes

 

## Reference list

- `WebSockets` can be used with FastAPI.
- `WebSocket` is provided as a convenience and comes from Starlette.
- `JSON` is one of the data forms you can send or receive.

## See also

- [fastapi-dependencies](https://iinventedlight.com/library/notes/fastapi-dependencies/)
- [fastapi-async-await](https://iinventedlight.com/library/notes/fastapi-async-await/)
- [fastapi-error-handling](https://iinventedlight.com/library/notes/fastapi-error-handling/)

## Claims

- id: C1
  claim: You can use WebSockets with FastAPI.
  source: S1
  evidence: "You can use WebSockets with FastAPI"

- id: C2
  claim: The WebSocket helper comes directly from Starlette.
  source: S2
  evidence: "But it comes directly from Starlette."

- id: C3
  claim: You can receive and send binary, text, and JSON data.
  source: S2
  evidence: "You can receive and send binary, text, and JSON data."

## Sources

- [S1] WebSockets. FastAPI docs. https://fastapi.tiangolo.com/advanced/websockets/ . License: MIT. Accessed 2026-11-18.

- [S2] websockets.md. FastAPI. https://raw.githubusercontent.com/fastapi/fastapi/master/docs/en/docs/advanced/websockets.md . License: MIT. Accessed 2026-11-18.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: FastAPI docs, WebSockets; FastAPI, websockets.md. MIT (https://raw.githubusercontent.com/fastapi/fastapi/master/LICENSE). Copyright FastAPI contributors. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
