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
Go quickstart
The Go client: standard library only, context aware, Go 1.22 or newer. Typed chat completions with streaming, models, embeddings, rerank and compute.
1. Add the module and set the key
The Go client is not published yet. It lives in the repository at sdks/go; point your module at a local checkout.
go mod edit -require=github.com/ekempinski/siliconnetwork/sdks/go@v0.0.0go mod edit -replace=github.com/ekempinski/siliconnetwork/sdks/go=/path/to/siliconnetwork/sdks/go export SILICON_API_KEY=sn_live_...With access to the repository, go get github.com/ekempinski/siliconnetwork/sdks/go@main works too. sn.NewClient() reads SILICON_API_KEY and SILICON_BASE_URL; sn.WithAPIKey and sn.WithBaseURL set them in code.
2. One chat completion, with errors handled
package main import ( "context" "errors" "fmt" "log" sn "github.com/ekempinski/siliconnetwork/sdks/go") func main() { client, err := sn.NewClient() // reads SILICON_API_KEY if err != nil { log.Fatal(err) } ctx := context.Background() out, err := client.ChatCompletion(ctx, sn.ChatCompletionRequest{ Model: "llama-3.2-3b", Messages: []sn.ChatMessage{sn.UserMessage("Say hello in one line.")}, }) var apiErr *sn.APIError switch { case errors.As(err, &apiErr) && apiErr.IsOutOfCredits(): log.Fatalf("add balance on the Billing page: %s", apiErr.Message) case errors.As(err, &apiErr) && apiErr.IsRateLimited(): log.Fatalf("rate limited; retry after %s", apiErr.RetryAfter) case errors.As(err, &apiErr): log.Fatalf("%d %s (request %s)", apiErr.StatusCode, apiErr.Message, apiErr.RequestID) case err != nil: log.Fatal(err) // no answer: network, TLS, timeout } fmt.Println(out.Text()) fmt.Println(out.Meta.RequestID)}3. Stream the answer
stream, err := client.ChatCompletionStream(ctx, sn.ChatCompletionRequest{ Model: "llama-3.2-3b", Messages: []sn.ChatMessage{sn.UserMessage("Write a haiku about silicon.")},})if err != nil { log.Fatal(err)}defer stream.Close()for stream.Next() { if c := stream.Chunk(); len(c.Choices) > 0 { fmt.Print(c.Choices[0].Delta.Content) }}if err := stream.Err(); err != nil { log.Fatal(err)}fmt.Println()stream.Text() and stream.Final() return the joined text or the whole completion instead. Streams are not retried and run until their context ends.
4. List the models
models, err := client.ListModels(ctx)if err != nil { log.Fatal(err)}for _, m := range models.Data { fmt.Println(m.ID, m.Aliases)}5. Errors
| Field | Meaning |
|---|---|
| StatusCode | 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. |
| Message, Code | The message and machine code from the body. |
| RequestID | The gateway's request id; quote it to support. |
| RetryAfter | The wait the gateway asked for, or 0. |
| IsOutOfCredits(), IsRateLimited() | 402 and 429. |
Non-streaming calls retry 429 and 5xx twice, honoring Retry-After (at most 30 seconds); sn.WithMaxRetries and sn.WithTimeout change that. The README in sdks/go covers embeddings, rerank, compute and the generated route methods.