Documentation
¶
Overview ¶
Package runpod is the Runpod v2 API client. It wires the per-tag clients generated from spec/openapi.yaml (see generator/) behind one authenticated, retrying HTTP client.
client, err := runpod.New() // key from RUNPOD_API_KEY gpus, err := client.Catalog.ListGpuTypesWithResponse(ctx, nil)
Example ¶
Example is the README's usage section, compiled. It has no output comment, so `go test` builds it and never runs it. The point is that a regeneration that moves a request shape breaks the build here instead of breaking the first code a new user copies.
package main
import (
"context"
"fmt"
"log"
runpod "github.com/runpod/go-sdk/v2"
"github.com/runpod/go-sdk/v2/lib/pods"
"github.com/runpod/go-sdk/v2/lib/types"
)
func main() {
ctx := context.Background()
client, err := runpod.New() // key from RUNPOD_API_KEY
if err != nil {
log.Fatal(err)
}
// The *WithResponse methods return a response wrapper: err covers
// transport, body-read and decode failures. An API-level error arrives as
// a status code, which CheckResponse turns into an *APIError.
gpus, err := client.Catalog.ListGpuTypesWithResponse(ctx, nil)
if err != nil {
log.Fatal(err)
}
if err := runpod.CheckResponse(gpus.HTTPResponse, gpus.Body); err != nil {
log.Fatal(err)
}
for _, gpu := range gpus.JSON200.Gpus {
fmt.Println(gpu.Id, gpu.Memory)
}
created, err := client.Pods.CreatePodWithResponse(ctx, pods.CreatePodJSONRequestBody{
Name: "training-pod",
Image: runpod.Ptr("runpod/pytorch:2.8.0-py3.11-cuda12.8.1-cudnn-devel-ubuntu22.04"),
Gpu: &types.CreateGpuConfig{Id: "NVIDIA GeForce RTX 4090", Count: runpod.Ptr(1)},
})
if err != nil {
log.Fatal(err)
}
if err := runpod.CheckResponse(created.HTTPResponse, created.Body); err != nil {
log.Fatal(err)
}
// A 201 is the pod; a 202 (only with queue set) means it is queued.
if pod := created.JSON201; pod != nil {
fmt.Println(pod.Id)
}
}
Output:
Example (Pagination) ¶
Example_pagination is the README's paging block, compiled on the same terms. A list call without a cursor loop returns one page, not the whole set, so this is the shape a caller that wants everything has to write.
package main
import (
"context"
"fmt"
"log"
runpod "github.com/runpod/go-sdk/v2"
"github.com/runpod/go-sdk/v2/lib/pods"
"github.com/runpod/go-sdk/v2/lib/types"
)
func main() {
ctx := context.Background()
client, err := runpod.New()
if err != nil {
log.Fatal(err)
}
var all []types.Pod
params := &pods.ListPodsParams{}
for {
page, err := client.Pods.ListPodsWithResponse(ctx, params)
if err != nil {
log.Fatal(err)
}
if err := runpod.CheckResponse(page.HTTPResponse, page.Body); err != nil {
log.Fatal(err)
}
all = append(all, page.JSON200.Pods...)
if !page.JSON200.Pagination.HasNextPage {
break
}
params.Cursor = page.JSON200.Pagination.NextCursor
}
fmt.Println(len(all))
}
Output:
Index ¶
- Constants
- func BuildVersion() string
- func CheckResponse(resp *http.Response, body []byte) error
- func Ptr[T any](v T) *T
- type APIError
- type Client
- type Option
- func WithAPIKey(key string) Option
- func WithBaseURL(url string) Option
- func WithHTTPClient(c *http.Client) Option
- func WithIntegration(name string) Option
- func WithNoRedirect() Option
- func WithSessionID(id string) Option
- func WithTimeout(d time.Duration) Option
- func WithTransport(rt http.RoundTripper) Option
- func WithUserAgent(agent string) Option
Examples ¶
Constants ¶
const DefaultBaseURL = "https://api.runpod.io"
DefaultBaseURL is the production API host; spec paths carry the /v2 prefix.
const Version = "2.4.0"
Version is this module's release; release.yml reads this line to tag it. Bump it in the same commit as the CHANGELOG.md entry.
Variables ¶
This section is empty.
Functions ¶
func BuildVersion ¶ added in v2.3.0
func BuildVersion() string
BuildVersion reports the version of this module linked into the running binary, read from Go's build information, without the leading "v". When Go recorded none (a local replace, this module's own tests) it is Version with a "-dev" suffix. The User-Agent header carries it.
func CheckResponse ¶ added in v2.3.0
CheckResponse returns nil for a 2xx response and an *APIError otherwise. Pass it a result's HTTPResponse and Body:
res, err := client.Pods.GetPodWithResponse(ctx, id)
if err != nil { ... }
if err := runpod.CheckResponse(res.HTTPResponse, res.Body); err != nil { ... }
Types ¶
type APIError ¶ added in v2.3.0
type APIError struct {
StatusCode int
Title string
Detail string
// Errors lists the request-validation failures.
Errors []string
// Body is the raw response body, always set.
Body []byte
}
APIError is an error response from the API, carrying the problem details (RFC 9457) it sends as application/problem+json.
Title, Detail and Errors are set only when the body parsed as problem JSON. A response that did not (a proxy's HTML error page, for example) leaves them empty, so check Body or StatusCode before relying on them.
type Client ¶
type Client struct {
Pods *pods.ClientWithResponses
Serverless *serverless.ClientWithResponses
Templates *templates.ClientWithResponses
NetworkVolumes *networkvolumes.ClientWithResponses
GlobalVolumes *globalvolumes.ClientWithResponses
Registries *registries.ClientWithResponses
Catalog *catalog.ClientWithResponses
Billing *billing.ClientWithResponses
Clusters *clusters.ClientWithResponses
Account *account.ClientWithResponses
Organization *organization.ClientWithResponses
AuditLogs *auditlogs.ClientWithResponses
CostCenters *costcenters.ClientWithResponses
Tags *tags.ClientWithResponses
}
Client bundles one authenticated client per API area. Signup is the one tag it leaves out: those operations declare no auth, and a caller making them has no key yet. Use lib/signup directly.
type Option ¶
type Option func(*options)
Option configures New. The With* functions in this package are its implementations.
func WithAPIKey ¶
WithAPIKey overrides the RUNPOD_API_KEY environment variable.
func WithBaseURL ¶
WithBaseURL points the client at a non-production API, e.g. stage, and overrides the RUNPOD_API_BASE_URL environment variable. The URL names the host without the API version: a trailing /v2 is dropped, because every operation path starts with /v2, and any other version segment is an error.
func WithHTTPClient ¶
WithHTTPClient replaces the default HTTP client entirely: no SDK timeout, retry or rate-limit pacing applies unless the client brings its own.
func WithIntegration ¶ added in v2.3.0
WithIntegration names the tool built on the SDK, e.g. "terraform", which the User-Agent then carries as Integration/<name>. The name may use letters, digits, '.', '_' and '-', up to 64 characters. The RUNPOD_UA_INTEGRATION environment variable adds a second token when it names something else.
func WithNoRedirect ¶ added in v2.3.0
func WithNoRedirect() Option
WithNoRedirect stops the client from following redirects: a 3xx response comes back to the caller as is, Location header included. Ignored with WithHTTPClient.
func WithSessionID ¶ added in v2.3.0
WithSessionID sends id as the X-Runpod-Session-Id header on every request, to group the requests of one session. Off by default.
func WithTimeout ¶ added in v2.3.0
WithTimeout bounds each call, retries and rate-limit waits included. The default is 60 seconds; 0 means no bound and a negative value is an error. The log streams are bounded too: for a long one use 0 and the request's context. Retry-After is honored up to 60s, or just under a shorter timeout. Ignored with WithHTTPClient.
func WithTransport ¶ added in v2.3.0
func WithTransport(rt http.RoundTripper) Option
WithTransport sets the http.RoundTripper requests go out through, e.g. for a proxy or custom TLS, beneath the SDK's retry and rate-limit layers, which stay in place. Ignored with WithHTTPClient.
func WithUserAgent ¶
WithUserAgent replaces the SDK's own User-Agent, for a tool that wants its requests attributed to itself.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
agent
Package agent names the AI coding agent, if any, whose process is calling the API, for the User-Agent header.
|
Package agent names the AI coding agent, if any, whose process is calling the API, for the User-Agent header. |
|
Package legacy is a hand-written client for the Runpod GraphQL endpoint, used only by the Terraform provider's deprecated compatibility shims.
|
Package legacy is a hand-written client for the Runpod GraphQL endpoint, used only by the Terraform provider's deprecated compatibility shims. |
|
lib
|
|
|
account
Package account provides primitives to interact with the openapi HTTP API.
|
Package account provides primitives to interact with the openapi HTTP API. |
|
auditlogs
Package auditlogs provides primitives to interact with the openapi HTTP API.
|
Package auditlogs provides primitives to interact with the openapi HTTP API. |
|
billing
Package billing provides primitives to interact with the openapi HTTP API.
|
Package billing provides primitives to interact with the openapi HTTP API. |
|
catalog
Package catalog provides primitives to interact with the openapi HTTP API.
|
Package catalog provides primitives to interact with the openapi HTTP API. |
|
clusters
Package clusters provides primitives to interact with the openapi HTTP API.
|
Package clusters provides primitives to interact with the openapi HTTP API. |
|
costcenters
Package costcenters provides primitives to interact with the openapi HTTP API.
|
Package costcenters provides primitives to interact with the openapi HTTP API. |
|
globalvolumes
Package globalvolumes provides primitives to interact with the openapi HTTP API.
|
Package globalvolumes provides primitives to interact with the openapi HTTP API. |
|
networkvolumes
Package networkvolumes provides primitives to interact with the openapi HTTP API.
|
Package networkvolumes provides primitives to interact with the openapi HTTP API. |
|
organization
Package organization provides primitives to interact with the openapi HTTP API.
|
Package organization provides primitives to interact with the openapi HTTP API. |
|
pods
Package pods provides primitives to interact with the openapi HTTP API.
|
Package pods provides primitives to interact with the openapi HTTP API. |
|
registries
Package registries provides primitives to interact with the openapi HTTP API.
|
Package registries provides primitives to interact with the openapi HTTP API. |
|
serverless
Package serverless provides primitives to interact with the openapi HTTP API.
|
Package serverless provides primitives to interact with the openapi HTTP API. |
|
signup
Package signup provides primitives to interact with the openapi HTTP API.
|
Package signup provides primitives to interact with the openapi HTTP API. |
|
tags
Package tags provides primitives to interact with the openapi HTTP API.
|
Package tags provides primitives to interact with the openapi HTTP API. |
|
templates
Package templates provides primitives to interact with the openapi HTTP API.
|
Package templates provides primitives to interact with the openapi HTTP API. |
|
types
Package types provides primitives to interact with the openapi HTTP API.
|
Package types provides primitives to interact with the openapi HTTP API. |
|
Package transport provides the HTTP retry layer and the RateLimit pacing layer that runpod.New installs.
|
Package transport provides the HTTP retry layer and the RateLimit pacing layer that runpod.New installs. |