SDK
Every option and method of `@shader/sdk`, what each returns, and the errors it throws.
@shader/sdk is a TypeScript client for Node 26. It calls the API, parses every answer with the API's own schemas, and pays for a generation over x402 from a wallet signer. First rental with the SDK runs it from start to stop.
import { Shader } from '@shader/sdk'
const shader = new Shader({ token: process.env.SHADER_TOKEN })#Options
new Shader(options) takes:
| Option | Meaning |
|---|---|
token (optional) | Agent token, sent as a bearer token. Leave it out for x402 only. |
baseUrl (optional) | API base URL; defaults to the production API. |
rpcUrl (optional) | Solana RPC for x402 payments and rentals; required off mainnet. |
fetch (optional) | A fetch to use instead of the global one. |
fixture (optional) | Fixture scenario, for the local fixture server only. |
#Methods
| Method | What it does | Returns |
|---|---|---|
config() | Product configuration: prices, headroom, agentRentalMaxSeconds, assets. | ProductConfig |
caller() | The wallet and agent key the token acts for. | Caller |
agents() | The wallet's agent keys with their caps and spend today. | AgentList |
gpus() | The GPU catalog. | GpuCatalog |
instances() | Your rentals, newest first; use it to find machines left running after a crash. | InstancePage |
jobs() | Your generations, newest first. | JobPage |
rent({ gpu, sshPublicKey? }) | Launches a GPU by catalog id. | InstanceDetail |
instance(id) | One rental with its meter and connection details. | InstanceDetail |
stop(id) | Stops a rental. | StopInstanceResponse |
rentX402({ gpu, maxSeconds?, signer, maxUsd?, sshPublicKey?, onQuote? }) | Rents a GPU over x402 from signer's wallet: asks for the quote, calls onQuote with its rate and ceiling, refuses before signing if the ceiling is above maxUsd, signs the channel open and retries. Needs no token. | X402RentalResponse |
extendX402({ instanceId, seconds?, stopToken, signer, maxUsd?, onQuote? }) | Extends an x402 rental with another channel at its locked rate, from the same wallet. | X402RentalResponse |
stopX402({ instanceId, stopToken }) | Stops an x402 rental with its stop token; the answer has each channel's charge and refund. | StopInstanceResponse |
estimate({ kind, prompt, options? }) | What a generation will cost. For voice, prompt is the text to speak. | GenerationEstimate |
generate({ kind, prompt, options? }) | Starts a generation paid from credits. | Job |
job(id) | One generation. | Job |
balance() | The credit balance. | CreditBalance |
receipts({ kind?, agentKey?, limit?, cursor? }) | Your receipts, newest first. | ReceiptPage |
waitUntilRunning(id, { timeoutMs?, pollIntervalMs?, signal? }) | Polls until the rental is running, every 2 seconds for up to 2 minutes by default. | InstanceDetail |
waitForJob(id, { timeoutMs?, pollIntervalMs?, signal? }) | Polls until the job is done, every 2 seconds for up to 10 minutes by default. | Job |
x402.generate(kind, body, { signer, maxAmountBaseUnits?, rpcUrl?, signal? }) | Pays one generation over x402 from signer, a Keypair or a wallet signer. | X402GenerationResponse |
#x402
x402.generate(kind, body, options) makes one challenge and one payment, and never retries a payment. It checks that the 402 asks for USDC with the mint the API's configuration names, and that the network matches the RPC.
| Option | Meaning |
|---|---|
signer | A Keypair, or a wallet signer: { address, signTransaction({ transaction, chain }) } returning the signed bytes. The SDK refuses a signed payment whose message the wallet changed. |
maxAmountBaseUnits (optional) | Most it will pay, in USDC atoms. A higher price throws before anything is signed. |
rpcUrl (optional) | Solana RPC; required off mainnet. |
signal (optional) | An AbortSignal. |
#Renting over x402
rentX402, extendX402 and stopX402 rent, extend and stop a GPU over x402 with no token. signer is { publicKey, signTransaction(transaction) }: the SDK builds the channel open and asks the signer for it, so it never holds a key. onQuote sees the locked rate and ceiling before anything is signed, and maxUsd refuses a ceiling above it. Rent a GPU over x402 runs one.
#Errors
An API error throws ApiClientError with code, status and the error body. A wait that ends in a failed instance or job throws ShaderStateError with resource, id and state. A wait that times out throws the abort reason and leaves the rental or job running; find it again with instances() or jobs().