> ## Documentation Index
> Fetch the complete documentation index at: https://docs.blackbox.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Workspace Diff

> Get the cumulative git diff of all changes made by the agent in the sandbox workspace.

This endpoint returns a unified git diff of all changes made by the agent in the sandbox workspace. If the workspace is a git repository, it produces a proper `git diff` output. For non-git workspaces, it falls back to a pseudo-diff listing all file contents.

## Authentication

To use this API, you need a BLACKBOX API Key. Follow these steps to get your API key:

1. Go to [app.blackbox.ai/agent-api](https://app.blackbox.ai/agent-api) and click **Get an API Key** (requires a Pro subscription)
2. Once provisioning completes, you will be redirected to your [Dashboard](https://app.blackbox.ai/dashboard)
3. From the Dashboard, create an API key to use with all Agent API requests

Your API key will be in the format: `sk-xxxxxxxxxxxxxxxxxxxxxx`

## Headers

<ParamField header="Authorization" type="string" required>
  API Key of the form `Bearer <api_key>`.

  Example: `Bearer sk_b41b647ffbfed27f616560`
</ParamField>

## Path Parameters

<ParamField path="runId" type="string" required>
  The unique run identifier returned when the task was created.
</ParamField>

## Query Parameters

<ParamField query="path" type="string" default="/vercel/sandbox">
  Workspace path to diff.

  Default: `/vercel/sandbox`
</ParamField>

<ParamField query="base" type="string" default="HEAD">
  Git ref to diff against.

  * `"HEAD"` — diff staged + unstaged changes against HEAD (default)
  * `"initial"` — diff from the very first commit to current working tree

  Example: `base=initial`
</ParamField>

## Response Fields

<ResponseField name="diff" type="string">
  Unified diff output. Empty string if no changes.
</ResponseField>

<ResponseField name="path" type="string">
  The workspace path that was diffed.
</ResponseField>

<ResponseField name="hasGit" type="boolean">
  Whether the workspace is a git repository.
</ResponseField>

<ResponseField name="base" type="string | null">
  The git ref used as the diff base. `null` for non-git workspaces.
</ResponseField>

<RequestExample>
  ```bash cURL theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
  curl 'https://agent.blackbox.ai/api/v1/tasks/a1b2c3d4-e5f6-7890-abcd-ef1234567890/files/diff' \
    -H 'Authorization: Bearer YOUR_API_KEY'
  ```

  ```bash cURL - From Initial Commit theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
  curl 'https://agent.blackbox.ai/api/v1/tasks/a1b2c3d4-e5f6-7890-abcd-ef1234567890/files/diff?base=initial' \
    -H 'Authorization: Bearer YOUR_API_KEY'
  ```

  ```javascript Node.js theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
  const API_KEY = "YOUR_API_KEY";
  const RUN_ID = "a1b2c3d4-e5f6-7890-abcd-ef1234567890";

  const response = await fetch(
    `https://agent.blackbox.ai/api/v1/tasks/${RUN_ID}/files/diff?base=initial`,
    { headers: { Authorization: `Bearer ${API_KEY}` } }
  );

  const data = await response.json();
  console.log(`Has git: ${data.hasGit}`);
  console.log(data.diff);
  ```

  ```python Python theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
  import requests

  API_KEY = "YOUR_API_KEY"
  RUN_ID = "a1b2c3d4-e5f6-7890-abcd-ef1234567890"

  response = requests.get(
      f"https://agent.blackbox.ai/api/v1/tasks/{RUN_ID}/files/diff",
      headers={"Authorization": f"Bearer {API_KEY}"},
      params={"base": "initial"},
  )
  data = response.json()
  print(f"Has git: {data['hasGit']}")
  print(data["diff"])
  ```
</RequestExample>

<ResponseExample>
  ````json Success Response theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
  {
    "diff": "diff --git a/README.fr.md b/README.fr.md\nnew file mode 100644\nindex 0000000..a1b2c3d\n--- /dev/null\n+++ b/README.fr.md\n@@ -0,0 +1,10 @@\n+# Bienvenue\n+\n+Ceci est le README en français.\n+\n+## Installation\n+\n+```bash\n+npm install\n+```\n",
    "path": "/vercel/sandbox",
    "hasGit": true,
    "base": "initial"
  }
  ````

  ```json No Changes theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
  {
    "diff": "",
    "path": "/vercel/sandbox",
    "hasGit": true,
    "base": "HEAD"
  }
  ```

  ```json Error - No Sandbox theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
  {
    "error": "No sandbox available for this task"
  }
  ```
</ResponseExample>

## Error Codes

| Status Code | Error                 | Description                            |
| ----------- | --------------------- | -------------------------------------- |
| 200         | Success               | Diff returned                          |
| 401         | Unauthorized          | Invalid or missing API key             |
| 403         | Forbidden             | Task belongs to a different user       |
| 404         | Not Found             | Task not found or no sandbox available |
| 500         | Internal Server Error | Failed to get diff                     |
