PortkeyClient

Struct PortkeyClient 

Source
pub struct PortkeyClient { /* private fields */ }
Expand description

Main Portkey API client for interacting with all Portkey services.

The PortkeyClient provides access to all Portkey 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 Arc internally for efficient cloning
  • Automatic authentication: Handles API key authentication automatically

§Examples

§Basic usage with environment configuration

use portkey_sdk::{PortkeyClient, Result};

let client = PortkeyClient::from_env()?;

§Custom configuration with builder pattern

use portkey_sdk::{PortkeyConfig, PortkeyClient, Result};
use std::time::Duration;

let client = PortkeyConfig::builder()
    .with_api_key("your-api-key")
    .with_base_url("https://api.portkey.ai/v1")
    .with_timeout(Duration::from_secs(30))
    .build_client()?;

§Multi-threaded usage

The client is cheap to clone (uses Arc internally):

use portkey_sdk::{PortkeyClient, Result};
use tokio::task;

let client = PortkeyClient::from_env()?;

let handles: Vec<_> = (0..3).map(|i| {
    let client = client.clone();
    task::spawn(async move {
        // Use client here
        Ok::<(), portkey_sdk::Error>(())
    })
}).collect();

for handle in handles {
    handle.await.unwrap()?;
}

Implementations§

Source§

impl PortkeyClient

Source

pub fn new(config: PortkeyConfig) -> Result<Self>

Creates a new Portkey API client.

Source

pub fn builder() -> PortkeyBuilder

Creates a new configuration builder for constructing a Portkey client.

This is a convenience method that returns a PortkeyBuilder for building a custom client configuration.

§Example
let client = PortkeyClient::builder()
    .with_api_key("your-api-key")
    .with_auth_method(AuthMethod::VirtualKey {
        virtual_key: "your-virtual-key".to_string(),
    })
    .with_timeout(Duration::from_secs(60))
    .build_client()?;
Source

pub fn from_env() -> Result<Self>

Creates a new Portkey API client from environment variables.

This is a convenience method that creates a PortkeyConfig from environment variables and then creates a client from that config.

§Environment Variables
  • PORTKEY_API_KEY - Your Portkey API key (required)
  • PORTKEY_BASE_URL - Base URL for the API (optional, defaults to https://api.portkey.ai/v1)
  • PORTKEY_TIMEOUT_SECS - Request timeout in seconds (optional, defaults to 30)
§Example
let client = PortkeyClient::from_env()?;

Trait Implementations§

Source§

impl AssistantsService for PortkeyClient

Source§

async fn create_assistant( &self, request: CreateAssistantRequest, ) -> Result<Assistant>

Create an assistant with a model and instructions.
Source§

async fn retrieve_assistant(&self, assistant_id: &str) -> Result<Assistant>

Retrieves an assistant.
Source§

async fn modify_assistant( &self, assistant_id: &str, request: ModifyAssistantRequest, ) -> Result<Assistant>

Modifies an assistant.
Source§

async fn delete_assistant( &self, assistant_id: &str, ) -> Result<DeleteAssistantResponse>

Delete an assistant.
Source§

async fn list_assistants( &self, params: PaginationParams<'_>, ) -> Result<ListAssistantsResponse>

Returns a list of assistants.
Source§

async fn create_assistant_file( &self, assistant_id: &str, request: CreateAssistantFileRequest, ) -> Result<AssistantFile>

Create an assistant file by attaching a File to an assistant.
Source§

async fn retrieve_assistant_file( &self, assistant_id: &str, file_id: &str, ) -> Result<AssistantFile>

Retrieves an AssistantFile.
Source§

async fn delete_assistant_file( &self, assistant_id: &str, file_id: &str, ) -> Result<DeleteAssistantFileResponse>

Delete an assistant file.
Source§

async fn list_assistant_files( &self, assistant_id: &str, params: PaginationParams<'_>, ) -> Result<ListAssistantFilesResponse>

Returns a list of assistant files.
Source§

impl AudioService for PortkeyClient

Source§

async fn create_transcription( &self, file_data: Vec<u8>, file_name: &str, request: CreateTranscriptionRequest, ) -> Result<TranscriptionResponse>

Creates a transcription of an audio file. Read more
Source§

async fn create_speech(&self, request: CreateSpeechRequest) -> Result<Vec<u8>>

Creates speech audio from text input. Read more
Source§

async fn create_translation( &self, file_data: Vec<u8>, file_name: &str, request: CreateTranslationRequest, ) -> Result<TranslationResponse>

Translates audio to English. Read more
Source§

impl BatchesService for PortkeyClient

Source§

async fn create_batch(&self, request: CreateBatchRequest) -> Result<Batch>

Creates and executes a batch from an uploaded file of requests. Read more
Source§

async fn retrieve_batch(&self, batch_id: &str) -> Result<Batch>

Retrieves a batch. Read more
Source§

async fn cancel_batch(&self, batch_id: &str) -> Result<Batch>

Cancels an in-progress batch. Read more
Source§

async fn list_batches( &self, params: PaginationParams<'_>, ) -> Result<ListBatchesResponse>

List your organization’s batches. Read more
Source§

impl ChatService for PortkeyClient

Source§

async fn create_chat_completion( &self, request: ChatCompletionRequest, ) -> Result<ChatCompletionResponse>

Creates a chat completion. Read more
Source§

impl Clone for PortkeyClient

Source§

fn clone(&self) -> PortkeyClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl CompletionsService for PortkeyClient

Source§

async fn create_completion( &self, request: CreateCompletionRequest, ) -> Result<CompletionResponse>

Create a completion for the provided prompt and parameters. Read more
Source§

impl Debug for PortkeyClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl EmbeddingsService for PortkeyClient

Source§

async fn create_embedding( &self, request: CreateEmbeddingRequest, ) -> Result<CreateEmbeddingResponse>

Creates an embedding vector representing the input text. Read more
Source§

impl FeedbackService for PortkeyClient

Source§

async fn create_feedback( &self, request: CreateFeedbackRequest, ) -> Result<FeedbackResponse>

Creates feedback for a trace. Read more
Source§

async fn update_feedback( &self, feedback_id: &str, request: UpdateFeedbackRequest, ) -> Result<FeedbackResponse>

Updates existing feedback by ID. Read more
Source§

impl FilesService for PortkeyClient

Source§

async fn upload_file(&self, request: UploadFileRequest) -> Result<FileObject>

Upload a file that can be used across various endpoints. Read more
Source§

async fn list_files(&self) -> Result<ListFilesResponse>

Returns a list of files that belong to the user’s organization. Read more
Source§

async fn retrieve_file(&self, file_id: &str) -> Result<FileObject>

Returns information about a specific file. Read more
Source§

async fn retrieve_file_content(&self, file_id: &str) -> Result<Vec<u8>>

Returns the contents of the specified file. Read more
Source§

async fn delete_file(&self, file_id: &str) -> Result<DeleteFileResponse>

Delete a file. Read more
Source§

impl FineTuningService for PortkeyClient

Source§

async fn create_fine_tuning_job( &self, request: CreateFineTuningJobRequest, ) -> Result<FineTuningJob>

Creates a fine-tuning job which begins the process of creating a new model from a given dataset. Read more
Source§

async fn list_fine_tuning_jobs( &self, params: PaginationParams<'_>, ) -> Result<ListFineTuningJobsResponse>

List your organization’s fine-tuning jobs. Read more
Source§

async fn retrieve_fine_tuning_job( &self, fine_tuning_job_id: &str, ) -> Result<FineTuningJob>

Get info about a fine-tuning job. Read more
Source§

async fn cancel_fine_tuning_job( &self, fine_tuning_job_id: &str, ) -> Result<FineTuningJob>

Immediately cancel a fine-tuning job. Read more
Source§

async fn list_fine_tuning_job_events( &self, fine_tuning_job_id: &str, params: PaginationParams<'_>, ) -> Result<ListFineTuningJobEventsResponse>

Get status updates for a fine-tuning job. Read more
Source§

async fn list_fine_tuning_job_checkpoints( &self, fine_tuning_job_id: &str, params: PaginationParams<'_>, ) -> Result<ListFineTuningJobCheckpointsResponse>

List checkpoints for a fine-tuning job. Read more
Source§

impl ImagesService for PortkeyClient

Source§

async fn generate_image( &self, request: CreateImageRequest, ) -> Result<ImagesResponse>

Generates images based on a text prompt. Read more
Source§

async fn edit_image( &self, image_data: Vec<u8>, image_name: &str, mask_data: Option<Vec<u8>>, mask_name: Option<&str>, request: CreateImageEditRequest, ) -> Result<ImagesResponse>

Edits an image based on a prompt. Read more
Source§

async fn create_image_variation( &self, image_data: Vec<u8>, image_name: &str, request: CreateImageVariationRequest, ) -> Result<ImagesResponse>

Creates a variation of an image. Read more
Source§

impl LogsService for PortkeyClient

Source§

async fn create_log_export( &self, request: CreateLogExportRequest, ) -> Result<CreateLogExportResponse>

Creates a new log export. Read more
Source§

async fn get_log_export(&self, export_id: &str) -> Result<LogExport>

Retrieves a log export by ID. Read more
Source§

async fn start_log_export(&self, export_id: &str) -> Result<ExportTaskResponse>

Starts processing a log export. Read more
Source§

async fn cancel_log_export(&self, export_id: &str) -> Result<ExportTaskResponse>

Cancels a running log export. Read more
Source§

async fn download_log_export( &self, export_id: &str, ) -> Result<DownloadLogExportResponse>

Downloads a completed log export. Read more
Source§

async fn insert_log( &self, request: InsertLogRequest, ) -> Result<InsertLogResponse>

Inserts one or more custom logs. Read more
Source§

async fn update_log_export( &self, export_id: &str, request: UpdateLogExportRequest, ) -> Result<UpdateLogExportResponse>

Updates an existing log export. Read more
Source§

async fn list_log_exports( &self, params: Option<ListLogExportsParams>, ) -> Result<ListLogExportsResponse>

Lists all log exports with optional workspace filter. Read more
Source§

impl MessagesService for PortkeyClient

Source§

async fn create_message( &self, thread_id: &str, request: CreateMessageRequest, ) -> Result<Message>

Create a message.
Source§

async fn retrieve_message( &self, thread_id: &str, message_id: &str, ) -> Result<Message>

Retrieve a message.
Source§

async fn modify_message( &self, thread_id: &str, message_id: &str, request: ModifyMessageRequest, ) -> Result<Message>

Modifies a message.
Source§

async fn list_messages( &self, thread_id: &str, params: PaginationParams<'_>, ) -> Result<ListMessagesResponse>

Returns a list of messages for a given thread.
Source§

async fn retrieve_message_file( &self, thread_id: &str, message_id: &str, file_id: &str, ) -> Result<MessageFile>

Retrieves a message file.
Source§

async fn list_message_files( &self, thread_id: &str, message_id: &str, params: PaginationParams<'_>, ) -> Result<ListMessageFilesResponse>

Returns a list of message files.
Source§

impl ModelsService for PortkeyClient

Source§

async fn list_models( &self, params: Option<ListModelsParams>, ) -> Result<ListModelsResponse>

Lists the currently available models. Read more
Source§

impl ModerationsService for PortkeyClient

Source§

async fn create_moderation( &self, request: CreateModerationRequest, ) -> Result<ModerationResponse>

Classifies if text is potentially harmful. Read more
Source§

impl PromptsService for PortkeyClient

Source§

async fn execute_prompt( &self, prompt_id: &str, request: PromptCompletionRequest, ) -> Result<PromptCompletionResponse>

Executes a saved prompt template with the given variables and parameters. Read more
Source§

async fn render_prompt( &self, prompt_id: &str, request: PromptRenderRequest, ) -> Result<PromptRenderResponse>

Renders a prompt template with variables and hyperparameters without executing it. Read more
Source§

impl ResponsesService for PortkeyClient

Source§

async fn create_response( &self, request: CreateResponseRequest, ) -> Result<Response>

Creates a new response. Read more
Source§

async fn get_response(&self, response_id: &str) -> Result<Response>

Retrieves a specific response by ID. Read more
Source§

async fn delete_response(&self, response_id: &str) -> Result<()>

Deletes a response. Read more
Source§

async fn list_input_items( &self, response_id: &str, params: ListInputItemsParams, ) -> Result<ListInputItemsResponse>

Lists input items for a specific response. Read more
Source§

impl RunsService for PortkeyClient

Source§

async fn create_run( &self, thread_id: &str, request: CreateRunRequest, ) -> Result<Run>

Create a run.
Source§

async fn retrieve_run(&self, thread_id: &str, run_id: &str) -> Result<Run>

Retrieves a run.
Source§

async fn modify_run( &self, thread_id: &str, run_id: &str, request: ModifyRunRequest, ) -> Result<Run>

Modifies a run.
Source§

async fn list_runs( &self, thread_id: &str, params: PaginationParams<'_>, ) -> Result<ListRunsResponse>

Returns a list of runs belonging to a thread.
Source§

async fn submit_tool_outputs( &self, thread_id: &str, run_id: &str, request: SubmitToolOutputsRequest, ) -> Result<Run>

When a run has the status: “requires_action” and required_action.type is submit_tool_outputs, this endpoint can be used to submit the outputs from the tool calls once they’re all completed.
Source§

async fn cancel_run(&self, thread_id: &str, run_id: &str) -> Result<Run>

Cancels a run that is in_progress.
Source§

async fn create_thread_and_run(&self, request: CreateRunRequest) -> Result<Run>

Create a thread and run it in one request.
Source§

async fn retrieve_run_step( &self, thread_id: &str, run_id: &str, step_id: &str, ) -> Result<RunStep>

Retrieves a run step.
Source§

async fn list_run_steps( &self, thread_id: &str, run_id: &str, params: PaginationParams<'_>, ) -> Result<ListRunStepsResponse>

Returns a list of run steps belonging to a run.
Source§

impl ThreadsService for PortkeyClient

Source§

async fn create_thread(&self, request: CreateThreadRequest) -> Result<Thread>

Create a thread.
Source§

async fn retrieve_thread(&self, thread_id: &str) -> Result<Thread>

Retrieves a thread.
Source§

async fn modify_thread( &self, thread_id: &str, request: ModifyThreadRequest, ) -> Result<Thread>

Modifies a thread.
Source§

async fn delete_thread(&self, thread_id: &str) -> Result<DeleteThreadResponse>

Delete a thread.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more