Call Compute with Go contexts
How to read a Compute job from Go with a context deadline, handle typed errors, and retry safely with the same idempotency key.
Create a client with lithi.NewClient for one context-bound job read. Your existing agent keeps
its model, goal, project context and final decision; this client exposes the current API operations.
Handle deadlines separately from server-side job cancellation.
1. Construct a context-aware client
Use the Go source supplied in the kit's local sdk/go directory and call lithi.NewClient(base, credential). Its module identity is github.com/lithi-ai/compute-kit/sdk/go, but that identity
does not imply a public registry download: point your application's module replacement at the
supplied local directory. The credential has type func(context.Context) (string, error). The
client requires an HTTPS base URL, and each operation receives the caller's context.Context.
The defaults are a 30-second request timeout, two retries, and a 4 MiB response limit. You may set
Timeout, MaxRetries, MaxResponseBytes, HTTP, and Credentials on the returned client within
their documented bounds. The Go adapter does not admit plain HTTP localhost.
2. Make a synthetic job read
This example injects an http.RoundTripper, so it checks request and response handling without
opening a connection.
package example
import (
"context"
"fmt"
"io"
"net/http"
"strings"
lithi "github.com/lithi-ai/compute-kit/sdk/go"
)
type roundTrip func(*http.Request) (*http.Response, error)
func (f roundTrip) RoundTrip(r *http.Request) (*http.Response, error) { return f(r) }
func Example() error {
key := "lthi_cmp_" + "0123456789abcdef" + "." + "0123456789012345678901234567890123456789012"
client, err := lithi.NewClient("https://api.example.test", func(context.Context) (string, error) {
return key, nil
})
if err != nil { return err }
client.HTTP = &http.Client{Transport: roundTrip(func(*http.Request) (*http.Response, error) {
body := `{"ok":true,"data":{"job_id":"550e8400-e29b-41d4-a716-446655440000","state":"queued","state_version":1,"digest":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","p_next_action":"none"}}`
return &http.Response{
StatusCode: 200,
Header: http.Header{"Content-Type": []string{"application/json"}},
Body: io.NopCloser(strings.NewReader(body)),
}, nil
})}
job, err := client.GetJob(context.Background(), "550e8400-e29b-41d4-a716-446655440000")
if err != nil { return err }
fmt.Println(job)
return nil
}The key, URL, job ID, and response are synthetic. GetJob receives the context and returns a
projection; it doesn't wait for completion.
3. Use exported operation methods
The client exposes CreateQuote, CreateJob, GetJob, CancelJob, ListJobEvents,
GetJobResult, CreateBatch, GetBatch, ListBatchResults, PrepareArtifact,
CompleteArtifact, ListCapabilities, ListUsage, GetReceipt, ListAgentEvents,
CompatibilityOpenaiResponses, CompatibilityOpenaiChatCompletions,
CompatibilityOpenaiEmbeddings, and CompatibilityAwsBatch. POST methods take a stable key;
resource reads do not. Page methods take an explicit limit and cursor string.
Request bodies are limited to 64 KiB and responses to 4 MiB. Retryable HTTP statuses are 408, 425,
429, 500, 502, 503, and 504. Context cancellation returns SDK_ABORTED; a deadline returns
SDK_TIMEOUT. Neither one cancels an admitted server job.
4. Recover with typed errors and result metadata
lithi.Error carries Code, HTTP Status, ServerCode, and NextAction. Check the typed code
before deciding whether to correct input, refresh access, or inspect a transient failure. A job
projection reports state, version, digest, and next action. GetJobResult reports encrypted
artifact metadata and digests; retrieve authorized bytes separately, then verify their digest and
media type.
When a POST outcome is uncertain, preserve the body and idempotency key, read the existing job, and
reuse the same intent. Call CancelJob only for an explicit server cancellation request.
Use the compatibility matrix to match versions, then read the Work API reference for exact payloads.
The Go wire client has no monthly-report operation. Reading that report needs separate permission and an approved reporting API or file path; it remains outside the five MCP work tools.
Go supplies the wire client
The supplied Go client covers Compute wire operations, typed response validation, request serialization, retries and context cancellation. It does not include the TypeScript Kit's local record preparation, pseudonymization, compile/seal workflow or complete result-delivery steps. Check the client matrix before choosing caller-supplied helpers. Your agent keeps its goal, context and final decision; SDK methods do not grant transfer or execution authority.
For the same support-ticket example, read What leaves your machine before sending prepared data, then use result verification and result delivery. The separate Kit helper reference shows which local helpers exist in other language surfaces.
See Kit contents for the supplied modules and workflow guides.