Skip to content

API Service ​

The API service provides access to Nosana APIs for jobs, credits, and markets. It's automatically configured based on your authentication method.

Authentication Methods ​

The API service supports two authentication methods:

  1. API Key Authentication (Recommended for server-side applications)

    • Provide an API key in the configuration
    • API key takes precedence over wallet-based authentication
  2. Wallet-Based Authentication (For client-side applications)

    • Set a wallet on the client
    • Uses message signing for authentication
    • Automatically enabled when a wallet is configured

Configuration ​

ts
// Option 1: Use API key (recommended for servers)
const const client1: NosanaClientclient1 = 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: 'your-api-key-here', }, }); // Option 2: Use wallet-based auth (for client-side) const const client2: NosanaClientclient2 = 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);
const client2: NosanaClientclient2.NosanaClient.wallet: Wallet | undefined
The wallet. Must be a Wallet (supports both message and transaction signing). Set this property directly to configure the wallet.
@example```ts import { createNosanaClient, NosanaNetwork } from '@nosana/kit'; const client = createNosanaClient(NosanaNetwork.MAINNET); client.wallet = myWallet; ```
wallet
=
const myWallet: Readonly<{
    address: Address<string>;
    signMessages(messages: readonly SignableMessage[], config?: MessagePartialSignerConfig): Promise<readonly SignatureDictionary[]>;
}> & Readonly<{
    address: Address<string>;
    signTransactions(transactions: readonly (Transaction & TransactionWithinSizeLimit & TransactionWithLifetime)[], config?: TransactionPartialSignerConfig): Promise<readonly SignatureDictionary[]>;
}>
myWallet
;
// Option 3: API key takes precedence when both are provided const const client3: NosanaClientclient3 = 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: 'your-api-key-here', }, PartialClientConfig.wallet?: Wallet | undefinedwallet:
const myWallet: Readonly<{
    address: Address<string>;
    signMessages(messages: readonly SignableMessage[], config?: MessagePartialSignerConfig): Promise<readonly SignatureDictionary[]>;
}> & Readonly<{
    address: Address<string>;
    signTransactions(transactions: readonly (Transaction & TransactionWithinSizeLimit & TransactionWithLifetime)[], config?: TransactionPartialSignerConfig): Promise<readonly SignatureDictionary[]>;
}>
myWallet
, // API key will be used, not wallet
});

Behavior ​

  • With API Key: API is created immediately with API key authentication
  • With Wallet: API is created when wallet is set, using wallet-based authentication
  • Without Both: API is undefined until either an API key or wallet is provided
  • Priority: If both API key and wallet are provided, API key is used

API Structure ​

The API service provides access to three main APIs.

ts
client.api?.jobs    // Jobs API
client.api?.credits // Credits API
client.api?.markets // Markets API

Examples ​

ts
// Using API key
const const client1: NosanaClientclient1 = 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: 'your-api-key' }, }); // API is immediately available if (const client1: NosanaClientclient1.NosanaClient.api: NosanaApiClientapi) { // Use the API - methods available on client1.api.jobs, client1.api.credits, client1.api.markets } // Using wallet-based auth const const client2: NosanaClientclient2 = 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);
const client2: NosanaClientclient2.NosanaClient.wallet: Wallet | undefined
The wallet. Must be a Wallet (supports both message and transaction signing). Set this property directly to configure the wallet.
@example```ts import { createNosanaClient, NosanaNetwork } from '@nosana/kit'; const client = createNosanaClient(NosanaNetwork.MAINNET); client.wallet = myWallet; ```
wallet
=
const myWallet: Readonly<{
    address: Address<string>;
    signMessages(messages: readonly SignableMessage[], config?: MessagePartialSignerConfig): Promise<readonly SignatureDictionary[]>;
}> & Readonly<{
    address: Address<string>;
    signTransactions(transactions: readonly (Transaction & TransactionWithinSizeLimit & TransactionWithLifetime)[], config?: TransactionPartialSignerConfig): Promise<readonly SignatureDictionary[]>;
}>
myWallet
;
// API is now available if (const client2: NosanaClientclient2.NosanaClient.api: NosanaApiClientapi) { // Methods available on client2.api.jobs, client2.api.credits, client2.api.markets } // API updates reactively when wallet changes const client2: NosanaClientclient2.NosanaClient.wallet: Wallet | undefined
The wallet. Must be a Wallet (supports both message and transaction signing). Set this property directly to configure the wallet.
@example```ts import { createNosanaClient, NosanaNetwork } from '@nosana/kit'; const client = createNosanaClient(NosanaNetwork.MAINNET); client.wallet = myWallet; ```
wallet
= var undefinedundefined; // API becomes undefined
const client2: NosanaClientclient2.NosanaClient.wallet: Wallet | undefined
The wallet. Must be a Wallet (supports both message and transaction signing). Set this property directly to configure the wallet.
@example```ts import { createNosanaClient, NosanaNetwork } from '@nosana/kit'; const client = createNosanaClient(NosanaNetwork.MAINNET); client.wallet = myWallet; ```
wallet
=
const anotherWallet: Readonly<{
    address: Address<string>;
    signMessages(messages: readonly SignableMessage[], config?: MessagePartialSignerConfig): Promise<readonly SignatureDictionary[]>;
}> & Readonly<{
    address: Address<string>;
    signTransactions(transactions: readonly (Transaction & TransactionWithinSizeLimit & TransactionWithLifetime)[], config?: TransactionPartialSignerConfig): Promise<readonly SignatureDictionary[]>;
}>
anotherWallet
; // API is recreated with new wallet

API Documentation ​

For detailed information about using the Nosana API, see the Nosana API documentation.