> This page is for Gateway.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.merge.dev/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.merge.dev/_mcp/server.

# Get Project Usage

GET https://api-gateway.merge.dev/v1/projects/{project_id}/usage

Spend totals for one project over a date range, plus a per-model
breakdown. Totals are by day; the per-model breakdown is by month and
covers the whole months the range overlaps.

Reference: https://docs.merge.dev/merge-gateway/management-api/usage/get-project-usage

## Authentication

- `Authorization` header (bearer token, required) — A management key (`mgmt_...`), sent as `Authorization: Bearer <key>`. Reading /v1/routing-policies also accepts the organization's gateway API keys; writing there needs a management key.

## Request

### Path parameters

- `project_id` (string, required) — The project's `id`.

### Query parameters

- `start` (string, optional, nullable) — First day of the range, `YYYY-MM-DD`, inclusive. Defaults to the 1st of this month.
- `end` (string, optional, nullable) — Last day of the range, `YYYY-MM-DD`, inclusive. Defaults to today.

## Response

### 200

The project's spend and usage for the range

- `byok_spend` (double, required) — Spend on your own provider credentials (BYOK), at list price, USD.
- `end` (string, required) — Last day of the range, inclusive, `YYYY-MM-DD`.
- `merge_hosted_spend` (double, required) — Spend on Merge-managed credentials, USD.
- `model_spend` (map from string to double, required) — Spend in USD per `provider/model`, with BYOK spend at list price. Covers the whole months the range overlaps. Months before per-project model tracking began have totals but no entries here.
- `model_spend_granularity` ("month", required) — `model_spend` covers the whole months overlapping `start` to `end`.
- `project_id` (string, required) — The project.
- `request_count` (integer, required) — Number of requests.
- `start` (string, required) — First day of the range, `YYYY-MM-DD`.
- `total_spend` (double, required) — All spend, USD.
- `web_search_spend` (double, required) — Server-side web search cost, USD.

## Errors

### 401 Unauthorized Error

The key is missing or invalid.

- `detail` (ErrorResponseDetail, required) — A message, or an object with a `code` to branch on and a `message`.

### 403 Forbidden Error

The key lacks the scope this route needs, or the change is not allowed.

- `detail` (ErrorResponseDetail, required) — A message, or an object with a `code` to branch on and a `message`.

### 404 Not Found Error

The resource does not exist in the key's organization.

- `detail` (ErrorResponseDetail, required) — A message, or an object with a `code` to branch on and a `message`.

### 422 Unprocessable Entity Error

Validation Error

- `detail` (list of ValidationError, optional)

## Types

### ErrorResponseDetail

A message, or an object with a `code` to branch on and a `message`.

### ValidationError

- `loc` (list of ValidationErrorLocItems, required)
- `msg` (string, required)
- `type` (string, required)
- `ctx` (ValidationErrorCtx, optional)
- `input` (any, optional)

### ErrorDetail

A structured error. Some carry extra fields, like `count`.

- `code` (string, required) — A stable code to branch on, like `payment_method_required`.
- `message` (string, required) — A human-readable explanation.

### ValidationErrorLocItems

### ValidationErrorCtx

## Examples

**Response**

```json
{
  "byok_spend": 371.85,
  "end": "2026-09-30",
  "merge_hosted_spend": 902.17,
  "model_spend": {
    "anthropic/claude-sonnet-4-6": 811.4,
    "openai/gpt-5-mini": 74.5,
    "openai/gpt-5.5": 398.62
  },
  "model_spend_granularity": "month",
  "project_id": "8b6f2d4a-1c3e-4b5a-9f7d-2e0c6a8b4d91",
  "request_count": 48210,
  "start": "2026-09-01",
  "total_spend": 1284.52,
  "web_search_spend": 10.5
}
```

**SDK Code**

```python
import requests

url = "https://api-gateway.merge.dev/v1/projects/project_id/usage"

headers = {"Authorization": "Bearer <token>"}

response = requests.get(url, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api-gateway.merge.dev/v1/projects/project_id/usage';
const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api-gateway.merge.dev/v1/projects/project_id/usage"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("Authorization", "Bearer <token>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api-gateway.merge.dev/v1/projects/project_id/usage")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("https://api-gateway.merge.dev/v1/projects/project_id/usage")
  .header("Authorization", "Bearer <token>")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://api-gateway.merge.dev/v1/projects/project_id/usage', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api-gateway.merge.dev/v1/projects/project_id/usage");
var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", "Bearer <token>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Authorization": "Bearer <token>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api-gateway.merge.dev/v1/projects/project_id/usage")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```