Skip to main content
Sagemaker allows users to host any ML model on their own AWS infrastructure. With Portkey you can manage/restrict access, log requests, and more.

Quick Start

from portkey_ai import Portkey

# 1. Install: pip install portkey-ai
# 2. Add @sagemaker provider in Model Catalog
# 3. Use it:

portkey = Portkey(
    api_key="PORTKEY_API_KEY",
    provider="@sagemaker"
)

response = portkey.post(
    url="endpoints/{endpoint_name}/invocations",
    # You can pass any key value pair required by the model
    # (apart from `url`), they are passed to the Sagemaker endpoint
    inputs="my_custom_value",
    my_custom_key="my_custom_value"
)

print(response)

Add Provider in Model Catalog

1

Navigate to Model Catalog

Go to Model Catalog → Add Provider in your Portkey dashboard.
2

Select AWS Sagemaker

Find and select AWS Sagemaker from the provider list.
3

Configure AWS Credentials

There are two authentication methods:Enter your AWS credentials and deployment details for your Sagemaker endpoint.
4

Save and Use

Save your configuration. Your provider slug will be @sagemaker (or a custom name you specify).

Direct Integration Without Model Catalog

If you prefer not to store your AWS credentials in Portkey, you can pass them directly when instantiating the Portkey client.

Supported Parameters

These parameters are supported for Sagemaker (not required if you’re using Model Catalog):
Node SDKPython SDKREST Headers
awsAccessKeyIdaws_access_key_idx-portkey-aws-access-key-id
awsSecretAccessKeyaws_secret_access_keyx-portkey-aws-secret-access-key
awsRegionaws_regionx-portkey-aws-region
awsSessionTokenaws_session_tokenx-portkey-aws-session-token
sagemakerCustomAttributessagemaker_custom_attributesx-portkey-amzn-sagemaker-custom-attributes
sagemakerTargetModelsagemaker_target_modelx-portkey-amzn-sagemaker-target-model
sagemakerTargetVariantsagemaker_target_variantx-portkey-amzn-sagemaker-target-variant
sagemakerTargetContainerHostnamesagemaker_target_container_hostnamex-portkey-amzn-sagemaker-target-container-hostname
sagemakerInferenceIdsagemaker_inference_idx-portkey-amzn-sagemaker-inference-id
sagemakerEnableExplanationssagemaker_enable_explanationsx-portkey-amzn-sagemaker-enable-explanations
sagemakerInferenceComponentsagemaker_inference_componentx-portkey-amzn-sagemaker-inference-component
sagemakerSessionIdsagemaker_session_idx-portkey-amzn-sagemaker-session-id
sagemakerModelNamesagemaker_model_namex-portkey-amzn-sagemaker-model-name

Example

from portkey_ai import Portkey

portkey = Portkey(
    api_key="PORTKEY_API_KEY",
    provider="@sagemaker",
    aws_region="us-east-1",
    aws_access_key_id="AWS_ACCESS_KEY_ID",
    aws_secret_access_key="AWS_SECRET_ACCESS_KEY",
    sagemaker_inference_component="SAGEMAKER_INFERENCE_COMPONENT"
)

response = portkey.post(
    url="endpoints/{endpoint_name}/invocations",
    # You can pass any key value pair required by the model
    # (apart from `url`), they are passed to the Sagemaker endpoint
    inputs="my_custom_value",
    my_custom_key="my_custom_value"
)

print(response)

Next Steps