Shader
First rental with the SDK

DocsStart3 of 35 · 1 min read

First rental with the SDK

Rent a GPU, wait for it, stop it and generate a file from TypeScript with an agent token.

The SDK acts with an agent token, so make a key first in Create an agent key, with caps that cover the GPU's rate for 1 hour, and put credits in its wallet.

#Rent and generate

  1. Install

    The SDK runs on Node 26 and installs @shader/contract, @solana/web3.js and @solana/spl-token with it.

  2. Save the script

    It reads the balance, rents an RTX 4090, waits for it, stops it in finally, then generates a 3D asset.

    rent-and-generate.ts
    import { Shader } from '@shader/sdk'
    
    const shader = new Shader({ token: process.env.SHADER_TOKEN, baseUrl: process.env.SHADER_API_URL })
    
    const { totalBaseUnits } = await shader.balance()
    console.log('balance', totalBaseUnits)
    
    const rented = await shader.rent({ gpu: 'rtx-4090-24gb', sshPublicKey: process.env.SSH_PUBLIC_KEY })
    try {
      const instance = await shader.waitUntilRunning(rented.id)
      console.log('running', instance.id, instance.ssh?.command)
    } finally {
      const { instance } = await shader.stop(rented.id)
      console.log('stopping', instance.state)
    }
    
    const job = await shader.generate({ kind: 'asset3d', prompt: 'a small wooden chair' })
    const done = await shader.waitForJob(job.id)
    console.log('done', done.result?.url, done.chargedCreditsBaseUnits, done.receipt?.signature)
  3. Run it

    Terminal
    SHADER_TOKEN=shdr_<YOUR_AGENT_TOKEN> SSH_PUBLIC_KEY="$(cat ~/.ssh/id_ed25519.pub)" node rent-and-generate.ts
  4. Read the output

    A run against a local Shader printed:

    Output
    balance 154078630
    running a1a2f748-243e-4a8c-9589-d215ce9da49d ssh shader@127.0.0.1 -p 4840
    stopping settling
    done http://127.0.0.1:4710/files/f53db07a-09c3-4698-a04a-8fa5be4511be-0.glb 200000 3PgsH6BSaryGURqhaNX6U6kD8ta5FCEWEZYKXFWbEjwBDhNKjcJAEJJ6yp9TJ5ZLpyoK82NZMvhPUDimwDGRKAJy

#What happened

  1. Rent

    rent launched the machine, and waitUntilRunning polled until SSH and Jupyter answered.

  2. Stop

    stop in finally ended it even if the work had thrown. It answers at settling; the final settlement lands a moment later.

  3. Generate

    The 3D job settled once when its file was stored: 200 credits, 200,000 base units.

#Read what it cost

receipts.ts
const { items } = await shader.receipts({ limit: 5 })
for (const line of items) console.log(line.occurredAt, line.kind, line.units, line.unit, line.creditsBaseUnits, line.signature)

Every option and method is in SDK. To pay over x402 from a wallet instead of a token, see Pay over x402.