Experimental
@aws-cdk/aws-bedrock-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.
PromptRouter Class
Amazon Bedrock intelligent prompt routing provides a single serverless endpoint for efficiently routing requests between different foundational models within the same model family.
It can help you optimize for response quality and cost.
Intelligent prompt routing predicts the performance of each model for each request, and dynamically routes each request to the model that it predicts is most likely to give the desired response at the lowest cost.
Example
// Create a prompt router for intelligent model selection
const promptRouter = bedrock.PromptRouter.fromDefaultId(
bedrock.DefaultPromptRouterIdentifier.ANTHROPIC_CLAUDE_V1,
'us-east-1'
);
// Use the prompt router with a prompt variant
const variant = bedrock.PromptVariant.text({
variantName: 'variant1',
promptText: 'What is the capital of France?',
model: promptRouter,
});
new bedrock.Prompt(this, 'Prompt', {
promptName: 'prompt-router-test',
variants: [variant],
});
# Create a prompt router for intelligent model selection
prompt_router = bedrock.PromptRouter.from_default_id(bedrock.DefaultPromptRouterIdentifier.ANTHROPIC_CLAUDE_V1, "us-east-1")
# Use the prompt router with a prompt variant
variant = bedrock.PromptVariant.text(
variant_name="variant1",
prompt_text="What is the capital of France?",
model=prompt_router
)
bedrock.Prompt(self, "Prompt",
prompt_name="prompt-router-test",
variants=[variant]
)
// Create a prompt router for intelligent model selection
PromptRouter promptRouter = PromptRouter.fromDefaultId(DefaultPromptRouterIdentifier.ANTHROPIC_CLAUDE_V1, "us-east-1");
// Use the prompt router with a prompt variant
IPromptVariant variant = PromptVariant.text(TextPromptVariantProps.builder()
.variantName("variant1")
.promptText("What is the capital of France?")
.model(promptRouter)
.build());
Prompt.Builder.create(this, "Prompt")
.promptName("prompt-router-test")
.variants(List.of(variant))
.build();
// Install: dotnet add package Amazon.CDK.AWS.Bedrock.Alpha
// Create a prompt router for intelligent model selection
var promptRouter = PromptRouter.FromDefaultId(DefaultPromptRouterIdentifier.ANTHROPIC_CLAUDE_V1, "us-east-1");
// Use the prompt router with a prompt variant
var variant = PromptVariant.Text(new TextPromptVariantProps {
VariantName = "variant1",
PromptText = "What is the capital of France?",
Model = promptRouter
});
new Prompt(this, "Prompt", new PromptProps {
PromptName = "prompt-router-test",
Variants = new [] { variant }
});
// Install: go get github.com/aws/aws-cdk-go/awsbedrockalpha/v2
// Create a prompt router for intelligent model selection
promptRouter := bedrock.PromptRouter_FromDefaultId(bedrock.DefaultPromptRouterIdentifier_ANTHROPIC_CLAUDE_V1(), jsii.String("us-east-1"))
// Use the prompt router with a prompt variant
variant := bedrock.PromptVariant_Text(&TextPromptVariantProps{
VariantName: jsii.String("variant1"),
PromptText: jsii.String("What is the capital of France?"),
Model: promptRouter,
})
bedrock.NewPrompt(this, jsii.String("Prompt"), &PromptProps{
PromptName: jsii.String("prompt-router-test"),
Variants: []IPromptVariant{
variant,
},
})
Initializer
new PromptRouter(props: PromptRouterProps, region: string)
PromptRouter(props: PromptRouterProps, region: str)
new PromptRouter(PromptRouterProps props, String region)
new PromptRouter(PromptRouterProps props, string region)
NewPromptRouter(Props PromptRouterProps, Region *string)
Properties
This equals to the promptRouterArn property, useful for implementing IBedrockInvokable interface.
promptRouterArnstringprompt_router_arnstrpromptRouterArnStringPromptRouterArnstringPromptRouterArn*stringrequired#promptRouterIdstringprompt_router_idstrpromptRouterIdStringPromptRouterIdstringPromptRouterId*stringrequired#routingEndpointsIBedrockInvokable[]routing_endpointstyping.List[IBedrockInvokable]routingEndpointsList<IBedrockInvokable>RoutingEndpointsIBedrockInvokable[]RoutingEndpoints*[]IBedrockInvokablerequired#These are created automatically based on the routing models and region.
Methods
fromDefaultId(defaultRouter: DefaultPromptRouterIdentifier, region: string): PromptRouter // chainable@staticmethod def from_default_id(default_router: DefaultPromptRouterIdentifier, region: str) -> PromptRouterpublic static PromptRouter fromDefaultId(DefaultPromptRouterIdentifier defaultRouter, String region)public static PromptRouter FromDefaultId(DefaultPromptRouterIdentifier defaultRouter, string region)func FromDefaultId(DefaultRouter DefaultPromptRouterIdentifier, Region *string) PromptRouterstatic#2 parameters · returns
Parameters
defaultRouterdefault_routerdefaultRouterdefaultRouterDefaultRouter— - The default router configuration to use.regionregionregionregionRegion— - The AWS region where the router will be used.
Returns: A new PromptRouter instance configured with the default settings
grantInvoke(grantee: IGrantable): Grantdef grant_invoke(self, grantee: IGrantable) -> Grantpublic Grant grantInvoke(IGrantable grantee)public Grant GrantInvoke(IGrantable grantee)func GrantInvoke(Grantee IGrantable) Grant#This method grants permissions to:
- Get prompt router details (bedrock:GetPromptRouter)
- Invoke models through the router (bedrock:InvokeModel)
- Use all underlying models and cross-region profiles [disable-awslint:no-grants]
1 parameter · returns
Parameters
granteegranteegranteegranteeGrantee— - The IAM principal to grant permissions to.
Returns: An IAM Grant object representing the granted permissions