Skip to main content

SAP Cloud SDK for AI (Python): Core SDK

The SDK formerly known as AI Core SDK was rebranded.

The class names have not changed i.e., you can continue to use existing code.

The SAP AI Core SDK can be used to interact with SAP AI Core. It provides access to all public lifecycle and administration APIs.

For example:

  • You can execute pipelines as a batch job to preprocess or train your models, or perform batch inference.

  • You can deploy а trained machine learning model as a web service to serve inference requests with high performance.

  • You can register your own Docker registry, synchronize your AI content from your own git repository, and register your own object store for training data and trained models.

  • You can log metrics within a workflow execution using the SDK. You can use the same code for tracking metrics in both your local environment and in the workflow execution (production).

Notes

  • Executing online inference is not part of Core SDK.

  • Metrics persistence is not currently available in your local environment using the SDK. However, it is available in your productive workflow execution.

  • Content packages for AICore are no longer supported.

Example Usage

Here are a few examples how to use this SDK. For details on the methods, please refer to the API documentation.

Import Definitions

from ai_core_sdk.ai_core_v2_client import AICoreV2Client

Create Client

The SDK requires credentials from your tenant's subaccount Service Key:

client = AICoreV2Client(base_url=AI_API_BASE,
                        auth_url=AUTH_URL,
                        client_id=CLIENT_ID,
                        client_secret=CLIENT_SECRET,
                        resource_group=resource_group_id)

(For persistent client configuration see below.)

Create New Resource Group

resource_group_create = client.resource_groups.create(resource_group_id=resource_group_id)
print(resource_group_create.resource_group_id)
resource_group_details = client.resource_groups.get(resource_group_id=resource_group_id)
print(f"{resource_group_details.status_message} \n{resource_group_details.resource_group_id}")

Create Object Store Secret

# access key and secret are assumed to reside in environment variables OSS_KEY and OSS_SECRET
object_store_secret_create = client.object_store_secrets.create(
            name="default",
            type="S3",
            bucket="<your S3 bucket>", 
            endpoint="<your S3 host>",
            path_prefix="<your path prefix in S3>", region="<your S3 region>",
            data={"AWS_ACCESS_KEY_ID": os.environ.get("OSS_KEY"),
            "AWS_SECRET_ACCESS_KEY": os.environ.get("OSS_SECRET")})

secret_get = client.object_store_secrets.get(name="default")
print(f"{secret_get.metadata}")

List Scenarios

scenarios = client.scenario.query()
for scenario in scenarios.resources:
    print(f"{scenario.name} {scenario.id}")

Client Configuration

There are different options to persist the client credentials (in this order of precedence):

  • in code via keyword arguments (see above),
  • from AICORE_SERVICE_KEY environment variable, if exists
  • environment variables,
  • profile configuration file.
  • from VCAP_SERVICES environment variable, if exists

A profile is a json file residing in a config directory, which can be set via environment variable AICORE_HOME (the default being ~/.aicore/config.json).

The command aicore configure --help shows the options for generating a profile.

With profile names one can switch easily between profiles e.g., for different (sub)accounts. The profile name can be passed also as a keyword. If no profile is specified, the default profile is used.

Tracking

The tracking module of the SAP AI Core SDK can be used to log metrics in both your local environment, and productive workflow executions. Metrics persistence is currently available in your productive environment.

Here are a few code samples demonstrating how to use the SDK for metrics tracking.

Modify Metrics

from ai_core_sdk.tracking import Tracking

from ai_core_sdk.models import Metric, MetricTag, MetricCustomInfo

tracking_client = Tracking()

tracking_client.modify(
   tags = [
       # list
       MetricTag(name="Our Team Tag", value="Tutorial Team"),
       MetricTag(name="Stage", value="Development")
   ],
   metrics = [
       Metric(
           name="Training Loss",
           value=np.finfo(np.float64).max,
           timestamp= datetime.now().utcnow(),
           step = 1, # denotes epoch 1
           labels = []
       )
   ],
   custom_info = [
       # list of Custom Information
        MetricCustomInfo(
            name = "My Classification Report",
            # you may convert anything to string and store it
            value = str('''{
                "Cats": {
                    "Precision": 75,
                    "Recall": 74
                },
                "Dogs": {
                    "Precision": 85,
                    "Recall": 84
                }
            }''')
       )
   ]
)

Log Metrics

tracking_client.log_metrics(
   metrics = [
       Metric(
           name="Training Loss",
           value=float(86.99),
           timestamp= datetime.now().utcnow(),
           step = 1, # denotes epoch 1
           labels = []
       ),
   ],
)

Set Tags

tracking_client.set_tags(
   tags = [
       # list
       MetricTag(name="Our Team Tag", value="Tutorial Team"),
       MetricTag(name="Stage", value="Development")
   ]
)

Set Custom Info

tracking_client.set_custom_info(
   custom_info = [
       # list of Custom Information
        MetricCustomInfo(
            name = "My Classification Report",
            # you may convert anything to string and store it
            value = str('''
            {
                "Cats": {
                    "Precision": 75,
                    "Recall": 74
                },
                "Dogs": {
                    "Precision": 85,
                    "Recall": 84
                }
            }
            '''
            )
       ),
   ]
)

Query Metrics

metrics_response = tracking_client.query(execution_ids = [
   "test_execution_id"    # Change this with the training execution id
])

Delete Metrics

metrics_response = tracking_client.delete(execution_id = "test_execution_id") # Change this with the actual execution id

Metadata

Release files for sap-ai-sdk-core 3.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sap-ai-sdk-core 3.5.0
File Size Uploaded
sap_ai_sdk_core-3.5.0.tar.gz 31.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sap-ai-sdk-core 3.5.0
File Interpreter ABI Platform
sap_ai_sdk_core-3.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 78.1 kB

Release files / sap_ai_sdk_core-3.5.0.tar.gz

Download URL sap_ai_sdk_core-3.5.0.tar.gz
Size 31.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0480e17152dce9d2a7f88dbbc48d40308129230447545057e28990b58510a185
BLAKE2b-256 checksum
How to use checksums
e825353c11a42091769df8794cec6a34d8e0c2ea3a8373fdac30b019b2d4ad0c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 2, 2026.

Transparency log

Release files / sap_ai_sdk_core-3.5.0-py3-none-any.whl

Download URL sap_ai_sdk_core-3.5.0-py3-none-any.whl
Size 46.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8b05c6d9186fe396d235c45d0ed395db6d61e217035c476a87d4b0e266bb4343
BLAKE2b-256 checksum
How to use checksums
e6856614435fa0563785eaa0203cd9fc9f31ee88d908e840ed195269e50b7831
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 2, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

3.5.0 This release

2 release files

3.4.0

2 release files

3.3.0

1 release file

3.2.0

1 release file

3.1.6

1 release file

3.1.2

1 release file

3.1.0

1 release file

3.0.11

1 release file

3.0.10

1 release file

3.0.8

1 release file

3.0.3

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page