Skip to content

docs: add Anything API product page#761

Closed
kalil-notte wants to merge 3 commits intonottelabs:mainfrom
kalil-notte:docs/anything-api-sdk
Closed

docs: add Anything API product page#761
kalil-notte wants to merge 3 commits intonottelabs:mainfrom
kalil-notte:docs/anything-api-sdk

Conversation

@kalil-notte
Copy link
Copy Markdown
Collaborator

@kalil-notte kalil-notte commented Apr 13, 2026

Summary

  • Adds a new docs page for the Anything API under Products
  • Documents the /api/anything/start SSE endpoint: request format, all event types, terminal events
  • Includes code examples for consuming the stream in Python and TypeScript
  • Shows how to re-run created functions via CLI and SDK
  • Adds link to https://anything.notte.cc

Summary by CodeRabbit

  • Documentation
    • Added Anything API docs and updated site navigation to include the new page.
    • Documents single-call SSE workflow, event types, terminal events, auth, HTTP error handling, and billing (done.total_cost_usd).
    • Includes curl, TypeScript, and Python quick-starts, plus runnable snippets and tester scripts demonstrating streaming consumption and re-running functions.

Greptile Summary

This PR adds a new Anything API documentation page under Products, covering the /api/anything/start SSE 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, missing raise_for_status, and TypeScript chunk-boundary splits) have been fully addressed — Python examples now use imported snippets, the SSE snippet calls raise_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

Filename Overview
docs/src/docs.json Adds product/anything-api to the navigation sidebar — clean, no issues.
docs/src/product/anything-api.mdx New docs page for the Anything API; Python examples correctly use imported snippets, TypeScript SSE reader uses proper buffer accumulation, HTTP error check present in snippet — all previously flagged issues addressed.
docs/src/snippets/anything-api/consume_sse.mdx Auto-generated snippet from tester; includes raise_for_status() and streaming with correct SSE line parsing.
docs/src/snippets/anything-api/run_function.mdx Auto-generated snippet for re-running a Notte Function via SDK — clean.
docs/src/testers/anything-api/consume_sse.py Source tester with @sniptest typecheck_only=true; correctly calls raise_for_status() before streaming.
docs/src/testers/anything-api/run_function.py Source tester for SDK function re-run with typecheck_only=true; example function ID is clearly illustrative.

Reviews (2): Last reviewed commit: "fix: add timeout to Python SSE example" | Re-trigger Greptile

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 555fe1e4-8673-431c-a9d9-445856838cb4

📥 Commits

Reviewing files that changed from the base of the PR and between dd39caf and dcecfaa.

📒 Files selected for processing (2)
  • docs/src/snippets/anything-api/consume_sse.mdx
  • docs/src/testers/anything-api/consume_sse.py
✅ Files skipped from review due to trivial changes (2)
  • docs/src/snippets/anything-api/consume_sse.mdx
  • docs/src/testers/anything-api/consume_sse.py

Walkthrough

Added 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 text/event-stream where lines begin with data: and contain JSON events (agent lifecycle, streaming outputs, tool execution, function creation, terminal outcomes done/error/timeout/cancelled). Also added example snippets and tester scripts under docs/src/snippets/anything-api/* and docs/src/testers/anything-api/* (Python consume_sse and run_function), and included guidance on headers, error codes, re-running functions via function_id, and billing via done.total_cost_usd.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a new Anything API product documentation page with supporting examples and navigation updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.
@kalil-notte kalil-notte force-pushed the docs/anything-api-sdk branch from 0bd5e08 to 871ad46 Compare April 13, 2026 12:12
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 631b524 and 0bd5e08.

📒 Files selected for processing (2)
  • docs/src/docs.json
  • docs/src/product/anything-api.mdx

Comment thread docs/src/product/anything-api.mdx Outdated
Comment thread docs/src/product/anything-api.mdx Outdated
Comment thread docs/src/product/anything-api.mdx Outdated
Comment thread docs/src/product/anything-api.mdx Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
docs/src/product/anything-api.mdx (1)

149-168: ⚠️ Potential issue | 🟠 Major

Guard response.ok and response.body, and handle all terminal events.

The non-null assertion response.body! on line 149 is unsafe. Per Fetch API best practices, check response.ok before consuming the body (fetch doesn't reject on HTTP errors). Additionally, Response.body can be null for opaque responses and certain status codes. The example only handles the done event (line 162) but ignores error, timeout, and cancelled terminal 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

📥 Commits

Reviewing files that changed from the base of the PR and between 0bd5e08 and 871ad46.

📒 Files selected for processing (2)
  • docs/src/docs.json
  • docs/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)
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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

📥 Commits

Reviewing files that changed from the base of the PR and between 871ad46 and dd39caf.

📒 Files selected for processing (5)
  • docs/src/product/anything-api.mdx
  • docs/src/snippets/anything-api/consume_sse.mdx
  • docs/src/snippets/anything-api/run_function.mdx
  • docs/src/testers/anything-api/consume_sse.py
  • docs/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.
@kalil-notte
Copy link
Copy Markdown
Collaborator Author

@greptile review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants