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
Arcinternally 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
impl PortkeyClient
Sourcepub fn new(config: PortkeyConfig) -> Result<Self>
pub fn new(config: PortkeyConfig) -> Result<Self>
Creates a new Portkey API client.
Sourcepub fn builder() -> PortkeyBuilder
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()?;Sourcepub fn from_env() -> Result<Self>
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
impl AssistantsService for PortkeyClient
Source§async fn create_assistant(
&self,
request: CreateAssistantRequest,
) -> Result<Assistant>
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>
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>
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>
async fn delete_assistant( &self, assistant_id: &str, ) -> Result<DeleteAssistantResponse>
Delete an assistant.
Source§async fn list_assistants(
&self,
params: PaginationParams<'_>,
) -> Result<ListAssistantsResponse>
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>
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>
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>
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>
async fn list_assistant_files( &self, assistant_id: &str, params: PaginationParams<'_>, ) -> Result<ListAssistantFilesResponse>
Returns a list of assistant files.
Source§impl AudioService for PortkeyClient
impl AudioService for PortkeyClient
Source§async fn create_transcription(
&self,
file_data: Vec<u8>,
file_name: &str,
request: CreateTranscriptionRequest,
) -> Result<TranscriptionResponse>
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>>
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>
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
impl BatchesService for PortkeyClient
Source§async fn create_batch(&self, request: CreateBatchRequest) -> Result<Batch>
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 cancel_batch(&self, batch_id: &str) -> Result<Batch>
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>
async fn list_batches( &self, params: PaginationParams<'_>, ) -> Result<ListBatchesResponse>
List your organization’s batches. Read more
Source§impl ChatService for PortkeyClient
impl ChatService for PortkeyClient
Source§async fn create_chat_completion(
&self,
request: ChatCompletionRequest,
) -> Result<ChatCompletionResponse>
async fn create_chat_completion( &self, request: ChatCompletionRequest, ) -> Result<ChatCompletionResponse>
Creates a chat completion. Read more
Source§impl Clone for PortkeyClient
impl Clone for PortkeyClient
Source§fn clone(&self) -> PortkeyClient
fn clone(&self) -> PortkeyClient
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 moreSource§impl CompletionsService for PortkeyClient
impl CompletionsService for PortkeyClient
Source§async fn create_completion(
&self,
request: CreateCompletionRequest,
) -> Result<CompletionResponse>
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
impl Debug for PortkeyClient
Source§impl EmbeddingsService for PortkeyClient
impl EmbeddingsService for PortkeyClient
Source§async fn create_embedding(
&self,
request: CreateEmbeddingRequest,
) -> Result<CreateEmbeddingResponse>
async fn create_embedding( &self, request: CreateEmbeddingRequest, ) -> Result<CreateEmbeddingResponse>
Creates an embedding vector representing the input text. Read more
Source§impl FeedbackService for PortkeyClient
impl FeedbackService for PortkeyClient
Source§async fn create_feedback(
&self,
request: CreateFeedbackRequest,
) -> Result<FeedbackResponse>
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>
async fn update_feedback( &self, feedback_id: &str, request: UpdateFeedbackRequest, ) -> Result<FeedbackResponse>
Updates existing feedback by ID. Read more
Source§impl FilesService for PortkeyClient
impl FilesService for PortkeyClient
Source§async fn upload_file(&self, request: UploadFileRequest) -> Result<FileObject>
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>
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>
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>>
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>
async fn delete_file(&self, file_id: &str) -> Result<DeleteFileResponse>
Delete a file. Read more
Source§impl FineTuningService for PortkeyClient
impl FineTuningService for PortkeyClient
Source§async fn create_fine_tuning_job(
&self,
request: CreateFineTuningJobRequest,
) -> Result<FineTuningJob>
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>
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>
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>
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>
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>
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
impl ImagesService for PortkeyClient
Source§async fn generate_image(
&self,
request: CreateImageRequest,
) -> Result<ImagesResponse>
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>
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>
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
impl LogsService for PortkeyClient
Source§async fn create_log_export(
&self,
request: CreateLogExportRequest,
) -> Result<CreateLogExportResponse>
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>
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>
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>
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>
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>
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>
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>
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
impl MessagesService for PortkeyClient
Source§async fn create_message(
&self,
thread_id: &str,
request: CreateMessageRequest,
) -> Result<Message>
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>
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>
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>
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>
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>
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
impl ModelsService for PortkeyClient
Source§async fn list_models(
&self,
params: Option<ListModelsParams>,
) -> Result<ListModelsResponse>
async fn list_models( &self, params: Option<ListModelsParams>, ) -> Result<ListModelsResponse>
Lists the currently available models. Read more
Source§impl ModerationsService for PortkeyClient
impl ModerationsService for PortkeyClient
Source§async fn create_moderation(
&self,
request: CreateModerationRequest,
) -> Result<ModerationResponse>
async fn create_moderation( &self, request: CreateModerationRequest, ) -> Result<ModerationResponse>
Classifies if text is potentially harmful. Read more
Source§impl PromptsService for PortkeyClient
impl PromptsService for PortkeyClient
Source§async fn execute_prompt(
&self,
prompt_id: &str,
request: PromptCompletionRequest,
) -> Result<PromptCompletionResponse>
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>
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
impl ResponsesService for PortkeyClient
Source§async fn create_response(
&self,
request: CreateResponseRequest,
) -> Result<Response>
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>
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<()>
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>
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
impl RunsService for PortkeyClient
Source§async fn create_run(
&self,
thread_id: &str,
request: CreateRunRequest,
) -> Result<Run>
async fn create_run( &self, thread_id: &str, request: CreateRunRequest, ) -> Result<Run>
Create a run.
Source§async fn modify_run(
&self,
thread_id: &str,
run_id: &str,
request: ModifyRunRequest,
) -> Result<Run>
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>
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>
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>
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>
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>
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>
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
impl ThreadsService for PortkeyClient
Source§async fn create_thread(&self, request: CreateThreadRequest) -> Result<Thread>
async fn create_thread(&self, request: CreateThreadRequest) -> Result<Thread>
Create a thread.
Source§async fn modify_thread(
&self,
thread_id: &str,
request: ModifyThreadRequest,
) -> Result<Thread>
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>
async fn delete_thread(&self, thread_id: &str) -> Result<DeleteThreadResponse>
Delete a thread.
Auto Trait Implementations§
impl Freeze for PortkeyClient
impl !RefUnwindSafe for PortkeyClient
impl Send for PortkeyClient
impl Sync for PortkeyClient
impl Unpin for PortkeyClient
impl !UnwindSafe for PortkeyClient
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