pub struct ServerlessEndpoint { /* private fields */ }Available on crate feature
serverless only.Expand description
Class for running jobs on a specific endpoint.
§Examples
use runpod_sdk::{RunpodClient, Result};
use runpod_sdk::serverless::ServerlessEndpoint;
use serde_json::json;
let client = RunpodClient::from_env()?;
let endpoint = ServerlessEndpoint::new("YOUR_ENDPOINT_ID", client);
let job = endpoint.run(&json!({"prompt": "Hello, world!"}))?;
let output: serde_json::Value = job.await?;Implementations§
Source§impl ServerlessEndpoint
impl ServerlessEndpoint
Sourcepub fn new(endpoint_id: impl Into<String>, client: RunpodClient) -> Self
pub fn new(endpoint_id: impl Into<String>, client: RunpodClient) -> Self
Sourcepub fn endpoint_id(&self) -> &str
pub fn endpoint_id(&self) -> &str
Returns the endpoint ID.
Sourcepub fn run<I>(&self, input: &I) -> Result<ServerlessJob>where
I: Serialize,
pub fn run<I>(&self, input: &I) -> Result<ServerlessJob>where
I: Serialize,
Runs a job on the endpoint.
§Arguments
input- The input payload for the job
§Returns
Returns a Job instance that implements Future for retrieving results. The job submission happens when you first poll the Job (e.g., by awaiting it).
§Example
let client = RunpodClient::from_env()?;
let endpoint = ServerlessEndpoint::new("ENDPOINT_ID", client);
let job = endpoint.run(&Input {
prompt: "Hello, World!".to_string()
})?;
let output: serde_json::Value = job.await?;
println!("Job result: {:?}", output);Sourcepub async fn run_now<I, O>(&self, input: &I) -> Result<O>where
I: Serialize,
O: DeserializeOwned,
pub async fn run_now<I, O>(&self, input: &I) -> Result<O>where
I: Serialize,
O: DeserializeOwned,
Runs a job and immediately waits for the result.
This is a convenience method that runs a job and awaits its completion.
§Example
let client = RunpodClient::from_env()?;
let endpoint = ServerlessEndpoint::new("ENDPOINT_ID", client);
let output: serde_json::Value = endpoint.run_now(&json!({"prompt": "Hello"})).await?;
println!("Result: {:?}", output);Sourcepub async fn health(&self) -> Result<EndpointHealth>
pub async fn health(&self) -> Result<EndpointHealth>
Checks the health of the endpoint.
§Example
let client = RunpodClient::from_env()?;
let endpoint = ServerlessEndpoint::new("ENDPOINT_ID", client);
let health = endpoint.health().await?;
println!("Workers ready: {}", health.workers.ready);
println!("Jobs in queue: {}", health.jobs.in_queue);Sourcepub async fn purge_queue(&self) -> Result<()>
pub async fn purge_queue(&self) -> Result<()>
Purges all jobs from the endpoint’s queue.
§Example
let client = RunpodClient::from_env()?;
let endpoint = ServerlessEndpoint::new("ENDPOINT_ID", client);
endpoint.purge_queue().await?;
println!("Queue purged");Trait Implementations§
Source§impl Clone for ServerlessEndpoint
impl Clone for ServerlessEndpoint
Source§fn clone(&self) -> ServerlessEndpoint
fn clone(&self) -> ServerlessEndpoint
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ServerlessEndpoint
impl !RefUnwindSafe for ServerlessEndpoint
impl Send for ServerlessEndpoint
impl Sync for ServerlessEndpoint
impl Unpin for ServerlessEndpoint
impl !UnwindSafe for ServerlessEndpoint
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more