Our SDK offers a developer-friendly way to consume foundational models available in the SAP generative AI hub. We strive to facilitate seamless interactions with these models by providing integrations that act as drop-in replacements for the native client SDKs and LangChain.
Native Client Integrations
As of now, there are integrations with three types of native client SDKs (OpenAI, Google, Amazon).
The list of the available models can be found in the overview.
Completions
OpenAI
Completions equivalent to openai.Completions:
from gen_ai_hub.proxy.native.openai import completions
response = completions.create(
model_name="gpt-4o-mini",
prompt="The Answer to the Ultimate Question of Life, the Universe, and Everything is",
max_tokens=20,
temperature=0
)
print(response)
ChatCompletions equivalent to openai.ChatCompletions:
from gen_ai_hub.proxy.native.openai import chat
messages = [{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Does Azure OpenAI support customer managed keys?"},
{"role": "assistant", "content": "Yes, customer managed keys are supported by Azure OpenAI."},
{"role": "user", "content": "Do other Azure Cognitive Services support this too?"}]
kwargs = dict(model_name='gpt-4o-mini', messages=messages)
response = chat.completions.create(**kwargs)
print(response)
With model_version parameter:
from gen_ai_hub.proxy.native.openai import chat
messages = [{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Does Azure OpenAI support customer managed keys?"},
{"role": "assistant", "content": "Yes, customer managed keys are supported by Azure OpenAI."},
{"role": "user", "content": "Do other Azure Cognitive Services support this too?"}]
response = chat.completions.create(model_name='gpt-4o-mini', model_version="latest", messages=messages)
print(response)
With deployment_id instead of model_name:
from gen_ai_hub.proxy.native.openai import chat
messages = [{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Does Azure OpenAI support customer managed keys?"},
{"role": "assistant", "content": "Yes, customer managed keys are supported by Azure OpenAI."},
{"role": "user", "content": "Do other Azure Cognitive Services support this too?"}]
response = chat.completions.create(deployment_id="dcef02e219ae4916", messages=messages)
print(response)
Responses API
Responses equivalent to openai.Responses. See the OpenAI migration guide.
from gen_ai_hub.proxy.native.openai import responses
response = responses.create(
model="gpt-5",
instructions="You are a helpful assistant.",
input="What is the capital of France?",
)
print(response.output_text)
Structured model outputs
LLM output as JSON objects. See OpenAI structured outputs.
from pydantic import BaseModel
from gen_ai_hub.proxy.native.openai import chat, responses
class Person(BaseModel):
name: str
age: int
response = chat.completions.parse(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Tell me about John Doe, aged 30."}],
response_format=Person
)
person = response.choices[0].message.parsed # Fully typed Person
print(person)
# Using responses API
response = responses.parse(
model="gpt-5",
input="Tell me about John Doe aged 30.",
text_format=Person
)
print(response.output_parsed) # Fully typed Person
Google GenAI
Generate Content:
from gen_ai_hub.proxy.native.google_genai import Client
from gen_ai_hub.proxy import get_proxy_client
proxy_client = get_proxy_client('gen-ai-hub')
client = Client(proxy_client=proxy_client)
response = client.models.generate_content(model="gemini-2.5-flash",
contents="How many paws are there for a dog?"
)
print(response)
response = client.models.generate_content(model="gemini-2.0-flash",
contents="Explain the theory of relativity in simple terms.")
print(response)
Generate Content streaming:
from gen_ai_hub.proxy.native.google_genai import Client
from gen_ai_hub.proxy import get_proxy_client
proxy_client = get_proxy_client('gen-ai-hub')
client = Client(proxy_client=proxy_client)
response_stream = client.models.generate_content_stream(model="gemini-2.5-flash",
contents="Explain singularity in short terms.")
for chunk in response_stream:
print("Chunk: ", chunk.text)
Function Calling:
from google.genai import types
from gen_ai_hub.proxy.native.google_genai import Client
from gen_ai_hub.proxy import get_proxy_client
def get_current_weather(location: str) -> str:
"""Returns the current weather.
Args:
location: The city and state, e.g. San Francisco, CA
"""
return 'sunny'
proxy_client = get_proxy_client('gen-ai-hub')
client = Client(proxy_client=proxy_client)
response = client.models.generate_content(
model='gemini-2.5-flash',
contents='What is the weather like in Boston?',
config=types.GenerateContentConfig(tools=[get_current_weather]),
)
print(response)
Amazon
Invoke Model:
import json
from gen_ai_hub.proxy.native.amazon import Session
bedrock = Session().client(model_name="amazon--nova-premier")
body = json.dumps(
{
"inputText": "Explain black holes in astrophysics to 8th graders.",
"textGenerationConfig": {
"maxTokenCount": 3072,
"stopSequences": [],
"temperature": 0.7,
"topP": 0.9,
},
}
)
response = bedrock.invoke_model(body=body)
response_body = json.loads(response.get("body").read())
print(response_body)
Converse:
from gen_ai_hub.proxy.native.amazon import Session
bedrock = Session().client(model_name="anthropic--claude-4-sonnet")
conversation = [
{
"role": "user",
"content": [{"text": "Describe the purpose of a 'hello world' program in one line."}],
}
]
response = bedrock.converse(
messages=conversation,
inferenceConfig={"maxTokens": 512, "temperature": 0.5, "topP": 0.9},
)
print(response)
Embeddings
OpenAI
from gen_ai_hub.proxy.native.openai import embeddings
response = embeddings.create(
input="Every decoding is another encoding.",
model_name="text-embedding-ada-002"
)
print(response.data)
With encoding format:
from gen_ai_hub.proxy.native.openai import embeddings
response = embeddings.create(
input="Every decoding is another encoding.",
model_name="text-embedding-ada-002",
encoding_format='base64'
)
print(response.data)
Amazon
import json
from gen_ai_hub.proxy.native.amazon import Session
bedrock = Session().client(model_name="amazon--nova-premier")
body = json.dumps({"inputText": "Please recommend books with a theme similar to the movie 'Inception'."})
response = bedrock.invoke_model(body=body)
response_body = json.loads(response.get("body").read())
print(response_body)
LangChain Integration
LangChain provides an interface that abstracts provider-specific details into a common interface.
Harmonized Model Initialization
The init_llm and init_embedding_model functions allow easy initialization of LangChain model interfaces:
from langchain_core.prompts import PromptTemplate
from langchain_core.output_parsers import StrOutputParser
from gen_ai_hub.proxy.langchain import init_llm
template = """Question: {question}
Answer: Let's think step by step."""
prompt = PromptTemplate(template=template, input_variables=['question'])
question = 'What is a supernova?'
llm = init_llm('gpt-5-nano', max_tokens=300)
chain = prompt | llm | StrOutputParser()
response = chain.invoke({'question': question})
print(response)
from gen_ai_hub.proxy.langchain import init_embedding_model
text = 'Every decoding is another encoding.'
embeddings = init_embedding_model('text-embedding-ada-002')
response = embeddings.embed_query(text)
print(response)
LLM
from langchain import PromptTemplate
from gen_ai_hub.proxy.langchain import OpenAI
from gen_ai_hub.proxy import get_proxy_client
proxy_client = get_proxy_client('gen-ai-hub')
model_name = "mistralai--mistral-small-instruct"
llm = OpenAI(proxy_model_name=model_name, proxy_client=proxy_client)
template = """Question: {question}
Answer: Let's think step by step."""
prompt = PromptTemplate(template=template, input_variables=["question"])
llm_chain = prompt | llm
question = "What NFL team won the Super Bowl in the year Justin Bieber was born?"
print(llm_chain.invoke({'question': question}))
Chat Model
from langchain.prompts.chat import (
AIMessagePromptTemplate,
ChatPromptTemplate,
HumanMessagePromptTemplate,
SystemMessagePromptTemplate,
)
from gen_ai_hub.proxy.langchain import ChatOpenAI
from gen_ai_hub.proxy import get_proxy_client
proxy_client = get_proxy_client('gen-ai-hub')
chat_llm = ChatOpenAI(proxy_model_name='gpt-4o-mini', proxy_client=proxy_client)
template = 'You are a helpful assistant that translates english to pirate.'
system_message_prompt = SystemMessagePromptTemplate.from_template(template)
example_human = HumanMessagePromptTemplate.from_template('Hi')
example_ai = AIMessagePromptTemplate.from_template('Ahoy!')
human_message_prompt = HumanMessagePromptTemplate.from_template('{text}')
chat_prompt = ChatPromptTemplate.from_messages(
[system_message_prompt, example_human, example_ai, human_message_prompt])
chain = chat_prompt | chat_llm
response = chain.invoke({'text': 'I love planking.'})
print(response.content)
Structured model outputs
from gen_ai_hub.proxy.langchain import ChatOpenAI
from gen_ai_hub.proxy import get_proxy_client
from langchain.schema import HumanMessage
from pydantic import BaseModel
class Person(BaseModel):
name: str
age: int
chat_model = ChatOpenAI(proxy_model_name="gpt-4o-mini", proxy_client=get_proxy_client())
chat_model = chat_model.with_structured_output(method="json_schema", schema=Person, strict=True)
message = HumanMessage(content="Tell me about a person named John who is 30")
print(chat_model.invoke([message]))
Embeddings
from gen_ai_hub.proxy.langchain import OpenAIEmbeddings
from gen_ai_hub.proxy import get_proxy_client
proxy_client = get_proxy_client('gen-ai-hub')
embedding_model = OpenAIEmbeddings(proxy_model_name='text-embedding-ada-002', proxy_client=proxy_client)
response = embedding_model.embed_query('Every decoding is another encoding.')
# Without proxy_client
embedding_model = OpenAIEmbeddings(proxy_model_name='text-embedding-ada-002')
response = embedding_model.embed_query('Every decoding is another encoding.')
print(response)
SAP RPT-1 Models
SAP-RPT-1 is a relational pretrained transformer for use on relational and structured data. It solves predictive tasks such as classification and regression out-of-the-box via in-context learning.
For detailed information visit the SAP Help Portal.
Regression
from gen_ai_hub.proxy.native.sap import RPTRequest, PredictionConfig, TargetColumn, RPTClient
rows_regression = [
{"PRODUCT": "Couch", "PRICE": 999.99, "ORDERDATE": "28-11-2025", "ID": "35", "DISCOUNT_RATE": "[PREDICT]"},
{"PRODUCT": "Office Chair", "PRICE": 150.80, "ORDERDATE": "02-11-2025", "ID": "44", "DISCOUNT_RATE": 0.12},
{"PRODUCT": "Server Rack", "PRICE": 2200.00, "ORDERDATE": "01-11-2025", "ID": "104", "DISCOUNT_RATE": 0.05},
{"PRODUCT": "Standing Desk", "PRICE": 640.00, "ORDERDATE": "05-11-2025", "ID": "205", "DISCOUNT_RATE": 0.10},
{"PRODUCT": "Monitor 27 inch", "PRICE": 289.99, "ORDERDATE": "08-11-2025", "ID": "306", "DISCOUNT_RATE": "[PREDICT]"},
]
client = RPTClient()
body = RPTRequest(
prediction_config=PredictionConfig(
target_columns=[TargetColumn(name="DISCOUNT_RATE", task_type="regression")]
),
rows=rows_regression
)
response = client.predict(body=body, model_name="sap-rpt-1-small")
print(response.predictions)
# With model_version
response = client.predict(body=body, model_name="sap-rpt-1-small", model_version="latest")
print(response.predictions)
Classification
example_request_by_columns_dict = {
"prediction_config": {
"target_columns": [{"name": "COSTCENTER", "prediction_placeholder": "[PREDICT]", "task_type": "classification"}]
},
"columns": {
"PRODUCT": ["Couch", "Office Chair", "Server Rack"],
"PRICE": [999.99, 150.8, 2200.00],
"ORDERDATE": ["28-11-2025", "02-11-2025", "01-11-2025"],
"ID": ["35", "44", "104"],
"COSTCENTER": ["[PREDICT]", "Office Furniture", "Data Infrastructure"]
},
"data_schema": {
"PRODUCT": {"dtype": "string"},
"PRICE": {"dtype": "numeric"},
"ORDERDATE": {"dtype": "date"},
"ID": {"dtype": "string"},
"COSTCENTER": {"dtype": "string"}
}
}
response = client.predict(body=example_request_by_columns_dict, model_name="sap-rpt-1-small")
print(response.predictions)
Async
await client.apredict(body=example_request_by_columns_dict, model_name="sap-rpt-1-small")