Guides
- Quickstart
- Quickstarts by language
- Migration guides
- Authentication and keys
- Key protection
- Models, aliases and fallbacks
- Automatic model choice (silicon/auto)
- Chat completions
- Streaming
- Structured outputs and tools
- Logprobs
- Vision
- Responses, Claude and Ollama
- Embeddings, rerank, audio, images
- Files and batches
- Documents and search
- LoRA adapters
- Project tags and costs
- Prefix caching
- Headers, rate limits and spend caps
- Errors
- Versioning and the sandbox
- Privacy and retention
- Verifiable receipts
- Data residency
- Pricing
- Billing
- Pay per request (x402)
- On-chain oracle
- Agent credit (backed compute lines)
- Status
- SDKs
- Swift SDK
- Integrations
- Run a node
- Linux agent
- Mac mini fleets
- Compute API
- Architecture
- Changelog
- Glossary
API reference
Quickstart
TypeScript quickstart
The @siliconnetwork/sdk package: no runtime dependencies, typed requests and answers, streaming. Node 20 or newer, Bun, Deno and browsers.
1. Install and set the key
npm install @siliconnetwork/sdk # not on npm yet? clone the repository and install it from therenpm install ./siliconnetwork/sdks/typescript export SILICON_API_KEY=sn_live_...Create the key on the API Keys page. The client reads SILICON_API_KEY, or takes apiKey. The files below use top level await, so run them as ES modules: for example with npx tsx chat.ts in a project whose package.json has "type": "module".
In a browser, anyone can read a key shipped in the page. Call the API from your server, or use a scoped key with a spend cap (see Key protection).
2. One chat completion
import { SiliconNetwork } from "@siliconnetwork/sdk"; const client = new SiliconNetwork(); // reads SILICON_API_KEY const out = await client.chat.completions.create({ model: "llama-3.2-3b", messages: [{ role: "user", content: "Say hello in one line." }],});console.log(out.choices[0].message.content);console.log(out.meta.requestId, out.meta.model, out.meta.node);meta carries the gateway's headers: the request id (quote it to support), the model that served and the node. Silicon Network body fields such as models: ["fast"] (fallbacks) pass through as extra fields.
3. Stream the answer
import { SiliconNetwork } from "@siliconnetwork/sdk"; const client = new SiliconNetwork(); const stream = await client.chat.completions.stream({ model: "llama-3.2-3b", messages: [{ role: "user", content: "Write a haiku about silicon." }],});for await (const chunk of stream) { process.stdout.write(chunk.choices[0]?.delta?.content ?? "");}process.stdout.write("\n");create({ ..., stream: true }) returns the same stream. The promise settles once the gateway accepted the request, so a 402 or 429 rejects before any output.
4. List the models
import { SiliconNetwork } from "@siliconnetwork/sdk"; const client = new SiliconNetwork(); const models = await client.models.list();for (const model of models.data) console.log(model.id);The list is what the network is serving now. Any id or alias in it works as model.
5. Handle an error
import { SiliconError, SiliconNetwork } from "@siliconnetwork/sdk"; const client = new SiliconNetwork(); try { const out = await client.chat.completions.create({ model: "llama-3.2-3b", messages: [{ role: "user", content: "Say hello in one line." }], }); console.log(out.choices[0].message.content);} catch (err) { if (!(err instanceof SiliconError)) throw err; if (err.isOutOfCredits) console.error("Add balance on the Billing page:", err.message); else if (err.isRateLimited) console.error(`Rate limited; retry after ${err.retryAfter} s`); else console.error(err.status, err.code, err.message, err.requestId);}| Field | Meaning |
|---|---|
| status | The HTTP status: 401 bad key, 402 out of credits or over a spend cap, 403 not allowed, 429 rate limited, 5xx the gateway or node failed. |
| code | The machine code, when the body carried one. |
| requestId | The gateway's request id; quote it to support. |
| retryAfter | Seconds to wait, when the gateway said so. |
| isOutOfCredits, isRateLimited | 402 and 429. |
Non-streaming calls retry 429 and 5xx twice by default, honoring Retry-After; set maxRetries on the client to change that. Next: Streaming, Structured outputs and tools, Errors.