# Sap AI Core

> <!-- AUTO-GENERATED by export-skills.py — DO NOT EDIT -->

- Skill: `frank-luongt/sap-ai-core` (Agent Skill)
- Install (CLI): `npx skillmds@latest add frank-luongt/sap-ai-core`
- Raw SKILL.md: https://api.skillmd.com/api/skills/frank-luongt/sap-ai-core/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: frank-luongt (https://skillmd.com/u/frank-luongt)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/frank-luongt/sap-ai-core

---

<!-- AUTO-GENERATED by export-skills.py — DO NOT EDIT -->
---
name: sap-ai-core
description: SAP AI Core and Generative AI Hub integration patterns. Use when connecting AI agents to SAP S/4HANA, SuccessFactors, or Ariba via SAP BTP, or when using SAP's multi-LLM orchestration layer (Claude, GPT-4, Gemini).
tags: [sap, erp, joule, btp]
---

# SAP AI Core & Generative AI Hub

Build AI agents that connect to SAP enterprise systems using SAP AI Core's Generative AI Hub (multi-LLM), SAP BTP integration, and the ABAP SDK for Google Cloud.

## When to Use

- Connecting AI agents to SAP S/4HANA, SuccessFactors, Ariba, or Concur data
- Using SAP's Generative AI Hub as a multi-LLM orchestration layer (GPT-4, Claude, Gemini, Llama)
- Building agents that query SAP OData/REST APIs for ERP data
- Integrating with SAP Joule copilot capabilities
- Using the ABAP SDK to call AI services from within SAP systems

## SAP AI Core -- LLM Support (Most Model-Agnostic Enterprise Platform)

| Provider | Models | Access |
|---|---|---|
| **OpenAI** | GPT-4, GPT-4 Turbo, GPT-4o | Via Azure OpenAI |
| **Anthropic** | Claude 3 Haiku, Sonnet, Opus; Claude 3.5 Sonnet | Direct + Bedrock |
| **Google** | Gemini 1.0 Pro, 1.5 Pro, 1.5 Flash | Direct |
| **Meta** | Llama 2, Llama 3 | Via AI Core |
| **Mistral** | Mistral Large, Mixtral | Via AI Core |
| **Aleph Alpha** | Luminous | For European/German use cases |

## Patterns

### 1. SAP Generative AI Hub SDK

```python
from gen_ai_hub.proxy.core.proxy_clients import get_proxy_client
from gen_ai_hub.proxy.langchain.openai import ChatOpenAI

# Initialize proxy client (authenticates via SAP AI Core)
proxy_client = get_proxy_client("gen-ai-hub")

# Use with LangChain (model-agnostic)
llm = ChatOpenAI(
    proxy_model_name="gpt-4o",  # or "claude-3-5-sonnet", "gemini-1.5-pro"
    proxy_client=proxy_client,
    temperature=0.1,
)

response = llm.invoke("Summarize the purchase order approval process in SAP S/4HANA")
```

### 2. SAP OData API Integration

```python
import requests
from urllib.parse import quote

class SAPS4Client:
    def __init__(self, base_url: str, username: str, password: str):
        self.base_url = base_url.rstrip("/")
        self.auth = (username, password)
        self.headers = {
            "Accept": "application/json",
            "Content-Type": "application/json",
        }

    def _get(self, path: str, params: dict = None) -> dict:
        response = requests.get(
            f"{self.base_url}{path}",
            auth=self.auth, headers=self.headers, params=params,
        )
        response.raise_for_status()
        return response.json()

    # --- Sales Orders ---
    def get_sales_orders(self, top: int = 20, filter_expr: str = "") -> list[dict]:
        params = {"$top": top, "$format": "json"}
        if filter_expr:
            params["$filter"] = filter_expr
        result = self._get("/sap/opu/odata/sap/API_SALES_ORDER_SRV/A_SalesOrder", params)
        return result.get("d", {}).get("results", [])

    def get_sales_order(self, order_id: str) -> dict:
        return self._get(f"/sap/opu/odata/sap/API_SALES_ORDER_SRV/A_SalesOrder('{order_id}')")["d"]

    # --- Purchase Orders ---
    def get_purchase_orders(self, top: int = 20) -> list[dict]:
        result = self._get("/sap/opu/odata/sap/API_PURCHASEORDER_PROCESS_SRV/A_PurchaseOrder",
                          {"$top": top, "$format": "json"})
        return result.get("d", {}).get("results", [])

    # --- Business Partners ---
    def search_business_partners(self, name: str) -> list[dict]:
        filter_expr = f"substringof('{name}',BusinessPartnerFullName)"
        result = self._get("/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner",
                          {"$filter": filter_expr, "$top": 10, "$format": "json"})
        return result.get("d", {}).get("results", [])

    # --- Material ---
    def get_material(self, material_id: str) -> dict:
        return self._get(f"/sap/opu/odata/sap/API_PRODUCT_SRV/A_Product('{material_id}')")["d"]
```

### 3. SAP Joule Copilot Capabilities

SAP Joule provides pre-built AI skills across SAP applications:

**S/4HANA:**
- Natural language queries across ERP data
- Transaction execution (create PO, approve requests)
- Intelligent Situation Handling (automated issue detection)

**SuccessFactors:**
- Job description generation
- Interview question suggestions
- Learning content recommendations

**Ariba:**
- Supplier risk scoring
- Contract clause extraction
- Guided buying recommendations

### 4. ABAP SDK for Google Cloud (Call AI from SAP)

```abap
" Call Vertex AI Gemini from within SAP ABAP
DATA(lo_client) = NEW /goog/cl_generative_model(
  iv_model_key = 'GEMINI_PRO' ).

DATA(lv_response) = lo_client->generate_content(
  iv_prompt = 'Analyze this purchase order for compliance issues...'
)->get_text( ).

WRITE: / lv_response.
```

### 5. Google Cortex Framework for SAP Data

```sql
-- Pre-built BigQuery views over SAP data (after Cortex deployment)
-- Finance: GL accounts, AP/AR, trial balance
SELECT * FROM `cortex_sap.AccountingDocuments`
WHERE CompanyCode = '1000' AND FiscalYear = '2025';

-- Supply Chain: Purchase orders, inventory, deliveries
SELECT * FROM `cortex_sap.PurchaseOrders`
WHERE PurchasingOrganization = '1000' AND OrderStatus = 'Open';

-- Order to Cash: Sales orders, deliveries, billing
SELECT * FROM `cortex_sap.SalesOrders`
WHERE SoldToParty = 'CUST001' AND NetValue > 10000;
```

## SAP BTP Integration Architecture

```
External AI Agent
  --> SAP BTP Destination Service (manages connections)
    --> SAP Cloud Connector (for on-premise S/4HANA)
      --> SAP S/4HANA OData API
    --> SAP Integration Suite (for complex orchestration)
      --> Multiple SAP systems (S/4, SF, Ariba)
    --> SAP AI Core / Generative AI Hub
      --> LLM Provider (Claude, GPT, Gemini)
```

## Anti-Patterns

- Calling SAP APIs without CSRF token handling -- OData write operations require `x-csrf-token`
- Ignoring SAP authorization objects -- always map agent actions to SAP authorization roles
- Embedding SAP credentials -- use SAP BTP Destination Service for credential management
- Skipping pagination -- SAP OData APIs use `$skip`/`$top` for large result sets
- Using generic REST when SAP SDK exists -- use official SAP SDKs for type safety

## References

- [SAP AI Core Generative AI Hub](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/generative-ai-hub)
- [SAP Generative AI Hub SDK (PyPI)](https://pypi.org/project/generative-ai-hub-sdk/)
- [SAP Business Accelerator Hub (API Explorer)](https://api.sap.com/)
- [SAP Joule](https://www.sap.com/products/artificial-intelligence/ai-assistant.html)
- [ABAP SDK for Google Cloud](https://cloud.google.com/solutions/sap/docs/abap-sdk/latest/overview)
- [Google Cloud Cortex Framework for SAP](https://cloud.google.com/cortex/docs/overview)

<!-- Source: .faos/custom/skills/integrations/sap-ai-core/SKILL.md -->

