2121from ..types .golden_record_param import GoldenRecordParam
2222from ..types .request_provider_param import RequestProviderParam
2323from ..types .prompt_optimization_optimize_response import PromptOptimizationOptimizeResponse
24+ from ..types .prompt_optimization_retrieve_costs_response import PromptOptimizationRetrieveCostsResponse
2425from ..types .prompt_optimization_get_optimziation_status_response import PromptOptimizationGetOptimziationStatusResponse
2526from ..types .prompt_optimization_get_optimization_results_response import (
2627 PromptOptimizationGetOptimizationResultsResponse ,
@@ -335,6 +336,56 @@ def optimize(
335336 cast_to = PromptOptimizationOptimizeResponse ,
336337 )
337338
339+ def retrieve_costs (
340+ self ,
341+ optimization_run_id : str ,
342+ * ,
343+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
344+ # The extra values given here take precedence over values defined on the client or passed to this method.
345+ extra_headers : Headers | None = None ,
346+ extra_query : Query | None = None ,
347+ extra_body : Body | None = None ,
348+ timeout : float | httpx .Timeout | None | NotGiven = not_given ,
349+ ) -> PromptOptimizationRetrieveCostsResponse :
350+ """
351+ Get LLM usage costs for a specific prompt optimization run.
352+
353+ This endpoint returns the total cost and detailed usage records for all LLM
354+ requests made during a prompt optimization run. Use this to track costs
355+ associated with optimizing prompts for different target models.
356+
357+ **Cost Breakdown:**
358+
359+ - Total cost across all models used in the optimization
360+ - Individual usage records with provider, model, tokens, and costs
361+ - Timestamps for each LLM request
362+
363+ **Access Control:**
364+
365+ - Only accessible by the user who created the optimization run
366+ - Requires prompt optimization access
367+
368+ Args:
369+ extra_headers: Send extra headers
370+
371+ extra_query: Add additional query parameters to the request
372+
373+ extra_body: Add additional JSON properties to the request
374+
375+ timeout: Override the client-level default timeout for this request, in seconds
376+ """
377+ if not optimization_run_id :
378+ raise ValueError (
379+ f"Expected a non-empty value for `optimization_run_id` but received { optimization_run_id !r} "
380+ )
381+ return self ._get (
382+ f"/v2/prompt/optimize/{ optimization_run_id } /costs" ,
383+ options = make_request_options (
384+ extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
385+ ),
386+ cast_to = PromptOptimizationRetrieveCostsResponse ,
387+ )
388+
338389
339390class AsyncPromptOptimizationResource (AsyncAPIResource ):
340391 @cached_property
@@ -642,6 +693,56 @@ async def optimize(
642693 cast_to = PromptOptimizationOptimizeResponse ,
643694 )
644695
696+ async def retrieve_costs (
697+ self ,
698+ optimization_run_id : str ,
699+ * ,
700+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
701+ # The extra values given here take precedence over values defined on the client or passed to this method.
702+ extra_headers : Headers | None = None ,
703+ extra_query : Query | None = None ,
704+ extra_body : Body | None = None ,
705+ timeout : float | httpx .Timeout | None | NotGiven = not_given ,
706+ ) -> PromptOptimizationRetrieveCostsResponse :
707+ """
708+ Get LLM usage costs for a specific prompt optimization run.
709+
710+ This endpoint returns the total cost and detailed usage records for all LLM
711+ requests made during a prompt optimization run. Use this to track costs
712+ associated with optimizing prompts for different target models.
713+
714+ **Cost Breakdown:**
715+
716+ - Total cost across all models used in the optimization
717+ - Individual usage records with provider, model, tokens, and costs
718+ - Timestamps for each LLM request
719+
720+ **Access Control:**
721+
722+ - Only accessible by the user who created the optimization run
723+ - Requires prompt optimization access
724+
725+ Args:
726+ extra_headers: Send extra headers
727+
728+ extra_query: Add additional query parameters to the request
729+
730+ extra_body: Add additional JSON properties to the request
731+
732+ timeout: Override the client-level default timeout for this request, in seconds
733+ """
734+ if not optimization_run_id :
735+ raise ValueError (
736+ f"Expected a non-empty value for `optimization_run_id` but received { optimization_run_id !r} "
737+ )
738+ return await self ._get (
739+ f"/v2/prompt/optimize/{ optimization_run_id } /costs" ,
740+ options = make_request_options (
741+ extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
742+ ),
743+ cast_to = PromptOptimizationRetrieveCostsResponse ,
744+ )
745+
645746
646747class PromptOptimizationResourceWithRawResponse :
647748 def __init__ (self , prompt_optimization : PromptOptimizationResource ) -> None :
@@ -656,6 +757,9 @@ def __init__(self, prompt_optimization: PromptOptimizationResource) -> None:
656757 self .optimize = to_raw_response_wrapper (
657758 prompt_optimization .optimize ,
658759 )
760+ self .retrieve_costs = to_raw_response_wrapper (
761+ prompt_optimization .retrieve_costs ,
762+ )
659763
660764
661765class AsyncPromptOptimizationResourceWithRawResponse :
@@ -671,6 +775,9 @@ def __init__(self, prompt_optimization: AsyncPromptOptimizationResource) -> None
671775 self .optimize = async_to_raw_response_wrapper (
672776 prompt_optimization .optimize ,
673777 )
778+ self .retrieve_costs = async_to_raw_response_wrapper (
779+ prompt_optimization .retrieve_costs ,
780+ )
674781
675782
676783class PromptOptimizationResourceWithStreamingResponse :
@@ -686,6 +793,9 @@ def __init__(self, prompt_optimization: PromptOptimizationResource) -> None:
686793 self .optimize = to_streamed_response_wrapper (
687794 prompt_optimization .optimize ,
688795 )
796+ self .retrieve_costs = to_streamed_response_wrapper (
797+ prompt_optimization .retrieve_costs ,
798+ )
689799
690800
691801class AsyncPromptOptimizationResourceWithStreamingResponse :
@@ -701,3 +811,6 @@ def __init__(self, prompt_optimization: AsyncPromptOptimizationResource) -> None
701811 self .optimize = async_to_streamed_response_wrapper (
702812 prompt_optimization .optimize ,
703813 )
814+ self .retrieve_costs = async_to_streamed_response_wrapper (
815+ prompt_optimization .retrieve_costs ,
816+ )
0 commit comments