Install
Use Go 1.22 or later. Run this command inside a Go module:Authenticate
Create an API key in the Dedalus Dashboard, then set it in the environment:dedalus.NewClient() reads DEDALUS_API_KEY automatically.
Create a machine
This creates a machine with 1 vCPU, 4,096 MiB of memory, 10 GiB of storage, and autosleep after five idle minutes:machine.MachineID in later requests for this machine.
Machine creation is asynchronous. The response contains the requested state and the machine’s current lifecycle status. You can submit an execution immediately after creation. Dedalus waits for the machine to start before running the command.
Run a command
An execution is one command run inside a machine. Creating an execution returns anExecutionID before the command finishes. Use that ID to check the command’s status and retrieve its output.
This function writes a file, reads it back, and waits for the execution to finish:
failed. Check the execution status before using its output.
TimeoutMs limits how long the command can run inside the machine. The execution continues independently of your application’s polling loop until it finishes, is cancelled, expires, or reaches that timeout. See Executions for working directories, environment variables, input, cancellation, and output limits.
Reuse the machine
Dedalus Machines are persistent. Save the machine ID to reuse the same filesystem across application sessions. In a later application session, retrieve the saved ID:machine contains the machine’s current state.
Submit another execution with machine.MachineID to continue working. Executions wake a sleeping machine automatically. Sleep preserves files on the root filesystem and resets processes and memory. See persistence for the complete lifecycle contract.
When you no longer need the machine or its files, explicitly request deletion:
Watch lifecycle changes
WatchStreaming streams machine state changes using server-sent events (SSE).
DesiredState is the requested state. Status.Phase is the machine’s current state. This function requests sleep and reads updates until the machine is sleeping:
defer stream.Close() closes the open stream when the function returns.
The stream closes when the machine reaches its desired state, reports a terminal error, or the five-minute watch limit expires. The final retrieve confirms the machine’s current state.
List machines
Machine lists are paginated.Limit sets the number of machines requested in each page, and Cursor continues from a previous page.
Use ListAutoPaging to fetch pages automatically:
Items and call GetNextPage() only when you want another request. A nil page means there are no more pages.
Configure requests
Pass options todedalus.NewClient(...) for every request, or after a method’s parameter struct for one request.
Retries and timeouts
The SDK retries connection failures, HTTP 408, 409, 429, and 5xx responses twice by default, with increasing delays between attempts. An explicitx-should-retry response header overrides the status-based decision.
A context deadline limits the entire call, including retries. option.WithRequestTimeout limits each attempt separately. Neither adds a timeout unless you configure it.
SDK methods
The SDK groups related methods under services. Every method accepts a context and a parameter struct. Check its returned error before using the result.
Use the API reference for every request field and response field.
Handle errors
An API request and a command can fail independently. A nil error fromExecutions.Get can accompany a failed command: check execution.Status, ExitCode, ErrorMessage, and captured Stderr before using its results.
After an HTTP timeout, use the execution ID to retrieve the existing execution. Submitting another command creates another execution. Request deadlines control HTTP waiting, execution TimeoutMs controls command runtime, and machine Autosleep controls idle compute.
Unsuccessful HTTP responses return *dedalus.Error. Use errors.As to inspect StatusCode and RawJSON():
error_code, message, and retryable are not named Go struct fields. Decode RawJSON() into your own type when your application needs them.
Advanced client options
Work with request and response fields
Optional primitive request fields useparam.Opt[T]. Constructors such as dedalus.String("5m") and dedalus.Int(20) set them. Use param.Null[T]() only when the API permits an explicit JSON null.
Response structs expose values directly and keep JSON metadata in a JSON field. Check response.JSON.Field.Valid() before interpreting an optional field’s zero value. Use response.RawJSON() for the original response.
Inspect HTTP responses
Useoption.WithResponseInto when you need the HTTP status or headers with the parsed result:
Logging
Passoption.WithDebugLog(nil) to use the default debug logger, or provide a log.Logger.
Customize HTTP requests
Useoption.WithHTTPClient to supply an HTTP client with your proxy, transport, or connection settings. Use option.WithMiddleware to add application-specific timing or diagnostics around requests.
Requests beyond the generated types
client.Get, client.Post, and the other HTTP methods let you call endpoints that do not have service methods. Client options such as authentication and retries still apply.
Use option.WithQuerySet for extra query parameters and option.WithJSONSet for body fields.
Multipart file uploads
For endpoints that accept multipart files, upload parameters useio.Reader. Wrap a reader with dedalus.File(reader, filename, contentType) to set the filename and content type.
