# Show credits by kind

The balance split by kind with the expiry of each, in the order the credits are used. Free files of the day come first.

`GET https://api.switchfile.io/v1/account/credits`

Needs an API key: `Authorization: Bearer YOUR_API_KEY`. See [Authentication](https://switchfile.io/docs/authentication).

## Example

cURL:

```bash
curl "https://api.switchfile.io/v1/account/credits" \
  -H "Authorization: Bearer $SWITCHFILE_API_KEY"
```

Node.js:

```js
const res = await fetch("https://api.switchfile.io/v1/account/credits", {
  headers: {
    Authorization: `Bearer ${process.env.SWITCHFILE_API_KEY}`,
  },
});
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
console.log(await res.json());
```

PHP:

```php
<?php
$ch = curl_init('https://api.switchfile.io/v1/account/credits');
curl_setopt_array($ch, [
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('SWITCHFILE_API_KEY'),
    ],
    CURLOPT_RETURNTRANSFER => true,
]);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

if ($status >= 400) {
    throw new RuntimeException("HTTP $status: $response");
}
print_r(json_decode($response, true));
```

Python:

```python
import os
import requests

res = requests.get(
    "https://api.switchfile.io/v1/account/credits",
    headers={"Authorization": f"Bearer {os.environ['SWITCHFILE_API_KEY']}"},
)
res.raise_for_status()
print(res.json())
```

## Responses

### 200: OK

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `balance` | string (integer) \| integer | yes | All credits left, not counting the free files of the day |
| `free` | object | yes | Free files of the day; they are used before any credits |
| `free.conversions_per_day` | string (integer) \| integer | yes |  |
| `free.conversions_used` | string (integer) \| integer | yes |  |
| `free.reset_at` | string | yes | ISO 8601 timestamp |
| `packs` | string (integer) \| integer | yes | Credits from packs (web or App Store); they never expire and are used last |
| `plan` | object[] | yes | Credits from plan payments that are left, earliest expiry first; used after welcome credits |
| `plan[].credits` | string (integer) \| integer | yes |  |
| `plan[].expires_at` | string | yes | ISO 8601 timestamp |
| `welcome` | object \| null | yes | Welcome credits, used first |
| `welcome.credits` | string (integer) \| integer | yes |  |
| `welcome.expires_at` | string | yes | ISO 8601 timestamp |
| `welcome.left` | string (integer) \| integer | yes |  |

Example (application/json):

```json
{
  "balance": 1240,
  "free": {
    "conversions_per_day": 20,
    "conversions_used": 3,
    "reset_at": "2026-11-07T00:00:00+00:00"
  },
  "welcome": {
    "credits": 100,
    "left": 100,
    "expires_at": "2026-12-06T18:00:00+00:00"
  },
  "plan": [],
  "packs": 1140
}
```

### 401: The API key is missing or not valid (`UNAUTHENTICATED`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-unauthenticated",
  "title": "Unauthenticated",
  "status": 401,
  "code": "UNAUTHENTICATED",
  "detail": "Missing or invalid API key."
}
```

### 403: Not available with a service key or a connected app (`NOT_AVAILABLE`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-not-available",
  "title": "Not available",
  "status": 403,
  "code": "NOT_AVAILABLE",
  "detail": "This endpoint is only available with your own API key or the switchfile app."
}
```

### 404: Does not exist for this account (`NOT_FOUND`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-not-found",
  "title": "Not found",
  "status": 404,
  "code": "NOT_FOUND",
  "detail": "Not found."
}
```

### 422: Invalid data. errors names the fields (`INVALID_DATA`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-invalid-data",
  "title": "Invalid data",
  "status": 422,
  "code": "INVALID_DATA",
  "detail": "The request contains invalid data.",
  "errors": {
    "to": [
      "Expected string"
    ]
  }
}
```

### 429: Too many requests or a daily quota is used up. See Retry-After (`RATE_LIMIT_EXCEEDED`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-rate-limit-exceeded",
  "title": "Rate limit exceeded",
  "status": 429,
  "code": "RATE_LIMIT_EXCEEDED",
  "detail": "Too many requests. Try again in 12 seconds."
}
```

Error bodies and codes are explained in [Errors](https://switchfile.io/docs/errors).
