Skip to content

optimize_prompt

Operation

Async only

This operation uses an event stream, so only the asynchronous client supports it.

optimize_prompt async

optimize_prompt(request: OptimizePromptInput | OptimizePromptInputDict | None = None, /, *, plugins: list[Plugin] | None = None, **kwargs: Unpack[OptimizePromptInputDict]) -> AsyncOutputEventStream[OptimizedPromptStream, OptimizePromptOutput]

Optimizes a prompt for the task that you specify. For more information, see Optimize a prompt in the Amazon Bedrock User Guide.

Parameters:

Name Type Description Default
request OptimizePromptInput | OptimizePromptInputDict | None

The input as a model or dictionary. Pass this or keyword arguments, not both.

None
plugins list[Plugin] | None

A list of callables that modify the configuration dynamically. Changes made by these plugins only apply for the duration of the operation execution and will not affect any other operation invocations.

None
**kwargs Unpack[OptimizePromptInputDict]

The input fields as keyword arguments.

{}

Returns:

Type Description
AsyncOutputEventStream[OptimizedPromptStream, OptimizePromptOutput]

An AsyncOutputEventStream for server-to-client streaming.

Input

Pass the input as keyword arguments, a positional dictionary, or a positional model object. Pass plugins separately as a keyword argument.

OptimizePromptInputDict

Bases: TypedDict

Dictionary form of OptimizePromptInput.

Attributes

input instance-attribute

Contains the prompt to optimize.

target_model_id instance-attribute
target_model_id: Required[str]

The unique identifier of the model that you want to optimize the prompt for.

OptimizePromptInput dataclass

Bases: _SerdeShape

Dataclass for OptimizePromptInput structure.

Attributes

input class-attribute instance-attribute
input: InputPrompt | None = ...

Contains the prompt to optimize.

target_model_id class-attribute instance-attribute
target_model_id: str | None = ...

The unique identifier of the model that you want to optimize the prompt for.

Output

This operation returns an AsyncOutputEventStream for server-to-client streaming.

Event Stream Structure

Output Event Type

OptimizedPromptStream

Initial Response Structure

OptimizePromptOutput dataclass

Bases: _SerdeShape

Dataclass for OptimizePromptOutput structure.

Attributes
response_metadata class-attribute instance-attribute
response_metadata: ResponseMetadata = ...

Metadata about the response that produced this output. Use this to recover the request identifiers a service's support team needs in order to investigate a call. Members of the metadata are individually optional.