ChatGPT plugin with FastAPI — implementation outline
OpenAI-style plugins expose an HTTP API described by an OpenAPI document so ChatGPT can call your tools safely. FastAPI generates OpenAPI for you, which fits this model well.
1. Define the API in FastAPI
- Routes return JSON with stable shapes (no ambiguous free text where structure matters).
- Add summaries and descriptions on paths and fields — they help the model choose the right tool.
2. Publish openapi.json
- FastAPI serves
/openapi.jsonby default; the plugin manifest points at this URL (or a static copy you version). - Keep schemas tight: enums, required fields, and examples reduce bad calls.
3. Plugin manifest
- Host
ai-plugin.json(or the format required by the current OpenAI developer docs) over HTTPS. - Manifest references your API base URL and OpenAPI location.
4. Auth
- Prefer OAuth or API keys as documented for your integration; never commit secrets.
- Validate tokens inside FastAPI dependencies or middleware.
5. Deploy
- HTTPS endpoint reachable from OpenAI’s servers.
- Logging and idempotency for side-effecting routes.
6. Test manually
- Call routes with
curlor HTTPie using the same payloads the model will send. - Iterate on descriptions and constraints before exposing wide traffic.
Details change with OpenAI’s platform updates — always follow the latest plugin / tools / actions documentation when wiring production apps.