Install SAP AI Core SDK & Make Your First Call

Install the SAP AI Core SDK for Python or Node.js, authenticate using your service key, and make a test API call to list available resource groups.

Install SAP AI Core SDK & Make Your First Call

Python SDK (most common)

Install

pip install ai-core-sdk

Authenticate

Create test_ai_core.py:

from ai_core_sdk.ai_core_v2_client import AICoreV2Client

client = AICoreV2Client(
    base_url="https://api.ai.prod.eu-central-1.aws.ml.hana.ondemand.com/v2",
    auth_url="https://yourtenant.authentication.eu10.hana.ondemand.com/oauth/token",
    client_id="sb-...",
    client_secret="..."
)

# List resource groups
resource_groups = client.resource_groups.query()
print("Resource groups:", [rg.resource_group_id for rg in resource_groups.resources])

Run it:

python test_ai_core.py
# Resource groups: ['default']

Load credentials from file (cleaner)

import json, os
from ai_core_sdk.ai_core_v2_client import AICoreV2Client

with open(os.path.expanduser("~/.ai-core-credentials.json")) as f:
    creds = json.load(f)

client = AICoreV2Client(
    base_url=creds["serviceurls"]["AI_API_URL"] + "/v2",
    auth_url=creds["url"] + "/oauth/token",
    client_id=creds["clientid"],
    client_secret=creds["clientsecret"]
)

Node.js / JavaScript SDK

npm install @sap-ai-sdk/core @sap-ai-sdk/foundation-models

Create test-ai-core.js:

import { AiCoreDeploymentApi } from '@sap-ai-sdk/core';

const deployments = await AiCoreDeploymentApi.deploymentQuery(
  { resourceGroup: 'default' }
).execute();

console.log('Deployments:', deployments.resources.map(d => d.deploymentId));

Set environment variables before running:

export AICORE_SERVICE_URL="https://api.ai.prod.eu-central-1.aws.ml.hana.ondemand.com"
export AICORE_CLIENT_ID="sb-..."
export AICORE_CLIENT_SECRET="..."
export AICORE_AUTH_URL="https://yourtenant.authentication.eu10.hana.ondemand.com"

node test-ai-core.js

Troubleshoot: 401 Unauthorized

Check that:
1. clientid and clientsecret are from the service key (not your BTP login)
2. auth_url ends in /oauth/token
3. The AI Core service instance status is Created in the BTP cockpit

Troubleshoot: 403 Forbidden

Your service key may not have the right scopes. Delete the key and create a new one.

Sign in for progress tracking & Q&A →