# GitHub Compare Files

Returns the file-by-file diff between two refs: each changed path with its diff lines and the addition and deletion counts. Served from the quota-free web tier.

- **Documentation:** [https://scrappa.co/docs/github-api/github_compare_files](https://scrappa.co/docs/github-api/github_compare_files)
- **API group:** GitHub API
- **Endpoint:** `GET https://scrappa.co/api/github/repository/compare/files`

## Authentication

Send your Scrappa API key in the `X-API-KEY` request header. Paid endpoints also support accountless x402 payments when called without an API key.

## Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `owner` | string | Yes | Repository owner login or organization, e.g. laravel. |
| `repo` | string | Yes | Repository name without the owner, e.g. framework. |
| `base` | string | Yes | Base ref of the comparison, e.g. main. |
| `head` | string | Yes | Head ref of the comparison, e.g. a branch or tag. |

## Example request

```bash
#!/bin/bash

curl -X GET \
    -H "x-api-key: YOUR_API_KEY_HERE" \
    "https://scrappa.co/api/github/repository/compare/files?owner=laravel&repo=framework&base=12.x&head=13.x"
```

## Example response

```json
{
    "search_parameters": {
        "engine": "github_compare_files",
        "owner": "laravel",
        "repo": "framework",
        "base": "12.x",
        "head": "13.x"
    },
    "range": "12.x...13.x",
    "files": [
        {
            "path": "src/Application.php",
            "additions": 3,
            "deletions": 1,
            "lines": [
                "+ new line"
            ]
        }
    ],
    "file_count": 1
}
```

## Errors

| Status | Error | Description |
| --- | --- | --- |
| 422 | Validation Error | A parameter failed validation. |
| 404 | Not Found | GitHub has no public resource at that address. For a repository this also covers a private or renamed repository, which is indistinguishable anonymously. |
| 503 | GitHub Upstream Unavailable | The upstream service is temporarily unavailable. Please retry shortly. |
| 500 | Parser Drift | GitHub returned a response shape this parser does not recognise. The incident has been reported; retrying will return the same result. |
| 406 | Not Acceptable Upstream | GitHub has no JSON representation for this route, or rejected the request headers. Never charged. |

## More Scrappa resources

- [API documentation](https://scrappa.co/docs)
- [Full LLM-readable API reference](https://scrappa.co/llms-full.txt)
- [OpenAPI specification](https://scrappa.co/docs/api.json)
- [Pricing](https://scrappa.co/pricing)
