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

# Usage By Language

GET https://api.onepin.ai/api/v1/usage/by-language

Return workspace audio generation usage broken down by language.

Each row represents one locale with its share of total credit and character
consumption. `share` is a 0..1 fraction of workspace-wide usage for the
period; multiply by 100 for a percentage.

Period selection: supply `activity_view` to align the language rows with
the same period shown on the Usage dashboard chart (daily = last 7 local
days, weekly = last 12 Monday-start weeks, monthly = last 12 months). When
`activity_view` is provided, `range` is ignored and `range` in the response
is `null`. Omit `activity_view` to use the rolling `range` window instead.

Date boundaries are computed in the supplied `timezone` (IANA). Defaults to UTC.

Dual-auth: Bearer JWT or API key (scope `workspace:read`).

Reference: https://onepin.ai/docs/reference/api-reference/usage/by-language-api-v-1-usage-by-language-get

## Authentication

- `Authorization` header (bearer token, required) — Clerk JWT token
- `Authorization` header (bearer token, required) — Onepin live API key (`op_live_...`). Test and public keys are reserved in Phase 1.

## Servers

- `https://api.onepin.ai` (prod, default)
- `https://dev-api.onepin.ai` (dev)

## Request

### Query parameters

- `range` (enum, optional, default: 30d) — Rolling local calendar-day range.
  - Allowed values: `30d`, `60d`, `90d`
- `activity_view` (enum, optional, nullable) — Optional activity view period to align language rows with the selected Usage tab. When supplied, range is ignored and range in the response is null.
  - Allowed values: `daily`, `weekly`, `monthly`
- `timezone` (string, optional, default: UTC) — IANA timezone for local day bucketing.

### Headers

- `X-Workspace-Id` (string, optional, nullable)

## Response

### 200

Successful Response

- `data` (UsageByLanguageOut, required)
- `meta` (Meta, required)

## Errors

### 422 Unprocessable Entity Error

Validation Error

- `detail` (list of ValidationError, optional)

## Types

### UsageByLanguageOut

- `range` (enum, required, nullable) — Rolling range used for rows, or null when activity_view supplies the effective period.
  - Allowed values: `30d`, `60d`, `90d`
- `timezone` (string, required) — IANA timezone used for period boundary computation.
- `period` (UsagePeriodOut, required) — Absolute UTC start and end of the reporting period.
- `activity_view` (enum, optional, nullable) — Activity view period applied when `range` is null.
  - Allowed values: `daily`, `weekly`, `monthly`
- `languages` (list of UsageLanguageRowOut, optional) — Per-language rows ordered by credit consumption descending.
- `total_credits` (integer, optional, default: 0) — Total credits across all languages in the period.
- `untagged_credits` (integer, optional, default: 0) — Credits that could not be attributed to a specific language.

### Meta

- `request_id` (string, required)
- `timestamp` (datetime, required)

### ValidationError

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

### UsagePeriodOut

- `start` (datetime, required) — Start of the reporting period (inclusive), in UTC.
- `end` (datetime, required) — End of the reporting period (exclusive), in UTC.

### UsageLanguageRowOut

- `locale_code` (string, required) — BCP-47 locale code (e.g. `en-us`, `ko-kr`).
- `display_name` (string, required) — Human-readable language name (e.g. `English (US)`).
- `share` (double, required) — Fractional share of workspace usage in the range 0..1; multiply by 100 for percent display.
- `credits` (integer, required) — Credits consumed for this language in the period.
- `characters` (integer, required) — Characters processed for this language in the period.
- `lines` (integer, required) — Script lines generated for this language in the period.
- `allocation_basis` (string, required) — How credit share is allocated for this language (e.g. `characters`).
- `corrected` (integer, optional, default: 0) — Words respliced by the Pronunciation Corrector for this language in the period. A different unit from `characters` — never add the two.

### ValidationErrorLocItems

### ValidationErrorCtx

## Examples

**Response**

```json
{
  "data": {
    "range": "30d",
    "timezone": "string",
    "period": {
      "start": "2024-01-15T09:30:00Z",
      "end": "2024-01-15T09:30:00Z"
    },
    "activity_view": "daily",
    "languages": [
      {
        "locale_code": "string",
        "display_name": "string",
        "share": 1.1,
        "credits": 1,
        "characters": 1,
        "lines": 1,
        "allocation_basis": "string",
        "corrected": 0
      }
    ],
    "total_credits": 0,
    "untagged_credits": 0
  },
  "meta": {
    "request_id": "string",
    "timestamp": "2024-01-15T09:30:00Z"
  }
}
```

**SDK Code**

```python
import requests

url = "https://api.onepin.ai/api/v1/usage/by-language"

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

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

print(response.json())
```

```javascript
const url = 'https://api.onepin.ai/api/v1/usage/by-language';
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.onepin.ai/api/v1/usage/by-language"

	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.onepin.ai/api/v1/usage/by-language")

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.onepin.ai/api/v1/usage/by-language")
  .header("Authorization", "Bearer <token>")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://api.onepin.ai/api/v1/usage/by-language', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.onepin.ai/api/v1/usage/by-language");
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.onepin.ai/api/v1/usage/by-language")! 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()
```