docs: add Anything API product page#761
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (2)
WalkthroughAdded a new documentation page docs/src/product/anything-api.mdx and registered it in docs/src/docs.json under navigation → Products → Products. The page documents the POST /api/anything/start endpoint that returns an SSE Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Documents the /api/anything/start SSE endpoint including request format, all SSE event types, code examples in Python and TypeScript, and how to re-run created functions via CLI or SDK.
0bd5e08 to
871ad46
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
docs/src/product/anything-api.mdx (1)
120-135: Add explicit HTTP error handling before SSE parsing.Call
raise_for_status()before iterating streamed lines to immediately catch authentication failures, rate limits, or server errors (4xx, 5xx responses). This prevents silent processing of error responses. Also set a timeout for robustness.Proposed doc snippet update
response = requests.post( "https://anything.notte.cc/api/anything/start", headers={ "Authorization": f"Bearer {NOTTE_API_KEY}", "Content-Type": "application/json", }, json={"query": "fetch the top 3 hacker news posts"}, stream=True, + timeout=120, ) +response.raise_for_status() for line in response.iter_lines(): if line:🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/src/product/anything-api.mdx` around lines 120 - 135, The code currently begins streaming with response.iter_lines() without checking HTTP status; update the requests.post call (response) to call response.raise_for_status() immediately after the post and before iterating, and add a timeout argument to requests.post to avoid hanging; this ensures authentication/4xx/5xx errors are raised instead of being silently parsed in the SSE loop that uses response.iter_lines().
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docs/src/product/anything-api.mdx`:
- Around line 149-168: Check response.ok and that response.body is not null
before using response.body!; if !response.ok log/throw and return, and if
response.body is null handle as an error case. Replace direct use of
response.body! with guarded creation of const reader = response.body.getReader()
only after these checks, and ensure the stream loop inspects event.type for all
terminal events ("done", "error", "timeout", "cancelled") so each case closes
the reader/returns and logs relevant fields (e.g., event.function_id,
event.total_cost_usd) rather than only handling "done".
---
Nitpick comments:
In `@docs/src/product/anything-api.mdx`:
- Around line 120-135: The code currently begins streaming with
response.iter_lines() without checking HTTP status; update the requests.post
call (response) to call response.raise_for_status() immediately after the post
and before iterating, and add a timeout argument to requests.post to avoid
hanging; this ensures authentication/4xx/5xx errors are raised instead of being
silently parsed in the SSE loop that uses response.iter_lines().
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 381f587d-a4e7-439e-a9bf-b73fe96ff6b4
📒 Files selected for processing (2)
docs/src/docs.jsondocs/src/product/anything-api.mdx
There was a problem hiding this comment.
♻️ Duplicate comments (1)
docs/src/product/anything-api.mdx (1)
149-168:⚠️ Potential issue | 🟠 MajorGuard
response.okandresponse.body, and handle all terminal events.The non-null assertion
response.body!on line 149 is unsafe. Per Fetch API best practices, checkresponse.okbefore consuming the body (fetch doesn't reject on HTTP errors). Additionally,Response.bodycan be null for opaque responses and certain status codes. The example only handles thedoneevent (line 162) but ignoreserror,timeout, andcancelledterminal events documented on lines 72-74, which means the stream may not terminate gracefully in error scenarios.🔒 Proposed doc fix
const response = await fetch("https://anything.notte.cc/api/anything/start", { method: "POST", headers: { Authorization: `Bearer ${NOTTE_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ query: "fetch the top 3 hacker news posts" }), }); -const reader = response.body!.getReader(); +if (!response.ok) { + throw new Error(`HTTP ${response.status}: ${response.statusText}`); +} +if (!response.body) { + throw new Error("Response body is not available"); +} + +const reader = response.body.getReader(); const decoder = new TextDecoder(); +const terminalEvents = new Set(["done", "error", "timeout", "cancelled"]); while (true) { const { done, value } = await reader.read(); if (done) break; const text = decoder.decode(value, { stream: true }); for (const line of text.split("\n")) { if (line.startsWith("data: ")) { const event = JSON.parse(line.slice(6)); console.log(event.type, event); if (event.type === "done") { console.log("Function ID:", event.function_id); console.log("Cost:", event.total_cost_usd); } + + if (terminalEvents.has(event.type)) { + await reader.cancel(); + return; + } } } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/src/product/anything-api.mdx` around lines 149 - 168, Check response.ok and ensure response.body exists before calling response.body.getReader(); if response.ok is false or response.body is null, throw or handle the error instead of using the non-null assertion on response.body!. Replace the single-case handling of event.type === "done" in the reader loop with a switch or if/else that also handles "error", "timeout", and "cancelled" terminal events (logging or throwing as appropriate) and ensure the reader is properly closed when any terminal event occurs; keep existing logging for event.function_id and event.total_cost_usd when event.type === "done".
🧹 Nitpick comments (1)
docs/src/product/anything-api.mdx (1)
117-135: Consider adding response status check.The example should validate the HTTP response before streaming to align with best practices and prevent confusion if the request fails.
📝 Suggested improvement
response = requests.post( "https://anything.notte.cc/api/anything/start", headers={ "Authorization": f"Bearer {NOTTE_API_KEY}", "Content-Type": "application/json", }, json={"query": "fetch the top 3 hacker news posts"}, stream=True, ) +response.raise_for_status() for line in response.iter_lines():🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/src/product/anything-api.mdx` around lines 117 - 135, Add an HTTP response validation step after the requests.post call (response = requests.post(...)) before iterating response.iter_lines(): check response.status_code or call response.raise_for_status() (or use if not response.ok: log/print response.status_code and response.text and return/raise) so the example fails-fast and avoids streaming error HTML/JSON when NOTTE_API_KEY is invalid or the request fails.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@docs/src/product/anything-api.mdx`:
- Around line 149-168: Check response.ok and ensure response.body exists before
calling response.body.getReader(); if response.ok is false or response.body is
null, throw or handle the error instead of using the non-null assertion on
response.body!. Replace the single-case handling of event.type === "done" in the
reader loop with a switch or if/else that also handles "error", "timeout", and
"cancelled" terminal events (logging or throwing as appropriate) and ensure the
reader is properly closed when any terminal event occurs; keep existing logging
for event.function_id and event.total_cost_usd when event.type === "done".
---
Nitpick comments:
In `@docs/src/product/anything-api.mdx`:
- Around line 117-135: Add an HTTP response validation step after the
requests.post call (response = requests.post(...)) before iterating
response.iter_lines(): check response.status_code or call
response.raise_for_status() (or use if not response.ok: log/print
response.status_code and response.text and return/raise) so the example
fails-fast and avoids streaming error HTML/JSON when NOTTE_API_KEY is invalid or
the request fails.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: ec1f140e-3cae-4774-8202-46016293b97b
📒 Files selected for processing (2)
docs/src/docs.jsondocs/src/product/anything-api.mdx
✅ Files skipped from review due to trivial changes (1)
- docs/src/docs.json
- Move Python code blocks to sniptest testers (code-snippets rule) - Add response.raise_for_status() to Python SSE example - Fix TypeScript: guard response.ok/response.body, buffer chunks, handle all terminal events (done/error/timeout/cancelled)
There was a problem hiding this comment.
🧹 Nitpick comments (1)
docs/src/testers/anything-api/consume_sse.py (1)
9-17: Add an explicit timeout to the streaming POST request.Line 9 currently issues a network call without a timeout, which can hang indefinitely on connect/read stalls.
Proposed patch
response = requests.post( "https://anything.notte.cc/api/anything/start", @@ json={"query": "fetch the top 3 hacker news posts"}, stream=True, + timeout=(10, 300), )🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/src/testers/anything-api/consume_sse.py` around lines 9 - 17, The streaming POST currently calls requests.post without a timeout which can hang; update the requests.post invocation (the call that assigns to response) to include an explicit timeout parameter (e.g., timeout=(connect_timeout, read_timeout) or a single timeout value) so connect and read stalls are bounded, and ensure this change applies to the streaming request (stream=True) used in consume_sse.py for request verification.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@docs/src/testers/anything-api/consume_sse.py`:
- Around line 9-17: The streaming POST currently calls requests.post without a
timeout which can hang; update the requests.post invocation (the call that
assigns to response) to include an explicit timeout parameter (e.g.,
timeout=(connect_timeout, read_timeout) or a single timeout value) so connect
and read stalls are bounded, and ensure this change applies to the streaming
request (stream=True) used in consume_sse.py for request verification.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 6920b359-5528-4869-9403-144cf7be2ffd
📒 Files selected for processing (5)
docs/src/product/anything-api.mdxdocs/src/snippets/anything-api/consume_sse.mdxdocs/src/snippets/anything-api/run_function.mdxdocs/src/testers/anything-api/consume_sse.pydocs/src/testers/anything-api/run_function.py
✅ Files skipped from review due to trivial changes (3)
- docs/src/snippets/anything-api/run_function.mdx
- docs/src/testers/anything-api/run_function.py
- docs/src/snippets/anything-api/consume_sse.mdx
10s connect timeout, 300s read timeout to bound stalls on the streaming request.
|
@greptile review |
Summary
/api/anything/startSSE endpoint: request format, all event types, terminal eventsSummary by CodeRabbit
Greptile Summary
This PR adds a new Anything API documentation page under Products, covering the
/api/anything/startSSE endpoint with event types, error handling, pricing, and code examples in curl, Python, and TypeScript. All issues flagged in the previous review round (inline Python blocks, missingraise_for_status, and TypeScript chunk-boundary splits) have been fully addressed — Python examples now use imported snippets, the SSE snippet callsraise_for_status(), and the TypeScript reader uses proper buffer accumulation.Confidence Score: 5/5
Safe to merge — documentation-only change with no logic regressions and all prior review concerns resolved.
No P0 or P1 findings remain. All three previously flagged issues have been corrected in this revision, and the new code follows the project's sniptest conventions correctly.
No files require special attention.
Important Files Changed
product/anything-apito the navigation sidebar — clean, no issues.raise_for_status()and streaming with correct SSE line parsing.@sniptest typecheck_only=true; correctly callsraise_for_status()before streaming.typecheck_only=true; example function ID is clearly illustrative.Reviews (2): Last reviewed commit: "fix: add timeout to Python SSE example" | Re-trigger Greptile