Loading...
Loading...
Integrates the SAP Cloud SDK for AI for Python (sap-ai-sdk-gen, formerly generative-ai-hub-sdk) into Python applications. Use when building Python apps with SAP AI Core, Generative AI Hub, or the Orchestration Service: chat completion, embeddings, streaming, LangChain integration, templating, content filtering, data masking, and document grounding. Supports OpenAI GPT models, Llama, Gemini, Amazon Nova, and other foundation models via SAP BTP.
npx skill4agent add secondsky/sap-skills sap-cloud-sdk-ai-pythonPackage rename: The PyPI packageis deprecated (v4.12.4 is the last release). Its successor isgenerative-ai-hub-sdk(currently v6.10.0 per public PyPI registry evidence from 2026-06-15). Code and tutorials referencingsap-ai-sdk-genshould migrate togenerative-ai-hub-sdk; the import name remainssap-ai-sdk-gen.gen_ai_hub
gen_ai_hubsap-ai-sdk-gengenerative-ai-hub-sdksap-ai-sdk-genfrom gen_ai_hub.proxy.native.openai import chat
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is SAP BTP?"}
]
response = chat.completions.create(
model_name="gpt-4o-mini",
messages=messages
)
print(response.choices[0].message.content)from gen_ai_hub.orchestration_v2 import (
OrchestrationConfig, OrchestrationService,
ModuleConfig, PromptTemplatingModuleConfig,
Template, UserMessage, LLMModelDetails
)
config = OrchestrationConfig(
modules=ModuleConfig(
prompt_templating=PromptTemplatingModuleConfig(
prompt=Template(
template=[UserMessage(role="user", content="{{?question}}")]
),
model=LLMModelDetails(name="gpt-4o-mini")
)
)
)
service = OrchestrationService(config=config)
response = service.run(placeholder_values={"question": "What is SAP?"})
print(response.final_result.choices[0].message.content)# All providers + LangChain support
pip install "sap-ai-sdk-gen[all]"
# Default (OpenAI only, no LangChain)
pip install sap-ai-sdk-gen
# Specific providers (without LangChain)
pip install "sap-ai-sdk-gen[google, amazon]"AICoreV2Client.from_env()GenAIHubProxyClient(...)AICORE_CLIENT_IDAICORE_CLIENT_SECRETAICORE_AUTH_URLAICORE_BASE_URLAICORE_RESOURCE_GROUP$AICORE_HOME/config.jsonAICORE_CONFIGAICORE_PROFILEexport AICORE_CLIENT_ID="sb-..."
export AICORE_CLIENT_SECRET="..."
export AICORE_AUTH_URL="https://<tenant>.authentication.sap.hana.ondemand.com/oauth/token"
export AICORE_BASE_URL="https://api.ai.prod.eu-central-1.aws.ml.hana.ondemand.com/v2"
export AICORE_RESOURCE_GROUP="default"# ~/.aicore/config.json
{
"AICORE_CLIENT_ID": "sb-...",
"AICORE_CLIENT_SECRET": "...",
"AICORE_AUTH_URL": "https://<tenant>.authentication.sap.hana.ondemand.com/oauth/token",
"AICORE_BASE_URL": "https://api.ai.prod.eu-central-1.aws.ml.hana.ondemand.com/v2",
"AICORE_RESOURCE_GROUP": "default"
}references/getting-started-auth.md| Module | Import Path | Purpose |
|---|---|---|
| Proxy (native clients) | | Direct model access per provider |
| LangChain integration | | |
| Orchestration | | Templating, filtering, masking, grounding |
| Document Grounding | | Pipeline, Vector, Retrieval APIs |
| Prompt Registry | | Template management and config storage |
| Evaluations | | Model evaluation runs and metrics |
| SAP RPT-1 | | Tabular prediction (classification, regression) |
| Provider | Import | Key Classes |
|---|---|---|
| OpenAI | | |
| Amazon Bedrock | | |
| Google GenAI | | |
| SAP RPT-1 | | |
| Provider | Example Families |
|---|---|
| OpenAI | GPT-family chat, multimodal, reasoning, and embedding models |
| Anthropic (via Bedrock) | Claude-family models |
| Amazon | Nova/Titan-family models |
| Gemini-family models | |
| Mistral | Mistral-family models |
| SAP | RPT-family tabular prediction models where enabled |
from gen_ai_hub.proxy.native.openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Explain CAP in one paragraph."}]
)
print(response.choices[0].message.content)from gen_ai_hub.proxy.native.openai import OpenAI
client = OpenAI()
stream = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Explain SAP CAP."}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")from gen_ai_hub.proxy.native.openai import embeddings
response = embeddings.create(
input="Every decoding is another encoding.",
model_name="text-embedding-3-small"
)
print(response.data[0].embedding)from gen_ai_hub.proxy.langchain import init_llm, init_embedding_model
llm = init_llm("gpt-4o-mini", max_tokens=300)
result = llm.invoke("What is SAP BTP?")
print(result.content)
embeddings = init_embedding_model("text-embedding-3-small")
vector = embeddings.embed_query("SAP Business Technology Platform")from gen_ai_hub.orchestration_v2 import (
OrchestrationConfig, OrchestrationService,
ModuleConfig, PromptTemplatingModuleConfig,
Template, UserMessage, LLMModelDetails,
FilteringModuleConfig, InputFiltering, OutputFiltering,
AzureContentSafetyInput, AzureContentSafetyOutput, AzureThreshold
)
config = OrchestrationConfig(
modules=ModuleConfig(
prompt_templating=PromptTemplatingModuleConfig(
prompt=Template(template=[UserMessage(role="user", content="{{?question}}")]),
model=LLMModelDetails(name="gpt-4o-mini")
),
filtering=FilteringModuleConfig(
input=InputFiltering(filters=[
AzureContentSafetyInput(hate=AzureThreshold.ALLOW_SAFE, violence=AzureThreshold.ALLOW_SAFE)
]),
output=OutputFiltering(filters=[
AzureContentSafetyOutput(hate=AzureThreshold.ALLOW_SAFE, violence=AzureThreshold.ALLOW_SAFE)
])
)
)
)
service = OrchestrationService(config=config)
response = service.run(placeholder_values={"question": "Explain SAP."})from gen_ai_hub.orchestration_v2 import (
OrchestrationConfig, OrchestrationService,
ModuleConfig, PromptTemplatingModuleConfig,
Template, UserMessage, LLMModelDetails,
MaskingModuleConfig, MaskingProviderConfig,
DPIStandardEntity, MaskingMethod, DataMaskingProviderName
)
config = OrchestrationConfig(
modules=ModuleConfig(
prompt_templating=PromptTemplatingModuleConfig(
prompt=Template(template=[UserMessage(role="user", content="{{?text}}")]),
model=LLMModelDetails(name="gpt-4o-mini")
),
masking=MaskingModuleConfig(
masking_providers=[
MaskingProviderConfig(
type=DataMaskingProviderName.SAP_DATA_PRIVACY_INTEGRATION,
method=MaskingMethod.ANONYMIZATION,
entities=[
DPIStandardEntity(type="profile-email"),
DPIStandardEntity(type="profile-person")
]
)
]
)
)
)
service = OrchestrationService(config=config)
response = service.run(placeholder_values={"text": "Contact john@example.com for details."})from gen_ai_hub.orchestration_v2 import (
OrchestrationConfig, OrchestrationService,
ModuleConfig, PromptTemplatingModuleConfig,
Template, UserMessage, LLMModelDetails,
GroundingModuleConfig, DocumentGroundingConfig,
DocumentGroundingFilter, DocumentGroundingPlaceholders,
GroundingSearchConfig, DataRepositoryType, GroundingType
)
config = OrchestrationConfig(
modules=ModuleConfig(
prompt_templating=PromptTemplatingModuleConfig(
prompt=Template(template=[UserMessage(role="user", content="{{?question}}")]),
model=LLMModelDetails(name="gpt-4o-mini")
),
grounding=GroundingModuleConfig(
type=GroundingType.DOCUMENT_GROUNDING_SERVICE,
config=DocumentGroundingConfig(
placeholders=DocumentGroundingPlaceholders(
input=["{{?question}}"],
output="{{?context}}"
),
filters=[
DocumentGroundingFilter(
id="my-vector-repo-id",
data_repository_type=DataRepositoryType.VECTOR,
search_config=GroundingSearchConfig(max_chunk_count=5)
)
]
)
)
)
)
service = OrchestrationService(config=config)
response = service.run(placeholder_values={"question": "What is the refund policy?"})| Error | Cause | Solution |
|---|---|---|
| Missing AI Core service key/env vars | Set all |
| Model not deployed in AI Core | Deploy the model in your resource group, or use |
| Missing resource group | Set |
| Wrong package installed | Install |
Import from | Using deprecated package name | The package was renamed; import from |
| Incomplete credentials | Verify all four required env vars: |
references/getting-started-auth.mdreferences/native-clients-guide.mdreferences/orchestration-guide.mdreferences/langchain-guide.mdreferences/troubleshooting.mdgenerative-ai-hub-sdk