Skip to content

create_prompt_router async

create_prompt_router(
    prompt_router_name: PromptRouterName,
    models: PromptRouterTargetModels,
    routing_criteria: RoutingCriteria,
    fallback_model: PromptRouterTargetModel,
    *,
    config_overrides: Optional[AsyncBedrockClientConfig] = None,
    client_request_token: Optional[IdempotencyToken] = None,
    description: Optional[PromptRouterDescription] = None,
    tags: Optional[TagList] = None,
) -> CreatePromptRouterResponse

Creates a prompt router that manages the routing of requests between multiple foundation models based on the routing criteria.

Parameters:

  • client_request_token (Optional[IdempotencyToken], default: None ) –

    A unique, case-sensitive identifier that you provide to ensure idempotency of your requests. If not specified, the Amazon Web Services SDK automatically generates one for you.

  • prompt_router_name (PromptRouterName) –

    The name of the prompt router. The name must be unique within your Amazon Web Services account in the current region.

  • models (PromptRouterTargetModels) –

    A list of foundation models that the prompt router can route requests to. At least one model must be specified.

  • description (Optional[PromptRouterDescription], default: None ) –

    An optional description of the prompt router to help identify its purpose.

  • routing_criteria (RoutingCriteria) –

    The criteria, which is the response quality difference, used to determine how incoming requests are routed to different models.

  • fallback_model (PromptRouterTargetModel) –

    The default model to use when the routing criteria is not met.

  • tags (Optional[TagList], default: None ) –

    An array of key-value pairs to apply to this resource as tags. You can use tags to categorize and manage your Amazon Web Services resources.

Raises:

  • AccessDeniedException –

    The request is denied because of missing access permissions.

  • ConflictException –

    Error occurred because of a conflict while performing an operation.

  • InternalServerException –

    An internal server error occurred. Retry your request.

  • ResourceNotFoundException –

    The specified resource Amazon Resource Name (ARN) was not found. Check the Amazon Resource Name (ARN) and try your request again.

  • ServiceQuotaExceededException –

    The number of requests exceeds the service quota. Resubmit your request later.

  • ThrottlingException –

    The number of requests exceeds the limit. Resubmit your request later.

  • TooManyTagsException –

    The request contains more tags than can be associated with a resource (50 tags per resource). The maximum number of tags includes both existing tags and those included in your current request.

  • ValidationException –

    Input validation failed. Check your request parameters and retry the request.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_bedrock/_services/async_bedrock.py
async def create_prompt_router(
    self,
    prompt_router_name: "capo_bedrock.types.prompt_router_name.PromptRouterName",
    models: "capo_bedrock.types.prompt_router_target_models.PromptRouterTargetModels",
    routing_criteria: "capo_bedrock.types.routing_criteria.RoutingCriteria",
    fallback_model: "capo_bedrock.types.prompt_router_target_model.PromptRouterTargetModel",
    *,
    config_overrides: Optional[AsyncBedrockClientConfig] = None,
    client_request_token: Optional[
        "capo_bedrock.types.idempotency_token.IdempotencyToken"
    ] = None,
    description: Optional[
        "capo_bedrock.types.prompt_router_description.PromptRouterDescription"
    ] = None,
    tags: Optional["capo_bedrock.types.tag_list.TagList"] = None,
) -> "capo_bedrock.types.create_prompt_router_response.CreatePromptRouterResponse":
    """<p>Creates a prompt router that manages the routing of requests between multiple foundation models based on the routing criteria.</p>

    Args:
        client_request_token: <p>A unique, case-sensitive identifier that you provide to ensure idempotency of your requests. If not specified, the Amazon Web Services SDK automatically generates one for you.</p>
        prompt_router_name: <p>The name of the prompt router. The name must be unique within your Amazon Web Services account in the current region.</p>
        models: <p>A list of foundation models that the prompt router can route requests to. At least one model must be specified.</p>
        description: <p>An optional description of the prompt router to help identify its purpose.</p>
        routing_criteria: <p>The criteria, which is the response quality difference, used to determine how incoming requests are routed to different models.</p>
        fallback_model: <p>The default model to use when the routing criteria is not met.</p>
        tags: <p>An array of key-value pairs to apply to this resource as tags. You can use tags to categorize and manage your Amazon Web Services resources.</p>

    Raises:
        capo_bedrock.errors.access_denied_exception.AccessDeniedException: <p>The request is denied because of missing access permissions.</p>
        capo_bedrock.errors.conflict_exception.ConflictException: <p>Error occurred because of a conflict while performing an operation.</p>
        capo_bedrock.errors.internal_server_exception.InternalServerException: <p>An internal server error occurred. Retry your request.</p>
        capo_bedrock.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified resource Amazon Resource Name (ARN) was not found. Check the Amazon Resource Name (ARN) and try your request again.</p>
        capo_bedrock.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The number of requests exceeds the service quota. Resubmit your request later.</p>
        capo_bedrock.errors.throttling_exception.ThrottlingException: <p>The number of requests exceeds the limit. Resubmit your request later.</p>
        capo_bedrock.errors.too_many_tags_exception.TooManyTagsException: <p>The request contains more tags than can be associated with a resource (50 tags per resource). The maximum number of tags includes both existing tags and those included in your current request. </p>
        capo_bedrock.errors.validation_exception.ValidationException: <p>Input validation failed. Check your request parameters and retry the request.</p>
        capo_bedrock.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_bedrock.types.create_prompt_router_request.CreatePromptRouterRequest]",
    ) -> AsyncOperationResponse[
        "capo_bedrock.types.create_prompt_router_response.CreatePromptRouterResponse"
    ]:
        import capo_bedrock._operations.amazon_bedrock_control_plane_service.create_prompt_router

        (
            output,
            http_response,
        ) = await capo_bedrock._operations.amazon_bedrock_control_plane_service.create_prompt_router.async_create_prompt_router(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_bedrock.types.create_prompt_router_request.CreatePromptRouterRequest",
    ) -> dict[str, Any]:
        import capo_bedrock.types.create_prompt_router_request

        return capo_bedrock.types.create_prompt_router_request.redact_sensitive(
            input_
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("CreatePromptRouter", redact_input=_redact_input),
    )
    input_: capo_bedrock.types.create_prompt_router_request.CreatePromptRouterRequest = {
        "prompt_router_name": prompt_router_name,
        "models": models,
        "routing_criteria": routing_criteria,
        "fallback_model": fallback_model,
    }
    if client_request_token is None:
        client_request_token = str(uuid.uuid4())
    input_["client_request_token"] = client_request_token
    if description is not None:
        input_["description"] = description
    if tags is not None:
        input_["tags"] = tags

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output