Account Balance
The GET /account/balance and POST /account/balance endpoints
return the current balance of your BBRE (Browser-Backed Request Engine) account. Balance
tracking is a fundamental part of working with the BBRE API because every request you send
through the system has an associated cost that is deducted from your account balance. When
your balance reaches zero, all subsequent API requests that incur a charge will fail with
an INSUFFICIENT_BALANCE error until you add more funds. The balance endpoint
is intentionally simple: it requires no request body parameters and supports both GET and
POST HTTP methods, making it the easiest endpoint in the entire BBRE API to integrate.
This simplicity is by design, because checking your balance should be a lightweight
operation that you can call frequently without worrying about request formatting or
payload construction. The returned balance value is a floating-point number representing
your current credit in USD. This value reflects all charges that have been processed up
to the moment of the request, including costs from request creation, session creation,
and synchronous request execution. Whether you are building a monitoring dashboard that
displays your remaining credit, implementing pre-flight balance checks before expensive
operations, or setting up automated low-balance alerts, this endpoint provides the data
you need. This page covers the endpoint definition, authentication requirements, response
format, working code examples in JavaScript, Python, and cURL, balance monitoring
patterns, SDK integration, error handling, and best practices for effective balance
management in production systems.
Your account balance is updated in real time as requests are processed. Each BBRE API operation that incurs a charge (request creation, session creation, synchronous execution) deducts the corresponding amount from your balance immediately upon completion. The balance endpoint always returns the most current value, so you can rely on it for accurate pre-flight checks before submitting expensive batch operations. Both GET and POST methods are supported and return identical responses, so you can use whichever method fits your existing HTTP client configuration. No request body or query parameters are needed.
Endpoint
The account balance endpoint supports both GET and POST HTTP methods. Both methods behave identically and return the same response structure. This dual-method support exists for convenience: some HTTP client libraries and proxy configurations handle GET requests differently from POST requests, so supporting both methods ensures you can always retrieve your balance regardless of your infrastructure constraints.
Authentication
All requests to the BBRE API require authentication via an API key. You must include your API
key in the HTTP headers of every request, including balance queries. The API accepts the key
through either the x-api-key header or the apikey header. Both
header names are supported and functionally identical. If no API key is provided, the API
returns a 401 error with the API_KEY_REQUIRED error code. If the
provided key is invalid or belongs to a suspended or inactive account, the API returns a
403 error with the appropriate error code (INVALID_API_KEY,
ACCOUNT_SUSPENDED, or ACCOUNT_INACTIVE).
| Header | Type | Required | Description |
|---|---|---|---|
x-api-key |
string | required | Your BBRE API key. You can find this in your MyDisct Solver dashboard. |
Unlike most other BBRE endpoints, the balance endpoint does not require a
Content-Type header when using the GET method because there is no request body.
If you use the POST method, you can optionally include Content-Type: application/json
but it is not required since the endpoint ignores the request body entirely.
Request Parameters
The account balance endpoint does not accept any request parameters. There is no request body, no query parameters, and no URL parameters. The only requirement is a valid API key in the request headers. This makes the balance endpoint the simplest endpoint in the BBRE API to call. When using the GET method, simply send a GET request with your API key header. When using the POST method, you can send an empty body or no body at all. The endpoint identifies your account entirely through the API key and returns the balance associated with that account.
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters required. The endpoint uses your API key to identify your account. | |||
Response Format
The balance endpoint returns a JSON response containing your current account balance. On success, the response includes the standard BBRE success fields plus the balance value as a floating-point number. The balance represents your available credit in USD and reflects all charges processed up to the moment of the request.
Success Response (200)
A successful balance query returns the following structure. The balance field
is a floating-point number representing your current credit. A balance of 0
means you have no remaining credit and any charged API operations will fail until you add
funds. The service field always contains "MyDisct Solver BBRE"
to identify which service processed the request.
{
"success": true,
"service": "MyDisct Solver BBRE",
"balance": 125.50
}
| Field | Type | Description |
|---|---|---|
success |
boolean | Always true for successful responses. |
service |
string | Always "MyDisct Solver BBRE". Identifies the service that processed the request. |
balance |
number | Your current account balance as a floating-point number in USD. This value is updated in real time as requests are processed. A value of 0 indicates no remaining credit. |
Error Response Examples
When the balance query fails, the API returns an error response with the appropriate HTTP status code, error code, and a descriptive message. The most common error scenarios for this endpoint are authentication-related, since the endpoint itself has no parameters that could be invalid.
401 - API Key Required
{
"success": false,
"service": "MyDisct Solver BBRE",
"error": {
"code": "API_KEY_REQUIRED",
"message": "API key is required. Please provide your API key in the x-api-key or apikey header."
}
}
403 - Invalid API Key
{
"success": false,
"service": "MyDisct Solver BBRE",
"error": {
"code": "INVALID_API_KEY",
"message": "The provided API key is invalid or does not exist."
}
}
403 - Account Suspended
{
"success": false,
"service": "MyDisct Solver BBRE",
"error": {
"code": "ACCOUNT_SUSPENDED",
"message": "Your account has been suspended. Please contact support for more information."
}
}
500 - Service Error
{
"success": false,
"service": "MyDisct Solver BBRE",
"error": {
"code": "SERVICE_ERROR",
"message": "An internal server error occurred. Please try again later."
}
}
Code Examples
The following examples demonstrate how to check your account balance using different
programming languages and HTTP methods. Since the balance endpoint supports both GET and
POST, examples are provided for both methods. All examples show complete, working code
that you can copy and run directly. Remember to replace YOUR_API_KEY with
your actual BBRE API key.
GET Request with JavaScript (fetch)
The simplest way to check your balance using the native fetch API. Since this
is a GET request with no body, you only need to include the authentication header.
const API_BASE = "https://bbre-solver-api.mydisct.com";
const API_KEY = "YOUR_API_KEY";
async function checkBalance() {
const response = await fetch(API_BASE + "/account/balance", {
method: "GET",
headers: {
"x-api-key": API_KEY
}
});
const data = await response.json();
if (data.success) {
console.log("Current balance: $" + data.balance.toFixed(2));
} else {
console.log("Error:", data.error.code, data.error.message);
}
return data.balance;
}
checkBalance();
POST Request with JavaScript (fetch)
If your application already uses POST for all BBRE API calls, you can use POST for the balance endpoint as well. The response is identical to the GET method.
const API_BASE = "https://bbre-solver-api.mydisct.com";
const API_KEY = "YOUR_API_KEY";
async function checkBalancePost() {
const response = await fetch(API_BASE + "/account/balance", {
method: "POST",
headers: {
"x-api-key": API_KEY
}
});
const data = await response.json();
console.log("Current balance: $" + data.balance.toFixed(2));
return data.balance;
}
checkBalancePost();
Python (requests library)
Checking your balance with Python using the popular requests library. The
example shows both GET and POST approaches.
import requests
API_BASE = "https://bbre-solver-api.mydisct.com"
API_KEY = "YOUR_API_KEY"
headers = {
"x-api-key": API_KEY
}
response = requests.get(
API_BASE + "/account/balance",
headers=headers
)
data = response.json()
if data["success"]:
print(f"Current balance: ${data['balance']:.2f}")
else:
print(f"Error: {data['error']['code']}")
import requests
API_BASE = "https://bbre-solver-api.mydisct.com"
API_KEY = "YOUR_API_KEY"
headers = {
"x-api-key": API_KEY
}
response = requests.post(
API_BASE + "/account/balance",
headers=headers
)
data = response.json()
print(f"Current balance: ${data['balance']:.2f}")
cURL
Quick balance checks from the command line using cURL. The GET method is the natural choice for cURL since it requires no body.
curl https://bbre-solver-api.mydisct.com/account/balance \
-H "x-api-key: YOUR_API_KEY"
curl -X POST https://bbre-solver-api.mydisct.com/account/balance \
-H "x-api-key: YOUR_API_KEY"
Balance Monitoring Patterns
In production systems, you rarely call the balance endpoint in isolation. Instead, you integrate balance checks into your application workflow to prevent failed requests due to insufficient funds and to trigger alerts when your balance drops below a threshold. The following patterns demonstrate common approaches to balance monitoring that you can adapt to your specific use case.
Pre-Flight Balance Check
Before submitting a batch of requests or creating an expensive session, check your balance to ensure you have sufficient funds. This prevents wasted time and partial batch failures where some requests succeed and others fail mid-batch due to balance depletion. The pre-flight check is especially important when you are about to submit a large number of requests in a loop, because each failed request still consumes network round-trip time even though it returns an error immediately.
const API_BASE = "https://bbre-solver-api.mydisct.com";
const API_KEY = "YOUR_API_KEY";
const authHeaders = {
"Content-Type": "application/json",
"x-api-key": API_KEY
};
async function getBalance() {
const response = await fetch(API_BASE + "/account/balance", {
headers: { "x-api-key": API_KEY }
});
const data = await response.json();
return data.balance;
}
async function submitBatchWithBalanceCheck(urls) {
const balance = await getBalance();
const estimatedCost = urls.length * 0.01;
if (balance < estimatedCost) {
console.log("Insufficient balance for batch.");
console.log("Current: $" + balance.toFixed(2));
console.log("Estimated cost: $" + estimatedCost.toFixed(2));
return;
}
console.log("Balance sufficient. Submitting " + urls.length + " requests...");
for (const url of urls) {
const response = await fetch(API_BASE + "/request/execute", {
method: "POST",
headers: authHeaders,
body: JSON.stringify({ url: url, method: "GET" })
});
const result = await response.json();
console.log(url + " -> " + result.success);
}
}
submitBatchWithBalanceCheck([
"https://example.com/page1",
"https://example.com/page2",
"https://example.com/page3"
]);
Low Balance Alert System
Set up a periodic balance check that triggers an alert when your balance drops below a configurable threshold. This gives you time to add funds before your balance reaches zero and your production workflows start failing. The alert threshold should be set high enough to cover at least a few hours of normal usage, giving you a comfortable window to respond.
const API_BASE = "https://bbre-solver-api.mydisct.com";
const API_KEY = "YOUR_API_KEY";
const LOW_BALANCE_THRESHOLD = 5.00;
const CHECK_INTERVAL_MS = 60000;
async function checkBalanceAndAlert() {
try {
const response = await fetch(API_BASE + "/account/balance", {
headers: { "x-api-key": API_KEY }
});
const data = await response.json();
if (data.success && data.balance < LOW_BALANCE_THRESHOLD) {
console.log("[ALERT] Low balance: $" + data.balance.toFixed(2));
console.log("Threshold: $" + LOW_BALANCE_THRESHOLD.toFixed(2));
await sendAlertNotification(data.balance);
}
} catch (error) {
console.log("Balance check failed:", error.message);
}
}
async function sendAlertNotification(balance) {
console.log("Sending low balance notification: $" + balance.toFixed(2));
}
setInterval(checkBalanceAndAlert, CHECK_INTERVAL_MS);
checkBalanceAndAlert();
Balance Check with Python
A Python implementation of the pre-flight balance check pattern. This is useful when your BBRE integration is built in Python and you want to verify funds before starting a scraping or automation workflow.
import requests
import time
API_BASE = "https://bbre-solver-api.mydisct.com"
API_KEY = "YOUR_API_KEY"
headers = {
"x-api-key": API_KEY
}
def get_balance():
response = requests.get(
API_BASE + "/account/balance",
headers=headers
)
data = response.json()
if data["success"]:
return data["balance"]
raise Exception(data["error"]["message"])
def check_balance_before_batch(url_list, cost_per_request=0.01):
balance = get_balance()
total_cost = len(url_list) * cost_per_request
if balance < total_cost:
print(f"Insufficient balance: ${balance:.2f}")
print(f"Required: ${total_cost:.2f} for {len(url_list)} requests")
return False
print(f"Balance OK: ${balance:.2f} (need ${total_cost:.2f})")
return True
urls = [
"https://example.com/page1",
"https://example.com/page2",
"https://example.com/page3"
]
if check_balance_before_batch(urls):
print("Proceeding with batch...")
Node.js SDK Usage
The mydisctsolver-bbre Node.js SDK provides a convenient
getBalance() method on the BBREClient class that wraps the
GET /account/balance endpoint. The SDK handles authentication headers and
response parsing automatically, returning the balance value directly as a number instead
of the full response object. This makes balance checks a single line of code in your
application.
Basic Balance Check
const { BBREClient } = require("mydisctsolver-bbre");
const client = new BBREClient({ apiKey: "YOUR_API_KEY" });
async function checkBalance() {
const balance = await client.getBalance();
console.log("Current balance: $" + balance.toFixed(2));
return balance;
}
checkBalance();
SDK Balance Check Before Operations
Combine the SDK getBalance() method with other SDK operations to implement
a pre-flight balance check pattern. The SDK returns the balance as a plain number, so
you can compare it directly against your threshold without parsing the response.
const { BBREClient } = require("mydisctsolver-bbre");
const client = new BBREClient({
apiKey: "YOUR_API_KEY",
mode: "passive",
sensibility: "medium"
});
async function safeRequest(url) {
const balance = await client.getBalance();
if (balance < 0.01) {
throw new Error("Balance too low: $" + balance.toFixed(2));
}
const result = await client.request({
url: url,
method: "GET"
});
console.log("Request completed. Status:", result.statusCode);
return result;
}
safeRequest("https://example.com");
SDK Balance Monitoring Loop
Use the SDK to build a simple balance monitoring loop that logs your balance at regular intervals. This is useful during development and testing to track how quickly your balance is being consumed by your workflow.
const { BBREClient } = require("mydisctsolver-bbre");
const client = new BBREClient({ apiKey: "YOUR_API_KEY" });
async function monitorBalance(intervalMs, thresholdUsd) {
const check = async () => {
try {
const balance = await client.getBalance();
const timestamp = new Date().toISOString();
console.log("[" + timestamp + "] Balance: $" + balance.toFixed(2));
if (balance < thresholdUsd) {
console.log("[WARNING] Balance below threshold of $" + thresholdUsd.toFixed(2));
}
} catch (error) {
console.log("Balance check error:", error.message);
}
};
await check();
setInterval(check, intervalMs);
}
monitorBalance(30000, 10.00);
The SDK getBalance() method internally sends a GET request to
/account/balance and extracts the balance field from the
response. If the request fails, the method throws an error with the error message from
the API response. For more details on the SDK, see the
Node.js SDK Overview and the
Account Methods documentation.
Error Codes
The following table lists all error codes that can be returned by the account balance endpoint, along with their HTTP status codes, descriptions, and recommended solutions. Because the balance endpoint has no request parameters, the only errors you will encounter are authentication-related errors and server-side errors. Implementing proper error handling for these codes ensures your balance monitoring logic degrades gracefully when issues occur.
| HTTP Status | Error Code | Description | Solution |
|---|---|---|---|
401 |
API_KEY_REQUIRED |
No API key was provided in the request headers. The balance endpoint requires authentication like all other BBRE endpoints. | Include your API key in the x-api-key or apikey header. Verify that your HTTP client is sending the header correctly and that it is not being stripped by a proxy or middleware. |
403 |
INVALID_API_KEY |
The provided API key is not valid or does not exist in the system. | Verify your API key in the MyDisct Solver dashboard. Ensure you are copying the complete key without extra spaces or line breaks. If you recently regenerated your key, update it in your application configuration. |
403 |
ACCOUNT_SUSPENDED |
Your account has been suspended. Suspended accounts cannot access any BBRE API endpoints, including the balance endpoint. | Contact MyDisct Solver support for information about your account suspension and steps to resolve it. |
403 |
ACCOUNT_INACTIVE |
Your account is inactive. Inactive accounts need to be activated before they can use the BBRE API. | Activate your account through the MyDisct Solver dashboard or contact support for assistance. |
500 |
SERVICE_ERROR |
An internal server error occurred while processing the balance request. This is rare for the balance endpoint since it performs a simple database lookup. | Retry the request after a short delay (2-5 seconds). If the error persists, contact support. Do not let a temporary balance check failure block your entire workflow. |
Error Handling Example
The following example demonstrates robust error handling for the balance endpoint. In production systems, your balance check should never crash your application. Instead, handle each error code appropriately and fall back to a safe default behavior when the balance cannot be determined.
const API_BASE = "https://bbre-solver-api.mydisct.com";
const API_KEY = "YOUR_API_KEY";
async function getBalanceSafe() {
try {
const response = await fetch(API_BASE + "/account/balance", {
headers: { "x-api-key": API_KEY }
});
const data = await response.json();
if (data.success) {
return { balance: data.balance, error: null };
}
const errorCode = data.error.code;
if (errorCode === "API_KEY_REQUIRED" || errorCode === "INVALID_API_KEY") {
return { balance: null, error: "Authentication failed: " + errorCode };
}
if (errorCode === "ACCOUNT_SUSPENDED" || errorCode === "ACCOUNT_INACTIVE") {
return { balance: null, error: "Account issue: " + errorCode };
}
return { balance: null, error: "Unexpected error: " + errorCode };
} catch (networkError) {
return { balance: null, error: "Network error: " + networkError.message };
}
}
async function main() {
const result = await getBalanceSafe();
if (result.error) {
console.log("Could not check balance:", result.error);
return;
}
console.log("Balance: $" + result.balance.toFixed(2));
}
main();
Best Practices
Always verify your balance before submitting large batches of requests or creating
sessions. A single balance check at the start of a batch operation takes milliseconds
and can save you from partial batch failures where some requests succeed and others
fail with INSUFFICIENT_BALANCE errors. Calculate the estimated total cost
of your batch based on the number of requests and the per-request price, then compare
it against your current balance. If the balance is insufficient, you can notify the
user or queue the batch for later execution instead of wasting time on requests that
will inevitably fail.
Set up automated balance monitoring that checks your balance at regular intervals and sends notifications when it drops below a configurable threshold. The threshold should be set high enough to cover several hours of normal usage, giving you time to add funds before your balance reaches zero. A check interval of 1-5 minutes is sufficient for most use cases. Avoid checking more frequently than once per minute, as this adds unnecessary load without providing meaningful additional insight. Use the balance value to calculate your estimated remaining runtime based on your average consumption rate.
If your application makes many balance checks in rapid succession (for example, checking before every individual request in a tight loop), consider caching the balance value for a short period (5-10 seconds). This reduces the number of API calls while still providing reasonably accurate balance information. The balance changes only when a charged operation completes, so a cached value from a few seconds ago is usually accurate enough for pre-flight checks. Invalidate the cache after any operation that you know will affect the balance, such as creating a request or session.
Never let a failed balance check crash your application or block your entire workflow. The balance endpoint can occasionally return errors due to temporary server issues, and your application should handle these gracefully. If a balance check fails, decide on a safe default behavior: either proceed with the operation (optimistic approach, suitable when you know your balance is usually sufficient) or skip the operation and retry the balance check later (conservative approach, suitable for expensive batch operations). Log the failure for debugging but do not treat it as a fatal error.
When you only need to check your balance without sending any data, use the GET method. GET requests are semantically correct for read-only operations, are easier to test from a browser or command line, and are more likely to be cached by intermediate proxies if you have caching infrastructure. The POST method is available for convenience when your HTTP client or infrastructure requires it, but GET is the preferred method for balance queries.
Common Issues
Issue 1: Balance Shows Zero But Funds Were Added Recently
You added funds to your account through the MyDisct Solver dashboard, but the balance
endpoint still returns 0 or the old balance value. Your requests continue
to fail with INSUFFICIENT_BALANCE errors.
Solution: Balance updates from the dashboard are processed in real time, but there can be a brief delay of a few seconds between the payment confirmation and the balance update in the database. Wait 10-15 seconds after adding funds and then check your balance again. If the balance still does not reflect your payment after a minute, verify that the payment was completed successfully in your dashboard transaction history. If the payment shows as completed but the balance is not updated, contact MyDisct Solver support with your transaction ID.
Issue 2: Balance Decreases Faster Than Expected
Your balance is decreasing more quickly than you anticipated based on the number of requests you are sending. The consumption rate does not match your calculations.
Solution: Different BBRE operations have different costs. Session creation, adaptive mode requests, and high sensibility requests typically cost more than simple passive mode requests with low sensibility. Check the Usage History endpoint to see the exact charge for each operation. Also verify that you do not have other applications or scripts using the same API key, which would consume balance from the same account. If you are using sessions, remember that session creation itself may have an associated cost in addition to the per-request charges within the session.
Issue 3: Getting 401 Error When Checking Balance
You receive a 401 API_KEY_REQUIRED error when calling the balance endpoint,
even though you believe you are including the API key in your request.
Solution: The most common cause is using the wrong header name. The BBRE
API accepts the API key through the x-api-key or apikey HTTP
headers only. It does not support API key authentication through query parameters, URL
paths, or the Authorization header. Verify that your HTTP client is sending
the header with the exact name x-api-key (all lowercase with hyphens) or
apikey (all lowercase, no hyphens). Also check that your API key value does
not contain leading or trailing whitespace, which can happen when copying from the
dashboard. Some HTTP client libraries automatically trim header values, but others do not.