SAP AI Core Provider
The AI SDK supports SAP AI Core through two community providers:
- @jerome-benoit/sap-ai-provider - Language Model V3 for AI SDK 5.x & 6.x (recommended)
- @jerome-benoit/sap-ai-provider-v2 - Language Model V2 for AI SDK 5.x
Both providers are built on the official @sap-ai-sdk/orchestration package and provide access to 80+ models (GPT-4o, Claude, Gemini, Amazon Nova, Llama) through SAP's enterprise-grade AI platform.
Choosing Your Provider
For New Projects (Recommended)
@jerome-benoit/sap-ai-provider implements Language Model V3 specification with:
- AI SDK 5.x and 6.x compatibility
- Enhanced streaming with structured V3 blocks
- Latest AI SDK features support
For AI SDK 5.x with V2 Specification
@jerome-benoit/sap-ai-provider-v2 is maintained for projects that require Language Model V2 specification compatibility.
Both providers share the same API surface and features - only the underlying specification differs.
Setup
Choose and install your preferred provider:
@jerome-benoit/sap-ai-provider (V3)
pnpm add @jerome-benoit/sap-ai-provider ai
@jerome-benoit/sap-ai-provider-v2 (V2)
pnpm add @jerome-benoit/sap-ai-provider-v2 ai
The features documented below require version 4.3.0 or higher of the provider package.
Environment Variables
Authentication is handled via the AICORE_SERVICE_KEY environment variable containing your SAP AI Core service key JSON.
Provider Instance
You can import the default provider instance sapai from the package:
import { sapai } from '@jerome-benoit/sap-ai-provider';If you need a customized setup, you can import createSAPAIProvider and create a provider instance with your settings:
import { createSAPAIProvider } from '@jerome-benoit/sap-ai-provider';
const sapai = createSAPAIProvider({ resourceGroup: 'default', // optional settings});You can use the following optional settings to customize the provider instance:
-
resourceGroup string
SAP AI Core resource group. Defaults to
'default'. -
deploymentId string
Specific deployment ID. If not provided, the SDK resolves deployment automatically.
Language Models
You can create models that call the SAP AI Core Orchestration API using the provider instance. The first argument is the model id.
const model = sapai('gpt-4o');Model naming follows SAP AI Core conventions. Some models require vendor prefixes:
const gpt4Model = sapai('gpt-4o');const claudeModel = sapai('anthropic--claude-3.5-sonnet');const geminiModel = sapai('gemini-2.0-flash');const novaModel = sapai('amazon--nova-pro');Model availability depends on your SAP AI Core tenant configuration and region.
Embedding Models
You can create models that call the SAP AI Core embeddings API using the .embeddingModel() factory method.
const model = sapai.embeddingModel('text-embedding-ada-002');Embedding models use the same naming convention as language models. Azure OpenAI embedding models (e.g., text-embedding-ada-002, text-embedding-3-small) do not require a vendor prefix.
Examples
generateText
import { sapai } from '@jerome-benoit/sap-ai-provider';import { generateText } from 'ai';
const { text } = await generateText({ model: sapai('gpt-4o'), prompt: 'What are the benefits of enterprise AI platforms?',});
console.log(text);streamText
import { sapai } from '@jerome-benoit/sap-ai-provider';import { streamText } from 'ai';
const result = streamText({ model: sapai('anthropic--claude-3.5-sonnet'), prompt: 'Write a short story about AI.',});
for await (const textPart of result.textStream) { process.stdout.write(textPart);}Embeddings
import { sapai } from '@jerome-benoit/sap-ai-provider';import { embed, embedMany } from 'ai';
const { embedding } = await embed({ model: sapai.embeddingModel('text-embedding-ada-002'), value: 'What is machine learning?',});
console.log(embedding);
const { embeddings } = await embedMany({ model: sapai.embeddingModel('text-embedding-3-small'), values: ['Hello world', 'AI is amazing', 'Vector search'],});
console.log(embeddings);Tool Calling
import { sapai } from '@jerome-benoit/sap-ai-provider';import { generateText, tool } from 'ai';import { z } from 'zod';
const { text } = await generateText({ model: sapai('gpt-4o'), prompt: 'What is the weather in Tokyo?', tools: { getWeather: tool({ description: 'Get weather for a location', parameters: z.object({ location: z.string() }), execute: async ({ location }) => `Weather in ${location}: sunny, 72°F`, }), }, maxSteps: 3,});
console.log(text);Advanced Features
The provider supports SAP AI Core enterprise features:
- Data Masking - SAP Data Privacy Integration (DPI) for anonymization
- Content Filtering - Azure Content Safety and Llama Guard
- Document Grounding - RAG with vector databases
- Translation - Automatic input/output translation
For complete documentation on these features, see the SAP AI Provider Repository.
Model Capabilities
| Model | Image Input | Object Generation | Tool Usage | Tool Streaming |
|---|---|---|---|---|
gpt-4o | ||||
anthropic--claude-3.5-sonnet | ||||
gemini-2.0-flash | ||||
amazon--nova-pro |
Google Gemini models have a 1 tool limit per request. For multi-tool applications, use GPT-4o, Claude, or Amazon Nova models.
Resources
This provider is developed by jerome-benoit, not SAP SE. While it uses the official SAP AI SDK, it is not an official SAP product.