pub struct RunpodClient { /* private fields */ }Expand description
Main RunPod API client for interacting with all RunPod services.
The RunpodClient provides access to all RunPod API endpoints through specialized
service interfaces. It handles authentication, request/response serialization,
and provides a consistent async interface for all operations.
§Features
- Thread-safe: Safe to use across multiple threads
- Cheap to clone: Uses
Arcinternally for efficient cloning - Automatic authentication: Handles API key authentication automatically
- Comprehensive coverage: Access to all RunPod services (Pods, Endpoints, Templates, etc.)
§Services
The client implements V1 API service traits that provide direct access to API methods:
PodsService- Pod lifecycle managementEndpointsService- Serverless endpoint operationsTemplatesService- Template creation and managementVolumesService- Network volume operationsRegistryService- Registry authenticationBillingService- Usage and billing information
§Examples
§Basic usage with environment configuration
use runpod_sdk::{RunpodClient, Result};
use runpod_sdk::model::ListPodsQuery;
use runpod_sdk::service::PodsService;
let client = RunpodClient::from_env()?;
// List all pods
let pods = client.list_pods(ListPodsQuery::default()).await?;
println!("Found {} pods", pods.len());§Custom configuration with builder pattern
use runpod_sdk::{RunpodConfig, RunpodClient, Result};
use runpod_sdk::service::{PodsService, EndpointsService, TemplatesService};
use std::time::Duration;
let client = RunpodConfig::builder()
.with_api_key("your-api-key")
.with_rest_url("https://rest.runpod.io/v1")
.with_timeout(Duration::from_secs(30))
.build_client()?;
// Use different services
let pods = client.list_pods(Default::default()).await?;
let endpoints = client.list_endpoints(Default::default()).await?;
let templates = client.list_templates(Default::default()).await?;§Multi-threaded usage
The client is cheap to clone (uses Arc internally):
use runpod_sdk::{RunpodClient, Result};
use runpod_sdk::service::PodsService;
use tokio::task;
let client = RunpodClient::from_env()?;
let handles: Vec<_> = (0..3).map(|i| {
let client = client.clone();
task::spawn(async move {
let pods = client.list_pods(Default::default()).await?;
println!("Thread {}: Found {} pods", i, pods.len());
Ok::<(), runpod_sdk::Error>(())
})
}).collect();
for handle in handles {
handle.await.unwrap()?;
}Implementations§
Source§impl RunpodClient
impl RunpodClient
Sourcepub fn new(config: RunpodConfig) -> Result<Self>
pub fn new(config: RunpodConfig) -> Result<Self>
Creates a new Runpod API client.
Sourcepub fn builder() -> RunpodBuilder
pub fn builder() -> RunpodBuilder
Creates a new configuration builder for constructing a RunPod client.
This is a convenience method that returns a RunpodConfigBuilder for building
a custom client configuration.
§Example
let client = RunpodClient::builder()
.with_api_key("your-api-key")
.with_timeout(Duration::from_secs(60))
.build_client()?;Sourcepub fn from_env() -> Result<Self>
pub fn from_env() -> Result<Self>
Creates a new Runpod API client from environment variables.
This is a convenience method that creates a RunpodConfig from environment variables and then creates a client from that config.
§Environment Variables
RUNPOD_API_KEY- Your RunPod API key (required)RUNPOD_BASE_URL- Base URL for the API (optional, defaults to https://rest.runpod.io/v1)RUNPOD_TIMEOUT_SECS- Request timeout in seconds (optional, defaults to 30)
§Example
let client = RunpodClient::from_env()?;Trait Implementations§
Source§impl BillingService for RunpodClient
impl BillingService for RunpodClient
Source§async fn get_pod_billing(
&self,
query: PodBillingQuery,
) -> Result<BillingRecords>
async fn get_pod_billing( &self, query: PodBillingQuery, ) -> Result<BillingRecords>
Source§async fn get_endpoint_billing(
&self,
query: EndpointBillingQuery,
) -> Result<BillingRecords>
async fn get_endpoint_billing( &self, query: EndpointBillingQuery, ) -> Result<BillingRecords>
Source§async fn get_volume_billing(
&self,
query: NetworkVolumeBillingQuery,
) -> Result<BillingRecords>
async fn get_volume_billing( &self, query: NetworkVolumeBillingQuery, ) -> Result<BillingRecords>
Source§impl Clone for RunpodClient
impl Clone for RunpodClient
Source§fn clone(&self) -> RunpodClient
fn clone(&self) -> RunpodClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more