Go SDK for BlockRun - access multiple LLM providers (OpenAI, Anthropic, Google, etc.) with automatic x402 micropayments on Base chain.
go get github.com/BlockRunAI/blockrun-llm-gopackage main
import (
"fmt"
"log"
blockrun "github.com/blockrun/blockrun-llm-go"
)
func main() {
// Create client (uses BASE_CHAIN_WALLET_KEY env var)
client, err := blockrun.NewLLMClient("")
if err != nil {
log.Fatal(err)
}
// Simple 1-line chat
response, err := client.Chat("openai/gpt-4o", "What is 2+2?")
if err != nil {
log.Fatal(err)
}
fmt.Println(response)
}Your private key NEVER leaves your machine.
Here's what happens when you make a request:
- Your key stays local - only used to sign an EIP-712 typed data message
- Only the SIGNATURE is sent in the
PAYMENT-SIGNATUREheader - BlockRun verifies the signature on-chain via Coinbase CDP facilitator
- Your actual private key is NEVER transmitted to any server
This is the same security model as:
- Signing a MetaMask transaction
- Any on-chain swap or trade
- Standard EIP-3009 TransferWithAuthorization
// From environment variable (BASE_CHAIN_WALLET_KEY)
client, err := blockrun.NewLLMClient("")
// Or pass private key directly
client, err := blockrun.NewLLMClient("0x...")
// With custom timeout (default: 60s)
client, err := blockrun.NewLLMClient("0x...",
blockrun.WithTimeout(120 * time.Second),
)// Basic chat
response, err := client.Chat("openai/gpt-4o", "What is the capital of France?")
// Chat with system prompt
response, err := client.ChatWithSystem(
"openai/gpt-4o",
"Tell me a joke",
"You are a comedian.",
)messages := []blockrun.ChatMessage{
{Role: "system", Content: "You are a helpful assistant."},
{Role: "user", Content: "Hello!"},
}
result, err := client.ChatCompletion("openai/gpt-4o", messages, &blockrun.ChatCompletionOptions{
MaxTokens: 1024,
Temperature: 0.7,
TopP: 0.9,
})
fmt.Println(result.Choices[0].Message.Content)
fmt.Printf("Tokens: %d\n", result.Usage.TotalTokens)models, err := client.ListModels()
for _, model := range models {
fmt.Printf("%s: $%.4f/$%.4f per 1M tokens\n",
model.ID, model.InputPrice, model.OutputPrice)
}address := client.GetWalletAddress()
fmt.Printf("Wallet: %s\n", address)BlockRun provides access to models from multiple providers:
| Provider | Models |
|---|---|
| OpenAI | gpt-4o, gpt-4o-mini, o1, o1-mini |
| Anthropic | claude-sonnet-4, claude-haiku-4 |
| gemini-2.5-pro, gemini-2.5-flash | |
| DeepSeek | deepseek-chat, deepseek-reasoner |
| xAI | grok-3, grok-3-mini |
Use client.ListModels() for the full list with current pricing.
- You make an API request
- Server returns
402 Payment Requiredwith payment details - SDK signs an EIP-712 message locally (key never sent)
- SDK retries with
PAYMENT-SIGNATUREheader - Server verifies signature, settles payment on-chain
- Server returns the AI response
All this happens automatically - you just call Chat() or ChatCompletion().
| Variable | Description | Default |
|---|---|---|
BASE_CHAIN_WALLET_KEY |
Your Base chain wallet private key | Required |
BLOCKRUN_API_URL |
Custom API endpoint | https://blockrun.ai/api |
response, err := client.Chat("openai/gpt-4o", "Hello")
if err != nil {
switch e := err.(type) {
case *blockrun.ValidationError:
fmt.Printf("Invalid input: %s - %s\n", e.Field, e.Message)
case *blockrun.PaymentError:
fmt.Printf("Payment failed: %s\n", e.Message)
case *blockrun.APIError:
fmt.Printf("API error %d: %s\n", e.StatusCode, e.Message)
default:
fmt.Printf("Error: %v\n", err)
}
}- Go 1.21+
- A wallet with USDC on Base chain
MIT