> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes.

# Top up the balance

POST https://%7BYour_Space_Name%7D.signalwire.com/api/space/balance/top_ups
Content-Type: application/json

Charges one of the space's payment methods and deposits the amount to the balance. The
minimum is 5,000,000 microdollars (5.00 USD), and the amount must be a whole number of
cents.

Every top-up needs an `Idempotency-Key` header, a key you generate, so the request is
safe to retry. Repeating a request with the same key and the same body replays the
original top-up and returns `200` with the same balance adjustment instead of charging
the card again; the first successful request returns `201`. The same key with a
different body is rejected with `400`, and a top-up still in flight for that key
returns `409`.

A declined card returns `422` with the processor's `decline_code` rather than the
standard validation body. Cards are added in the Dashboard;
[List payment methods](/docs/apis/rest/space/billing/list-payment-methods) returns the
ids to charge.

#### Permissions

Authenticate with a [Personal access token](/docs/apis/authorization#personal-access-tokens) whose holder is an owner or admin of the space. A project API token is not accepted on this endpoint, and a Personal access token has no scopes: the holder's role in the space is the whole authorization decision.

Reference: https://signalwire.com/docs/apis/rest/space/balance/create-top-up

## Authentication

- `Authorization` header (basic auth, required) — Personal access token authentication for space-wide administration. Send HTTP Basic auth with an empty username and the Personal access token as the password. A Personal access token carries your own authority rather than a project's: it is created from your user menu in the Dashboard, is prefixed `pat_`, and has no scopes. The holder must be an owner or admin of the space named by the subdomain, and the token acts only on that space. Example: ``` Authorization: Basic base64(:pat_...) ```

## Request

### Headers

- `Idempotency-Key` (string, required) — A key you generate that makes the top-up safe to retry. Reusing it with the same body replays the original top-up; reusing it with a different body is rejected.

### Body (application/json)

This endpoint expects an object.

- `amount_in_microdollars` (long, required) — The amount to charge and deposit, in microdollars. At least 5,000,000 (5.00 USD) and a whole number of cents, so a multiple of 10,000.
- `payment_method_id` (string, required) — The payment method to charge. Must name a payment method on this space (`payment_method_invalid`). List them with [List payment methods](/docs/apis/rest/space/billing/list-payment-methods).

## Response

### 200

The request has succeeded.

- `type` (enum, required) — The object type. Always `balance_adjustment`.
  - Allowed values: `balance_adjustment`
- `id` (string, required) — The unique identifier of the adjustment.
- `kind` (string, required) — The kind of adjustment, for example `balance_top_up`, `auto_balance_top_up`, `balance_credit_by_signalwire`, `balance_debit_by_signalwire`, `coupon_code_credit`, or `sign_up_free_credit`.
- `amount_in_microdollars` (long, required) — The signed amount in microdollars. Credits and debits carry the sign they were recorded with.
- `amount` (double, required) — The same amount in US dollars.
- `created_at` (datetime, required) — The date and time when the adjustment was recorded.
- `payment_method_last4` (string, required, nullable) — The last four digits of the card that was charged, or `null` when the adjustment was not charged to a card.

### 201

The request has succeeded and a new resource has been created as a result.

- `type` (enum, required) — The object type. Always `balance_adjustment`.
  - Allowed values: `balance_adjustment`
- `id` (string, required) — The unique identifier of the adjustment.
- `kind` (string, required) — The kind of adjustment, for example `balance_top_up`, `auto_balance_top_up`, `balance_credit_by_signalwire`, `balance_debit_by_signalwire`, `coupon_code_credit`, or `sign_up_free_credit`.
- `amount_in_microdollars` (long, required) — The signed amount in microdollars. Credits and debits carry the sign they were recorded with.
- `amount` (double, required) — The same amount in US dollars.
- `created_at` (datetime, required) — The date and time when the adjustment was recorded.
- `payment_method_last4` (string, required, nullable) — The last four digits of the card that was charged, or `null` when the adjustment was not charged to a card.

## Errors

### 400 Bad Request Error

The `Idempotency-Key` header is missing (`Idempotency-Key header is required.`), the key was reused with a different body (`This Idempotency-Key was already used with different request parameters.`), or the request body is not valid JSON (`not_a_valid_json`).

- `object or object`
  - Space.TopUpIdempotencyKeyMessage
    - `message` (string, required) — Why the request was rejected.
  - Space.SpaceErrorBody
    - `errors` (list of object, required) — List of validation errors.
      - `type` (string, required) — The category of error.
      - `code` (string, required) — A specific error code.
      - `message` (string, required) — A description of what caused the error.
      - `url` (string, required) — A link to documentation about this error.
      - `attribute` (string, optional, nullable) — The request parameter that caused the error, if applicable.

### 401 Unauthorized Error

The credential is missing, unknown, or revoked; its holder is not a member of the space in the subdomain; or the member is not an owner or admin. The body is the plain text `Unauthorized`. An unverified space instead receives the JSON body `{"message": "Please validate a phone number to access your account."}` on every endpoint under `/api/space`.

- `message` (string, required) — States that a phone number must be validated for the space before it can use the API.

### 409 Conflict Error

A top-up with the same `Idempotency-Key` is still in progress. Wait for it to finish, then replay the request with the same key to read its result.

- `message` (string, required) — Why the request was rejected.

### 422 Unprocessable Entity Error

A validation failure, or a declined card. Validation codes: `amount_not_a_whole_number`, `amount_not_whole_cents`, `amount_below_minimum`, and `payment_method_invalid`. A decline returns the decline body instead, with the processor's `decline_code`.

- `object or object`
  - Space.SpaceErrorBody
    - `errors` (list of object, required) — List of validation errors.
      - `type` (string, required) — The category of error.
      - `code` (string, required) — A specific error code.
      - `message` (string, required) — A description of what caused the error.
      - `url` (string, required) — A link to documentation about this error.
      - `attribute` (string, optional, nullable) — The request parameter that caused the error, if applicable.
  - Space.CardDeclinedError
    - `message` (string, required) — A description of the decline.
    - `decline_code` (string, required) — The payment processor's stable decline code.

### 500 Internal Server Error

An internal server error occurred.

- `error` (enum, required)
  - Allowed values: `Internal Server Error`

### 502 Bad Gateway Error

An upstream billing service was unavailable and the deposit to the space balance could not be completed.

- `message` (string, required) — A description of the failure.
- `code` (string, required) — A stable code for the failure.

## Examples

### Example 1

**Request**

```json
{
  "amount_in_microdollars": 25000000,
  "payment_method_id": "7a8b9c0d-1e2f-4304-8516-27384950a6b7"
}
```

**Response**

```json
{
  "type": "balance_adjustment",
  "id": "6f708192-a3b4-4c5d-9e6f-708192a3b4c5",
  "kind": "balance_top_up",
  "amount_in_microdollars": 25000000,
  "amount": 25,
  "created_at": "2026-08-20T14:19:00Z",
  "payment_method_last4": "4242"
}
```

**SDK Code**

```python
import requests

url = "https://{your_space_name}.signalwire.com/api/space/balance/top_ups"

payload = {
    "amount_in_microdollars": 25000000,
    "payment_method_id": "7a8b9c0d-1e2f-4304-8516-27384950a6b7"
}
headers = {
    "Idempotency-Key": "Idempotency-Key"
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers, auth=("<username>", "<personal_access_token>"))

print(response.json())
```

```javascript
const url = 'https://{your_space_name}.signalwire.com/api/space/balance/top_ups';
const credentials = btoa("<username>:<personal_access_token>");

const options = {
  method: 'POST',
  headers: {
    'Idempotency-Key': 'Idempotency-Key',
    Authorization: `Basic ${credentials}`,
    'Content-Type': 'application/json'
  },
  body: '{"amount_in_microdollars":25000000,"payment_method_id":"7a8b9c0d-1e2f-4304-8516-27384950a6b7"}'
};

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"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://{your_space_name}.signalwire.com/api/space/balance/top_ups"

	payload := strings.NewReader("{\n  \"amount_in_microdollars\": 25000000,\n  \"payment_method_id\": \"7a8b9c0d-1e2f-4304-8516-27384950a6b7\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Idempotency-Key", "Idempotency-Key")
	req.SetBasicAuth("<username>", "<personal_access_token>")
	req.Header.Add("Content-Type", "application/json")

	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://{your_space_name}.signalwire.com/api/space/balance/top_ups")

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

request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = 'Idempotency-Key'
request.basic_auth("<username>", "<personal_access_token>")
request["Content-Type"] = 'application/json'
request.body = "{\n  \"amount_in_microdollars\": 25000000,\n  \"payment_method_id\": \"7a8b9c0d-1e2f-4304-8516-27384950a6b7\"\n}"

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.post("https://{your_space_name}.signalwire.com/api/space/balance/top_ups")
  .header("Idempotency-Key", "Idempotency-Key")
  .basicAuth("<username>", "<personal_access_token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"amount_in_microdollars\": 25000000,\n  \"payment_method_id\": \"7a8b9c0d-1e2f-4304-8516-27384950a6b7\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://{your_space_name}.signalwire.com/api/space/balance/top_ups', [
  'body' => '{
  "amount_in_microdollars": 25000000,
  "payment_method_id": "7a8b9c0d-1e2f-4304-8516-27384950a6b7"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'Idempotency-Key' => 'Idempotency-Key',
  ],
    'auth' => ['<username>', '<personal_access_token>'],
]);

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

```csharp
using RestSharp;
using RestSharp.Authenticators;

var client = new RestClient("https://{your_space_name}.signalwire.com/api/space/balance/top_ups");
client.Authenticator = new HttpBasicAuthenticator("<username>", "<personal_access_token>");
var request = new RestRequest(Method.POST);
request.AddHeader("Idempotency-Key", "Idempotency-Key");

request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"amount_in_microdollars\": 25000000,\n  \"payment_method_id\": \"7a8b9c0d-1e2f-4304-8516-27384950a6b7\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let credentials = Data("<username>:<personal_access_token>".utf8).base64EncodedString()

let headers = [
  "Idempotency-Key": "Idempotency-Key",
  "Authorization": "Basic \(credentials)",
  "Content-Type": "application/json"
]
let parameters = [
  "amount_in_microdollars": 25000000,
  "payment_method_id": "7a8b9c0d-1e2f-4304-8516-27384950a6b7"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://{your_space_name}.signalwire.com/api/space/balance/top_ups")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

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()
```

### Example 2

**Request**

```json
{
  "amount_in_microdollars": 25000000,
  "payment_method_id": "7a8b9c0d-1e2f-4304-8516-27384950a6b7"
}
```

**Response**

```json
{
  "type": "balance_adjustment",
  "id": "6f708192-a3b4-4c5d-9e6f-708192a3b4c5",
  "kind": "balance_top_up",
  "amount_in_microdollars": 25000000,
  "amount": 25,
  "created_at": "2026-08-20T14:19:00Z",
  "payment_method_last4": "4242"
}
```

**SDK Code**

```python
import requests

url = "https://{your_space_name}.signalwire.com/api/space/balance/top_ups"

payload = {
    "amount_in_microdollars": 25000000,
    "payment_method_id": "7a8b9c0d-1e2f-4304-8516-27384950a6b7"
}
headers = {
    "Idempotency-Key": "Idempotency-Key"
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers, auth=("<username>", "<personal_access_token>"))

print(response.json())
```

```javascript
const url = 'https://{your_space_name}.signalwire.com/api/space/balance/top_ups';
const credentials = btoa("<username>:<personal_access_token>");

const options = {
  method: 'POST',
  headers: {
    'Idempotency-Key': 'Idempotency-Key',
    Authorization: `Basic ${credentials}`,
    'Content-Type': 'application/json'
  },
  body: '{"amount_in_microdollars":25000000,"payment_method_id":"7a8b9c0d-1e2f-4304-8516-27384950a6b7"}'
};

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"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://{your_space_name}.signalwire.com/api/space/balance/top_ups"

	payload := strings.NewReader("{\n  \"amount_in_microdollars\": 25000000,\n  \"payment_method_id\": \"7a8b9c0d-1e2f-4304-8516-27384950a6b7\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Idempotency-Key", "Idempotency-Key")
	req.SetBasicAuth("<username>", "<personal_access_token>")
	req.Header.Add("Content-Type", "application/json")

	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://{your_space_name}.signalwire.com/api/space/balance/top_ups")

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

request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = 'Idempotency-Key'
request.basic_auth("<username>", "<personal_access_token>")
request["Content-Type"] = 'application/json'
request.body = "{\n  \"amount_in_microdollars\": 25000000,\n  \"payment_method_id\": \"7a8b9c0d-1e2f-4304-8516-27384950a6b7\"\n}"

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.post("https://{your_space_name}.signalwire.com/api/space/balance/top_ups")
  .header("Idempotency-Key", "Idempotency-Key")
  .basicAuth("<username>", "<personal_access_token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"amount_in_microdollars\": 25000000,\n  \"payment_method_id\": \"7a8b9c0d-1e2f-4304-8516-27384950a6b7\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://{your_space_name}.signalwire.com/api/space/balance/top_ups', [
  'body' => '{
  "amount_in_microdollars": 25000000,
  "payment_method_id": "7a8b9c0d-1e2f-4304-8516-27384950a6b7"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'Idempotency-Key' => 'Idempotency-Key',
  ],
    'auth' => ['<username>', '<personal_access_token>'],
]);

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

```csharp
using RestSharp;
using RestSharp.Authenticators;

var client = new RestClient("https://{your_space_name}.signalwire.com/api/space/balance/top_ups");
client.Authenticator = new HttpBasicAuthenticator("<username>", "<personal_access_token>");
var request = new RestRequest(Method.POST);
request.AddHeader("Idempotency-Key", "Idempotency-Key");

request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"amount_in_microdollars\": 25000000,\n  \"payment_method_id\": \"7a8b9c0d-1e2f-4304-8516-27384950a6b7\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let credentials = Data("<username>:<personal_access_token>".utf8).base64EncodedString()

let headers = [
  "Idempotency-Key": "Idempotency-Key",
  "Authorization": "Basic \(credentials)",
  "Content-Type": "application/json"
]
let parameters = [
  "amount_in_microdollars": 25000000,
  "payment_method_id": "7a8b9c0d-1e2f-4304-8516-27384950a6b7"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://{your_space_name}.signalwire.com/api/space/balance/top_ups")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

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()
```