Add typed request/response models and streaming toggle to the API - #2
Open
stanleyu911 wants to merge 1 commit into
Open
Add typed request/response models and streaming toggle to the API#2stanleyu911 wants to merge 1 commit into
stanleyu911 wants to merge 1 commit into
Conversation
The completion/search/history endpoints took a raw Request and parsed
the body manually, and read sid/ctx-api-token straight from query
params/headers without declaring them - so the auto-generated
OpenAPI schema (and Swagger UI's "Try it out") showed empty {}
request bodies and no documented parameters.
- Replace manual request.json() parsing with Pydantic request models
(CompletionRequest, SearchRequest).
- Declare sid/ctx-api-token as FastAPI Query/Header params so they
show up in the OpenAPI schema. ctx-api-token stays optional at the
framework level so a missing token still returns the existing 401,
rather than FastAPI's own 422 validation error pre-empting it.
- Add a stream query param (default true, preserving existing
behavior) to all three endpoints. stream=false buffers the same
underlying generator server-side and returns one consolidated JSON
response (CompletionResponse/SearchResponse/HistoryResponse) with a
declared schema - useful for Swagger's "Try it out" and simple
non-streaming clients, since Swagger UI has no special handling for
text/event-stream and otherwise just dumps the raw SSE lines as text.
- Add docs/api-usage-examples.md with reusable curl examples for all
three endpoints, streaming and non-streaming.
- Add pydantic to requirements.txt explicitly, since our code now
imports it directly rather than relying on it only as fastapi's
transitive dependency.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012uwq94g5qTJmrQyRnib67P
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/completion,/search,/historyparsed the request body manually and readsid/ctx-api-tokenstraight from query params/headers, so the OpenAPI schema (and Swagger's "Try it out") showed empty request bodies and no documented parameters.sid/ctx-api-tokenasQuery/Headerparams, now fully documented in/openapi.json.ctx-api-tokenstays optional at the framework level so a missing token still returns401rather than a generic422.streamquery param (defaulttrue, existing behavior unchanged) to all three endpoints;stream=falsereturns one consolidated JSON response instead of SSE - useful for Swagger and simple non-streaming clients.docs/api-usage-examples.mdwith reusable curl examples.pydantictorequirements.txtexplicitly (already an implicit dependency offastapi, now used directly).Test plan
/openapi.jsonand Swagger UI render correctly for all three endpoints in both modes.401/422behavior unchanged.stream=falsemodes.