Get credit balance
curl --request GET \
--url https://api.magica.com/api/v1/credits/balance \
--header 'Authorization: <authorization>'import requests
url = "https://api.magica.com/api/v1/credits/balance"
headers = {"Authorization": "<authorization>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: '<authorization>'}};
fetch('https://api.magica.com/api/v1/credits/balance', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.magica.com/api/v1/credits/balance",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.magica.com/api/v1/credits/balance"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "<authorization>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.magica.com/api/v1/credits/balance")
.header("Authorization", "<authorization>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.magica.com/api/v1/credits/balance")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = '<authorization>'
response = http.request(request)
puts response.read_body{
"availableBalance": 123,
"formatted": "<string>",
"hasActiveSubscription": true,
"isOrganization": true
}Credits
Get credit balance
Return the authenticated user’s current credit balance.
GET
/
v1
/
credits
/
balance
Get credit balance
curl --request GET \
--url https://api.magica.com/api/v1/credits/balance \
--header 'Authorization: <authorization>'import requests
url = "https://api.magica.com/api/v1/credits/balance"
headers = {"Authorization": "<authorization>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: '<authorization>'}};
fetch('https://api.magica.com/api/v1/credits/balance', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.magica.com/api/v1/credits/balance",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.magica.com/api/v1/credits/balance"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "<authorization>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.magica.com/api/v1/credits/balance")
.header("Authorization", "<authorization>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.magica.com/api/v1/credits/balance")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = '<authorization>'
response = http.request(request)
puts response.read_body{
"availableBalance": 123,
"formatted": "<string>",
"hasActiveSubscription": true,
"isOrganization": true
}Returns the current credit balance for the authenticated user (or the user’s active organization, if applicable).
Pair this with
POST /v1/workflows/estimate-credits or
POST /v1/nodes/estimate-credits to
confirm there’s enough balance before kicking off an expensive run.Authorizations
string
required
Bearer API key. Format:
Bearer gx_your_api_key.Response
number
Raw credit balance in microcredits. Divide by 1,000,000 to convert to
credits. Use
formatted if you just need a display string.string
Human-readable balance, denominated in millions (e.g.
"1.23M").boolean
true when the user’s (or org’s) subscription is currently active.boolean
true when the returned balance belongs to an organization the user is a
member of, rather than the user’s personal account.Request
- cURL
- Node.js
- Python
curl https://api.magica.com/api/v1/credits/balance \
-H "Authorization: Bearer $MAGICA_API_KEY"
const res = await fetch("https://api.magica.com/api/v1/credits/balance", {
headers: { Authorization: `Bearer ${process.env.MAGICA_API_KEY}` },
});
const { availableBalance, formatted, hasActiveSubscription } = await res.json();
import os, requests
res = requests.get(
"https://api.magica.com/api/v1/credits/balance",
headers={"Authorization": f"Bearer {os.environ['MAGICA_API_KEY']}"},
)
payload = res.json()
print(payload["formatted"]) # e.g. "26.17M"
Response example
{
"availableBalance": 26170000,
"formatted": "26.17M",
"hasActiveSubscription": true,
"isOrganization": false
}
Errors
| Status | Reason |
|---|---|
401 | Missing or invalid API key |
500 | Server error |
Was this page helpful?
⌘I