Credits API
The Credits API allows you to check your account's credit balance. Credits are used to pay for deployments when using API key authentication.
Overview
Credits are the currency used in the Nosana Network when using API key authentication. Each deployment execution consumes credits based on the resources used and execution time.
Get Credit Balance
Check your current credit balance:
ts
import { function createNosanaClient(network: NosanaNetwork | undefined, customConfig: PartialClientConfig & {
connect: ConnectFactoryConfig & {
clientSecret: string;
};
}): NosanaClient & {
connect: ServerConnect;
} (+3 overloads)
createNosanaClient, type NosanaNetwork = "mainnet" | "devnet" | "localnet"
const NosanaNetwork: {
readonly MAINNET: "mainnet";
readonly DEVNET: "devnet";
readonly LOCALNET: "localnet";
}
NosanaNetwork } from '@nosana/kit';
const const client: NosanaClientclient = function createNosanaClient(network?: NosanaNetwork, customConfig?: PartialClientConfig): NosanaClient (+3 overloads)createNosanaClient(const NosanaNetwork: {
readonly MAINNET: "mainnet";
readonly DEVNET: "devnet";
readonly LOCALNET: "localnet";
}
NosanaNetwork.type MAINNET: "mainnet"MAINNET, {
PartialClientConfig.api?: Partial<APIConfig> | undefinedapi: {
apiKey?: string | undefinedapiKey: const process: {
env: Record<string, string>;
}
process.env: Record<string, string>env.stringNOSANA_API_KEY,
},
});
// Get credit balance
const const balance: {
assignedCredits: number;
reservedCredits: number;
settledCredits: number;
}
balance = await const client: NosanaClientclient.NosanaClient.api: NosanaApiClientapi.credits: NosanaCreditsApicredits.NosanaCreditsApi.balance: () => Promise<Balance>balance();
var console: ConsoleThe `console` module provides a simple debugging console that is similar to the
JavaScript console mechanism provided by web browsers.
The module exports two specific components:
* A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream.
* A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v24.x/api/process.html#processstdout) and
[`process.stderr`](https://nodejs.org/docs/latest-v24.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module.
_**Warning**_: The global console object's methods are neither consistently
synchronous like the browser APIs they resemble, nor are they consistently
asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v24.x/api/process.html#a-note-on-process-io) for
more information.
Example using the global `console`:
```js
console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr
```
Example using the `Console` class:
```js
const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err
```console.Console.log(message?: any, ...optionalParams: any[]): void (+1 overload)Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log('Assigned Credits:', const balance: {
assignedCredits: number;
reservedCredits: number;
settledCredits: number;
}
balance.assignedCredits: numberassignedCredits);
var console: ConsoleThe `console` module provides a simple debugging console that is similar to the
JavaScript console mechanism provided by web browsers.
The module exports two specific components:
* A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream.
* A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v24.x/api/process.html#processstdout) and
[`process.stderr`](https://nodejs.org/docs/latest-v24.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module.
_**Warning**_: The global console object's methods are neither consistently
synchronous like the browser APIs they resemble, nor are they consistently
asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v24.x/api/process.html#a-note-on-process-io) for
more information.
Example using the global `console`:
```js
console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr
```
Example using the `Console` class:
```js
const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err
```console.Console.log(message?: any, ...optionalParams: any[]): void (+1 overload)Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log('Reserved Credits:', const balance: {
assignedCredits: number;
reservedCredits: number;
settledCredits: number;
}
balance.reservedCredits: numberreservedCredits);
var console: ConsoleThe `console` module provides a simple debugging console that is similar to the
JavaScript console mechanism provided by web browsers.
The module exports two specific components:
* A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream.
* A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v24.x/api/process.html#processstdout) and
[`process.stderr`](https://nodejs.org/docs/latest-v24.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module.
_**Warning**_: The global console object's methods are neither consistently
synchronous like the browser APIs they resemble, nor are they consistently
asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v24.x/api/process.html#a-note-on-process-io) for
more information.
Example using the global `console`:
```js
console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr
```
Example using the `Console` class:
```js
const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err
```console.Console.log(message?: any, ...optionalParams: any[]): void (+1 overload)Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log('Settled Credits:', const balance: {
assignedCredits: number;
reservedCredits: number;
settledCredits: number;
}
balance.settledCredits: numbersettledCredits);
var console: ConsoleThe `console` module provides a simple debugging console that is similar to the
JavaScript console mechanism provided by web browsers.
The module exports two specific components:
* A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream.
* A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v24.x/api/process.html#processstdout) and
[`process.stderr`](https://nodejs.org/docs/latest-v24.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module.
_**Warning**_: The global console object's methods are neither consistently
synchronous like the browser APIs they resemble, nor are they consistently
asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v24.x/api/process.html#a-note-on-process-io) for
more information.
Example using the global `console`:
```js
console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr
```
Example using the `Console` class:
```js
const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err
```console.Console.log(message?: any, ...optionalParams: any[]): void (+1 overload)Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log('Available Credits:', const balance: {
assignedCredits: number;
reservedCredits: number;
settledCredits: number;
}
balance.assignedCredits: numberassignedCredits - const balance: {
assignedCredits: number;
reservedCredits: number;
settledCredits: number;
}
balance.reservedCredits: numberreservedCredits - const balance: {
assignedCredits: number;
reservedCredits: number;
settledCredits: number;
}
balance.settledCredits: numbersettledCredits);Balance Fields
| Field | Description |
|---|---|
assignedCredits | Total credits assigned to your account |
reservedCredits | Credits currently reserved for running deployments |
settledCredits | Credits that have been consumed by completed deployments |
| Available Credits | assignedCredits - reservedCredits - settledCredits |
Understanding Credit Usage
- Reserved Credits: Credits that are currently allocated to active deployments. These credits are held until the deployment completes or is stopped.
- Settled Credits: Credits that have been consumed by completed deployments. These are permanently deducted from your balance.
- Available Credits: The amount of credits you can use for new deployments. This is calculated as
assignedCredits - reservedCredits - settledCredits.
Insufficient Credits
If you don't have enough available credits, deployments will fail with an INSUFFICIENT_FUNDS status. You can:
- Check your balance using this API
- Top up your account through the Nosana Deploy dashboard
- Wait for running deployments to complete and release reserved credits
Claiming & Requesting Credits
ts
// Claim a credit code
await const client: NosanaClientclient.NosanaClient.api: NosanaApiClientapi.credits: NosanaCreditsApicredits.NosanaCreditsApi.claim: (code: string) => Promise<Record<string, unknown>>claim('CREDIT-CODE-123');
// Request free credits (subject to eligibility)
const const eligibility: Record<string, unknown>eligibility = await const client: NosanaClientclient.NosanaClient.api: NosanaApiClientapi.credits: NosanaCreditsApicredits.NosanaCreditsApi.checkEligibility: () => Promise<Record<string, unknown>>checkEligibility();
if (const eligibility: Record<string, unknown>eligibility.unknowneligible) {
await const client: NosanaClientclient.NosanaClient.api: NosanaApiClientapi.credits: NosanaCreditsApicredits.NosanaCreditsApi.request: () => Promise<Record<string, unknown>>request();
}
// Invitations
const const invite: Record<string, unknown>invite = await const client: NosanaClientclient.NosanaClient.api: NosanaApiClientapi.credits: NosanaCreditsApicredits.NosanaCreditsApi.invitations: {
get: (token: string) => Promise<Record<string, unknown>>;
claim: (token: string) => Promise<Record<string, unknown>>;
}
invitations.get: (token: string) => Promise<Record<string, unknown>>get(const token: stringtoken);
await const client: NosanaClientclient.NosanaClient.api: NosanaApiClientapi.credits: NosanaCreditsApicredits.NosanaCreditsApi.invitations: {
get: (token: string) => Promise<Record<string, unknown>>;
claim: (token: string) => Promise<Record<string, unknown>>;
}
invitations.claim: (token: string) => Promise<Record<string, unknown>>claim(const token: stringtoken);| Method | HTTP | Path | Description |
|---|---|---|---|
credits.claim(code) | POST | /api/credits/claim | Claim a credit code |
credits.request() | POST | /api/credits/request | Request free credits |
credits.checkEligibility() | GET | /api/credits/request/eligibility | Check free-credit eligibility |
credits.invitations.get(token) | GET | /api/credits/invitations/{token} | Get invitation details |
credits.invitations.claim(token) | POST | /api/credits/invitations/{token}/claim | Claim an invitation |
Spending History & Transactions
ts
// Spending history (start_date required; optional end_date, group_by)
const const spending: Record<string, unknown>spending = await const client: NosanaClientclient.NosanaClient.api: NosanaApiClientapi.credits: NosanaCreditsApicredits.NosanaCreditsApi.getSpendingHistory: (request: CreditsSpendingHistoryRequest) => Promise<Record<string, unknown>>getSpendingHistory({
start_date: stringstart_date: '2025-01-01',
group_by?: "month" | "day" | undefinedgroup_by: 'month',
});
// Paginated transaction list
const const txs: Record<string, unknown>txs = await const client: NosanaClientclient.NosanaClient.api: NosanaApiClientapi.credits: NosanaCreditsApicredits.NosanaCreditsApi.getTransactions: (request: CreditsTransactionsRequest) => Promise<Record<string, unknown>>getTransactions({ limit: string | numberlimit: 50, offset: string | numberoffset: 0 });| Method | HTTP | Path | Description |
|---|---|---|---|
credits.getSpendingHistory(request) | GET | /api/credits/spending-history | Credit spending history |
credits.getTransactions(request) | GET | /api/credits/transactions | List credit transactions |