Skip to main content
Use this recipe to start a CodeRabbit review from a script or an agent, wait for it, and read what it produced.

Before you start

  • You need an API key for a GitHub Cloud organization; requesting a review needs an agentic key. See Authentication for keys and Conventions for base URLs, pagination, errors, and rate limits.
  • The curl examples and the Python script read the key from CODERABBIT_API_KEY and the API host from CODERABBIT_API_HOST, the variables that Set up your shell sets for your region. The CLI examples use the coderabbit api command. Each step also names its tool on the hosted MCP server.
  • The examples use repository ID 123456789 and pull request 42.

1. Find the repository ID

Pull request operations take the repository’s numeric GitHub ID, not its name. List repositories returns the repositories where CodeRabbit is installed and you have read access on GitHub.
Take the id of the repository you want. It’s GitHub’s numeric repository ID, not the node_id. The list has no name filter, so to look up a repository by name, filter the response on full_name:
Trimmed response:
If the filter prints nothing, the repository isn’t on that page: keep following next_page_token as described in Pagination. To check a single ID, call Get a repository. MCP tools: list_repositories, get_repository.

2. Find the pull request

List pull requests returns open pull requests. Set state for closed or merged pull requests, and head_branch to find the pull request for a branch; add head_owner to tell forks apart.
Without author, the list holds only the pull requests opened by the GitHub account linked to the key’s owner (author=me). Set author=all for every author, or a GitHub login for one person.
The list comes from a live GitHub search, so it can change between pages. When coverage.complete is false, coverage.limitations says what the search couldn’t cover; narrow the filters and search again. To read one pull request, call Get a pull request with the repository ID and the pull request’s number. The id field in pull request responses is GitHub’s internal ID and doesn’t work in paths. include selects the sections to return: checks (the default), threads, both, or none. Review threads default to unresolved threads that CodeRabbit started. Set thread_author=all, thread_state=all, or thread_include_outdated=true to widen that.
Threads page separately from the rest of the response: pass threads.next_page_token as thread_page_token with the same filters. If the pull request’s head commit moves while you page, the API returns 409 head_changed; start again without the token. A thread’s replies_complete is false when the response holds only part of the replies. To read the whole discussion, call List all comments in a pull-request review thread with the thread’s id: it returns the root comment and every reply, and pages with its own page_token, separate from thread_page_token. The reviews section shows what GitHub reports. To find out whether CodeRabbit finished reviewing the current head, use the review status in step 4. MCP tools: list_pull_requests, get_pull_request, and list_pull_request_review_thread_comments. list_pull_requests and get_pull_request take GitHub URLs instead of a repository ID and pull request number. list_pull_request_review_thread_comments takes the repository ID, the pull request number, and the thread’s id, as the API does.

3. Request a review

Request a review asks CodeRabbit to review the pull request’s current head. The pull request must be open.
A 202 response means CodeRabbit accepted the request, not that the review finished. observed_head_sha is the pull request’s head when you sent the request. CodeRabbit handles the request like a new push to the pull request and reviews whatever the head is when the review starts. The API can’t review an older commit or cancel a review. MCP tool: request_pull_request_review. The connection needs the reviews:write scope; the review scope for local reviews doesn’t include it.

4. Follow the review status

Get review status returns the pull request’s current head and CodeRabbit’s latest review status for it. It’s the status that Triage shows, but it doesn’t depend on anyone using Triage: CodeRabbit records it as pull request events arrive.
Read the response with these rules:
  • The current head is reviewed when status is completed and target_commit_sha equals head_sha.
  • completed doesn’t tell you what CodeRabbit posted. Read the summary in step 5 and the review threads from step 2.
  • review: null means CodeRabbit has no status for the pull request’s current commit, for example because it hasn’t recorded the pull request yet or because the last status belongs to an older commit. It doesn’t prove that no review ran.
  • updated_at is when the status last changed, not when you read it.
Poll about once a minute; each call counts toward your rate limit. This loop waits until the current head is reviewed or the review fails:
MCP tool: get_pull_request_review.

5. Read the summary

Get the review summary returns CodeRabbit’s latest summary comment on the pull request, the comment that carries the walkthrough. summary.body_markdown holds its Markdown without the hidden markers, and summary.source_url links to the comment on GitHub.
summary: null means CodeRabbit hasn’t posted a summary comment. summary.reviewed_commit_sha is null when the commit the summary describes is unknown, so use step 4 to check that the review covers the current head. MCP tool: get_pull_request_review_summary.

6. Read the Change Stack

Get the Change Stack returns the latest saved Change Stack for the pull request: its title and summary, groups of ordered layers, each layer’s files, line ranges, dependencies (depends_on), and Mermaid diagrams. The call never builds a Change Stack; artifact: null means none is saved.
Check these fields of artifact before you use it: An outdated Change Stack stays readable. See Snapshots and freshness for how versions relate to the live pull request. MCP tool: get_pull_request_change_stack.

7. Read a layer’s diff

Get a layer’s diff returns unified patches for the files in one layer. Use the snapshot_id, the group id, and the layer id from the same Change Stack response. Layer IDs are unique only within their group. For example, to pick the first layer of the first group:
URL-encode the IDs if they contain reserved characters. Each file in data has an availability: available files carry a patch, and unavailable files are ones GitHub couldn’t supply a patch for, not empty diffs. Add path to get one file of the layer. Results page by file, 50 files per page by default. If the snapshot is gone or doesn’t record its commits, the call returns 404 not_found; it doesn’t fall back to a newer Change Stack. Read the Change Stack again for a current snapshot_id. MCP tool: get_pull_request_change_stack_layer_diff.

Check every open pull request

This Python script combines steps 2 and 4: it lists every open pull request in a repository and reports whether CodeRabbit finished reviewing each one’s current head, and why not when it hasn’t. It needs the requests package and reads the key and host from CODERABBIT_API_KEY and CODERABBIT_API_HOST. Set CODERABBIT_API_HOST to the host of your region, without /v1; see Base URLs and regions.
check_reviews.py
A 403 stops the script and prints the error, because retrying can’t fix a key that the operation doesn’t accept. The script collects every page before it reads any status, so page tokens don’t expire while it works, and it keys pull requests by number because a live listing can repeat one. Each status read counts toward your rate limit: on a repository with many open pull requests, the script pauses at each 429 for the time in Retry-After, then sends the same request again.

Handle errors

All errors in this flow use the error format described in Errors. The common ones:

What’s next

Run coding tasks

Create a Coding Agent task, review its plan, and deliver its patch through the API.

Connect an MCP client

Connect an AI agent to CodeRabbit and call these operations as MCP tools.

Handle responses

Look up base URLs, pagination, error formats, and rate limits for every operation.