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, so check the typed status field for it.
gpus, err := client.Catalog.ListGpuTypesWithResponse(ctx, nil)
if err != nil {
log.Fatal(err)
}
if gpus.JSON200 == nil {
log.Fatalf("catalog: HTTP %d: %s", gpus.HTTPResponse.StatusCode, gpus.Body)
}
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 created.JSON201 == nil {
log.Fatalf("create pod: HTTP %d: %s", created.HTTPResponse.StatusCode, created.Body)
}
fmt.Println(created.JSON201.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 page.JSON200 == nil {
log.Fatalf("list pods: HTTP %d: %s", page.HTTPResponse.StatusCode, page.Body)
}
all = append(all, page.JSON200.Pods...)
if !page.JSON200.Pagination.HasNextPage {
break
}
params.Cursor = page.JSON200.Pagination.NextCursor
}
fmt.Println(len(all))
}
Output:
Index ¶
Examples ¶
Constants ¶
const DefaultBaseURL = "https://api.runpod.io"
DefaultBaseURL is the production API host; spec paths carry the /v2 prefix.
const Version = "2.2.0"
Version is this module's release, sent in the User-Agent header. Bump it in the same commit as the release tag; CHANGELOG.md records what changed.
Variables ¶
This section is empty.
Functions ¶
Types ¶
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
}
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.
func WithHTTPClient ¶
WithHTTPClient replaces the default retrying HTTP client entirely.
func WithUserAgent ¶
WithUserAgent replaces the SDK's own User-Agent, for a tool that wants its requests attributed to itself.
Directories
¶
| Path | Synopsis |
|---|---|
|
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. |
|
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 shared HTTP retry layer every Runpod client generated from this repo goes through.
|
Package transport provides the shared HTTP retry layer every Runpod client generated from this repo goes through. |