PackagePackagetypeA library you install and call yourself.See every one →What this type is →independently maintainedindependently maintainedoriginPublished by one person or a small company outside SAP. Says nothing about quality; the readings say that.See every one →

@jerome-benoit/sap-ai-provider

A provider for the Vercel AI SDK that speaks to SAP AI Core through its orchestration or foundation models API, so an application written against that SDK runs on SAP's models without being rewritten.

An application written against the Vercel AI SDK keeps its code and changes where the model comes from. This package is that provider for SAP AI Core, reaching the models AI Core hosts through its orchestration API by default or its foundation models API instead, and it streams the generated text rather than returning the whole answer at once. The README calls it a community provider and names compatibility with AI SDK 5 to 7 behind versioned entrypoints. It replaces the model, not the SDK: the loop, the prompt and the surface stay the Vercel SDK's, and the service binding and the deployment stay the project's.

Facts

Latestv5.0.3ReleasedLast pushLicenceApache-2.0

Where it sits

Lives in
Provides
LLM integrationCAPLLM integrationcapabilityCalling a language model from application code with the tenant, destination and credential handling already solved instead using an SDK call with a hand-rolled key.

Who is behind it

Jérôme BenoitJérôme BenoitPersonMaintains this
In the atlas: maintains 1, contributes to 6
@jerome-benoit
maintainerDavid KnaackPersonContributes to this
In the atlas: contributes to 13, wrote 1
@davidkna-sap
1 contributor

Before choosing this

Conditions

LicenceSAP Developer License Agreement 3.2 CAP§ 3from LLM integrationCovered SAP materials or a covered CAP customer application are used as training data or to develop or refine an AI model or system.
  • § 3 Artificial Intelligence Training. The agreement prohibits use of the covered materials and customer applications for training artificial-intelligence models or systems.

Calling a model for inference is not automatically AI training. Section 3 matters when the covered material or application participates in training, model development, refinement or the text-and-data-mining uses it names.

SAP Developer License Agreement 3.2 CAP →

What it declares

Every artifact

Type
Package
Origin
Independently maintained

As a package

Where it runs
does not say
Distributed through
npm

For LLM integration

Supports
Streams the response
Models it reaches
SAP AI Core
property statedstated nonot said

Tasks this contributes to2Beta

Change which model a CAP service callsA CAP service that already calls a language model is pointed at a different one — a newer version, a cheaper one, or a model from another vendor — and the handler that calls it is not rewritten.Also in BTP/BAIP, ABAPAssessed, not knownprovider for an SDK written elsewhere
What it does

Reaches the models SAP AI Core hosts through its orchestration API or its foundation models API, behind the interface a Vercel AI SDK application already calls. What the README does not say is what changes when the model does: it names the models available and the two routes, and no sentence states that the switch leaves the calling code alone.

Remaining work

Read how the model is named when the provider is constructed, which this reading did not establish, before relying on the switch being configuration.

All options on the LLM integration page →
Stream a model's answer out of a CAP serviceA CAP service receives a model's answer in pieces as the model writes it, rather than one payload after the model has finished, so a chat surface can show text appearing instead of a spinner.Coversstreaming provider for an SDK written elsewhere
What it does

Keeps the stream the Vercel AI SDK already expects while the model comes from SAP AI Core: the README lists streaming support among the package's features, as real-time text generation with structured V3 blocks.

Remaining work

Carry the chunks onward through whatever the Vercel AI SDK application already uses for that, and read which of the package's versioned entrypoints the project is on, since the README names AI SDK 5 to 7 behind separate ones.

All options on the LLM integration page →

Connections1

Install

npm add @jerome-benoit/sap-ai-provider

Derived from the package name. No recipe recorded; the README has the configuration.

README

quoted from jerome-benoit/sap-ai-provider under Apache-2.0, read
jerome-benoit/sap-ai-provider/README.mdOn GitHub

SAP AI Provider for Vercel AI SDK

npm License: Apache-2.0 Vercel AI SDK Language Model Embedding Model

A community provider for SAP AI Core that integrates seamlessly with the Vercel AI SDK. Built on top of the official @sap-ai-sdk/orchestration and @sap-ai-sdk/foundation-models packages, this provider enables you to use SAP's enterprise-grade AI models through the familiar Vercel AI SDK interface.

Table of Contents

Features

  • 🔐 Simplified Authentication - Uses SAP AI SDK's built-in credential handling
  • 🎯 Tool Calling Support - Full tool/function calling capabilities
  • 🧠 Reasoning-Safe by Default - Assistant reasoning parts are not forwarded unless enabled
  • 🖼️ Multi-modal Input - Support for text and image inputs
  • 📡 Streaming Support - Real-time text generation with structured V3 blocks
  • 🔒 Data Masking - Built-in SAP DPI integration for privacy
  • 🛡️ Content Filtering - Azure Content Safety and Llama Guard support
  • 🔧 TypeScript Support - Full type safety and IntelliSense
  • 🎨 Multiple Models - Support for OpenAI, Claude, Gemini, Nova, and more
  • 🔄 AI SDK 5–7 Compatibility - Versioned V2, V3, and V4 entrypoints preserve the matching Vercel AI SDK provider specification
  • 📊 Text Embeddings - Generate vector embeddings for RAG and semantic search
  • 🔀 Dual API Support - Choose between Orchestration or Foundation Models API per provider, model, or call
  • 📦 Stored Configuration Support - Reference orchestration configurations or prompt templates from SAP AI Core

Quick Start

npm install @jerome-benoit/sap-ai-provider ai@^6 dotenv
import "dotenv/config"; // Load environment variables
import { createSAPAIProvider } from "@jerome-benoit/sap-ai-provider";
import { generateText } from "ai";
import { APICallError } from "@ai-sdk/provider";

// Create provider (authentication via AICORE_SERVICE_KEY env var)
const provider = createSAPAIProvider();

try {
  // Generate text with gpt-4.1
  const result = await generateText({
    model: provider("gpt-4.1"),
    prompt: "Explain quantum computing in simple terms.",
  });

  console.log(result.text);
} catch (error) {
  process.exitCode = 1;
  if (APICallError.isInstance(error)) {
    console.error("SAP AI Core API error:", error.statusCode, error.name);
  } else {
    console.error("Unexpected error:", error instanceof Error ? error.name : "Unknown error");
  }
}

Note: For local service-key setup, set AICORE_SERVICE_KEY. SAP BTP service bindings and custom destinations are alternatives. See Environment Setup for configuration.

Quick Reference

TaskCode PatternDocumentation
Installnpm install @jerome-benoit/sap-ai-provider ai@^6Installation
Auth SetupAdd AICORE_SERVICE_KEY to .envEnvironment Setup
Create ProvidercreateSAPAIProvider() or use sapaiProvider Creation
Text GenerationgenerateText({ model: provider("gpt-4.1"), prompt })Basic Usage
StreamingstreamText({ model: provider("gpt-4.1"), prompt })Streaming
Tool CallinggenerateText({ tools: { myTool: tool({...}) } })Tool Calling
Error Handlingif (APICallError.isInstance(error)) { /* handle error */ }API Reference
Choose ModelDiscover models available in your tenantModels
Embeddingsembed({ model: provider.embedding("text-embedding-3-small") })Embeddings

Installation

Requirements: Node.js 22.12+. The provider entrypoint must match the installed AI SDK major.

The published package targets Node.js. Its ESM output uses Node module.createRequire, and the SAP SDK dependency chain relies on Node APIs. The source-level Edge test suite does not establish deployability to pure Edge runtimes such as Cloudflare Workers; use a Node.js server runtime for deployment.

AI SDKInstallProvider import
7npm install @jerome-benoit/sap-ai-provider ai@^7@jerome-benoit/sap-ai-provider/v4
6npm install @jerome-benoit/sap-ai-provider ai@^6@jerome-benoit/sap-ai-provider or @jerome-benoit/sap-ai-provider/v3
5npm install @jerome-benoit/sap-ai-provider ai@^5@jerome-benoit/sap-ai-provider/v2

/v3 is an explicit alias for the AI SDK 6 root entrypoint. Both resolve to the same runtime modules and TypeScript declarations, including the same sapai instance within each module format; existing root imports remain valid.

The Quick Start and inline snippets on this page use AI SDK 6 with the root V3 entrypoint. The runnable files in examples/ use the repository's installed AI SDK 7 with the V4 entrypoint. For AI SDK 7, install ai@^7 and import createSAPAIProvider or sapai from @jerome-benoit/sap-ai-provider/v4:

npm install @jerome-benoit/sap-ai-provider ai@^7

The V4 entrypoint exposes the same provider aliases and version-independent helpers as the root V3 entrypoint. Its standardized reasoning option maps to SAP's reasoning_effort model parameter. provider-default preserves an explicit modelParams.reasoning_effort; a stored orchestrationConfigRef owns the model configuration and ignores local reasoning options with a warning. See the V4 API reference for the full normalization and precedence contract.

V2 facade: AI SDK 5, AI SDK 6 through its V2 compatibility layer, and other LanguageModelV2/EmbeddingModelV2 consumers can use the main package's v2 subpath or the dedicated V2 package:

npm install @jerome-benoit/sap-ai-provider ai@^5
# Alternatively: npm install @jerome-benoit/sap-ai-provider-v2 ai@^5

Both entrypoints expose the same V2 facade:

import { createSAPAIProvider } from "@jerome-benoit/sap-ai-provider/v2";
// Dedicated-package alternative:
// import { createSAPAIProvider } from "@jerome-benoit/sap-ai-provider-v2";

The V2 type contracts are bundled at build time; neither package installs a second provider package through the @ai-sdk/provider-v2 alias. When using V2 with AI SDK 6, use the latest 6.x patch: the initial 6.0.0 embedding compatibility adapter has an upstream warning-handling failure that is absent in 6.0.280.

See Architecture - Versioned Packages for the V4/V3/V2 packaging model.

Provider Creation

You can create an SAP AI provider in two ways:

import "dotenv/config"; // Load environment variables
import { createSAPAIProvider } from "@jerome-benoit/sap-ai-provider";

const provider = createSAPAIProvider({
  resourceGroup: "production",
  deploymentId: "your-deployment-id", // Optional
});
API Selection

The provider supports two SAP AI Core APIs:

  • Orchestration API (default): Full-featured API with data masking, content filtering, document grounding, and translation
  • Foundation Models API: Direct model access with additional parameters like logprobs, seed, logit_bias, and dataSources (Azure On Your Data)

Complete example: examples/example-foundation-models.ts
Complete documentation: API Reference - Foundation Models API

import { createSAPAIProvider, SAP_AI_PROVIDER_NAME } from "@jerome-benoit/sap-ai-provider";

// Provider-level API selection
const provider = createSAPAIProvider({
  api: "foundation-models", // All models use Foundation Models API
});

// Model-level API override
const model = provider("gpt-4.1", {
  api: "orchestration", // Override for this model only
});

// Per-call API override via providerOptions
const result = await generateText({
  model: provider("gpt-4.1"),
  prompt: "Hello",
  providerOptions: {
    [SAP_AI_PROVIDER_NAME]: {
      api: "foundation-models", // Override for this call only
    },
  },
});

Run it: npx tsx examples/example-foundation-models.ts

Note: The Foundation Models API does not support orchestration features (masking, filtering, grounding, translation). Attempting to use these features with Foundation Models API will throw an UnsupportedFeatureError.

Option 2: Default Instance (Quick Start)
import "dotenv/config"; // Load environment variables
import { sapai } from "@jerome-benoit/sap-ai-provider";
import { generateText } from "ai";

// Use directly with auto-detected configuration
const result = await generateText({
  model: sapai("gpt-4.1"),
  prompt: "Hello!",
});

The sapai export provides a convenient default provider instance with automatic configuration from environment variables or service bindings.

Provider Methods

The provider is callable and also exposes explicit methods:

// Callable syntax (creates language model)
const chatModel = provider("gpt-4.1");

// Explicit method syntax
const explicitChatModel = provider.chat("gpt-4.1");
const embeddingModel = provider.embedding("text-embedding-3-small");

Available methods:

MethodDescription
provider(modelId)Callable syntax, creates language model
provider.chat(modelId)Creates language model (alias)
provider.languageModel(modelId)Creates language model (ProviderV3 standard)
provider.embedding(modelId)Creates embedding model (alias)
provider.embeddingModel(modelId)Creates embedding model (ProviderV3 standard)
provider.textEmbeddingModel(modelId)Creates embedding model (alias)

embedding() and embeddingModel() are identical. textEmbeddingModel() is deprecated in the V3 and V4 entrypoints — use embeddingModel() instead.

Note: The V2 facade package (@jerome-benoit/sap-ai-provider-v2) only exposes textEmbeddingModel() for embeddings per the ProviderV2 specification. Use the V3 root with AI SDK 6 or V4 subpath with AI SDK 7 if you need these aliases.

Authentication

Authentication is handled automatically by the SAP AI SDK via the AICORE_SERVICE_KEY environment variable (local) or VCAP_SERVICES (SAP BTP).

→ Environment Setup Guide - Complete setup instructions, SAP BTP deployment, and troubleshooting.

Basic Usage

Text Generation

Complete example: examples/example-generate-text.ts

const result = await generateText({
  model: provider("gpt-4.1"),
  prompt: "Write a short story about a robot learning to paint.",
});
console.log(result.text);

Run it: npx tsx examples/example-generate-text.ts

Chat Conversations

Complete example: examples/example-simple-chat-completion.ts

Note: Assistant reasoning parts are dropped by default. Set includeReasoning: true on the model settings if you explicitly want to forward them.

const result = await generateText({
  model: provider("anthropic--claude-4.5-sonnet"),
  messages: [
    { role: "system", content: "You are a helpful coding assistant." },
    {
      role: "user",
      content: "How do I implement binary search in TypeScript?",
    },
  ],
});

Run it: npx tsx examples/example-simple-chat-completion.ts

Streaming Responses

Complete example: examples/example-streaming-chat.ts

import { streamText } from "ai";
import { APICallError } from "@ai-sdk/provider";

try {
  let streamError: unknown;
  const result = streamText({
    model: provider("gpt-4.1"),
    prompt: "Explain machine learning concepts.",
    onError({ error }) {
      streamError = error;
    },
  });

  for await (const delta of result.textStream) {
    process.stdout.write(delta);
  }

  // textStream does not throw stream errors; preserve the original API error.
  if (streamError !== undefined) throw streamError;

  // streamText returns a result object; its usage property is a promise.
  console.log("\n\nUsage:", await result.usage);
} catch (error) {
  process.exitCode = 1;
  if (APICallError.isInstance(error)) {
    console.error("API error:", error.statusCode, error.name);
  } else {
    console.error("Streaming failed:", error instanceof Error ? error.name : "Unknown error");
  }
}

Run it: npx tsx examples/example-streaming-chat.ts

Note: For comprehensive error handling patterns, see the Error Handling section and API Reference - Error Types.

Model Configuration
import "dotenv/config"; // Load environment variables
import { createSAPAIProvider } from "@jerome-benoit/sap-ai-provider";
import { generateText } from "ai";

const provider = createSAPAIProvider();

const model = provider("gpt-4.1", {
  // Optional: include assistant reasoning parts (chain-of-thought).
  // Best practice is to keep this disabled.
  includeReasoning: false,
  modelParams: {
    temperature: 0.3,
    maxTokens: 2000,
    topP: 0.9,
  },
});

const result = await generateText({
  model,
  prompt: "Write a technical blog post about TypeScript.",
});
Embeddings

Generate vector embeddings for RAG (Retrieval-Augmented Generation), semantic search, and similarity matching.

Complete example: examples/example-embeddings.ts

import "dotenv/config"; // Load environment variables
import { createSAPAIProvider } from "@jerome-benoit/sap-ai-provider";
import { embed, embedMany } from "ai";

const provider = createSAPAIProvider();

// Single embedding
const { embedding } = await embed({
  model: provider.embedding("text-embedding-3-small"),
  value: "What is machine learning?",
});

// Multiple embeddings
const { embeddings } = await embedMany({
  model: provider.embedding("text-embedding-3-small"),
  values: ["Hello world", "AI is amazing", "Vector search"],
});

Run it: npx tsx examples/example-embeddings.ts

Note: Embedding model availability depends on your SAP AI Core tenant configuration. Common providers include OpenAI, Amazon Titan, and NVIDIA.

For complete embedding API documentation, see API Reference: Embeddings.

Supported Models

This provider supports all models available through SAP AI Core, including models from OpenAI, Anthropic Claude, Google Gemini, Amazon Nova, Mistral AI, Cohere, and SAP (ABAP, RPT).

Note: Model availability depends on your SAP AI Core tenant configuration, region, and subscription. Use provider("model-name") with any model ID available in your environment.

For details on discovering available models, see API Reference: Supported Models.

Advanced Features

The following helper functions are exported by this package for convenient configuration of SAP AI Core features. These builders provide type-safe configuration for data masking, content filtering, grounding, and translation modules.

Tool Calling

Note on Terminology: This documentation uses "tool calling" (Vercel AI SDK convention), equivalent to "function calling" in OpenAI documentation. Both terms refer to the same capability of models invoking external functions.

📖 Complete guide: API Reference - Tool Calling
Complete example: examples/example-chat-completion-tool.ts

import { generateText, stepCountIs, tool } from "ai";
import { z } from "zod";
import { createSAPAIProvider } from "@jerome-benoit/sap-ai-provider";

const provider = createSAPAIProvider();

const weatherTool = tool({
  description: "Get weather for a location",
  inputSchema: z.object({ location: z.string() }),
  execute: async (args) => `Weather in ${args.location}: sunny, 72°F`,
});

const result = await generateText({
  model: provider("gpt-4.1"),
  prompt: "What's the weather in Tokyo?",
  tools: { getWeather: weatherTool },
  stopWhen: stepCountIs(3),
});

Run it: npx tsx examples/example-chat-completion-tool.ts

⚠️ Model Limitations: Some models have tool calling restrictions. See API Reference - Model-Specific Tool Limitations for upstream support documentation.

Multi-modal Input (Images)

Complete example: examples/example-image-recognition.ts

const result = await generateText({
  model: provider("gpt-4.1"),
  messages: [
    {
      role: "user",
      content: [
        { type: "text", text: "What do you see in this image?" },
        { type: "image", image: new URL("https://example.com/image.jpg") },
      ],
    },
  ],
});

Run it: npx tsx examples/example-image-recognition.ts

Data Masking (SAP DPI)

Use SAP's Data Privacy Integration to mask sensitive data:

Complete example: examples/example-data-masking.ts
Complete documentation: API Reference - Data Masking

import { buildDpiMaskingProvider } from "@jerome-benoit/sap-ai-provider";

const dpiConfig = buildDpiMaskingProvider({
  method: "anonymization",
  entities: ["profile-email", "profile-person", "profile-phone"],
});

Run it: npx tsx examples/example-data-masking.ts

Content Filtering

Content filtering is available through the Orchestration API.

Complete example: examples/example-content-filtering.ts
Complete documentation: API Reference - Content Filtering

Run it: npx tsx examples/example-content-filtering.ts

Document Grounding (RAG)

Ground LLM responses in your own documents using vector databases.

Complete example: examples/example-document-grounding.ts
Complete documentation: API Reference - Document Grounding

const provider = createSAPAIProvider({
  defaultSettings: {
    grounding: buildDocumentGroundingConfig({
      filters: [{ id: "knowledge-filter", data_repositories: ["*"] }],
      placeholders: { input: ["groundingRequest"], output: "groundingOutput" },
    }),
  },
});

const result = await generateText({
  model: provider("gpt-4.1"),
  prompt: "Question: {{?groundingRequest}}\nContext: {{?groundingOutput}}",
  providerOptions: {
    "sap-ai": {
      escapeTemplatePlaceholders: false,
      placeholderValues: { groundingRequest: "What is SAP?" },
    },
  },
});

Set escapeTemplatePlaceholders to false only when intentionally sending SAP or Jinja placeholders in prompts or messages.

Run it: npx tsx examples/example-document-grounding.ts

Translation

Automatically translate user queries and model responses.

Complete example: examples/example-translation.ts
Complete documentation: API Reference - Translation

const provider = createSAPAIProvider({
  defaultSettings: {
    translation: {
      // Translate user input from German to English
      input: buildTranslationConfig("input", {
        sourceLanguage: "de",
        targetLanguage: "en",
      }),
      // Translate model output from English to German
      output: buildTranslationConfig("output", {
        targetLanguage: "de",
      }),
    },
  },
});

// Model handles German input/output automatically
const model = provider("gpt-4.1");

Run it: npx tsx examples/example-translation.ts

Provider Options (Per-Call Overrides)

Override constructor settings on a per-call basis using providerOptions. Only the documented per-call fields are supported: unknown top-level fields are stripped by the Zod schemas, while additional modelParams keys pass through. Standard AI SDK generation options (for example, temperature) take precedence over the corresponding providerOptions model parameters.

import { generateText } from "ai";
import { createSAPAIProvider, SAP_AI_PROVIDER_NAME } from "@jerome-benoit/sap-ai-provider";

const provider = createSAPAIProvider();

const result = await generateText({
  model: provider("gpt-4.1"),
  prompt: "Explain quantum computing",
  providerOptions: {
    [SAP_AI_PROVIDER_NAME]: {
      includeReasoning: true,
      modelParams: {
        temperature: 0.7,
        maxTokens: 1000,
      },
    },
  },
});

Complete documentation: API Reference - Provider Options

Configuration Options

The provider and models can be configured with various settings for authentication, model parameters, data masking, content filtering, and more.

Common Configuration:

  • name: Provider identifier prefix (default: 'sap-ai'). The segment before the first dot is used as the key in providerOptions/providerMetadata.
  • resourceGroup: SAP AI Core resource group (default: 'default')
  • deploymentId: Specific deployment ID (auto-resolved if not set)
  • requestConfig: Custom HTTP request configuration (headers, params, timeout, etc.) forwarded to the underlying SAP AI SDK client on every call. Provider-level scope only; per-call headers can override individual headers. Use requestConfig.headers for SAP-specific headers such as AI-Object-Store-Secret-Name (feedback service). See API Reference for portability caveats.
  • modelParams: Temperature, maxTokens, topP, and other generation parameters
  • masking: SAP Data Privacy Integration (DPI) configuration
  • filtering: Content safety filters (Azure Content Safety, Llama Guard)

For complete configuration reference including all available options, types, and examples, see API Reference - Configuration.

Error Handling

The provider uses standard Vercel AI SDK error types (APICallError, LoadAPIKeyError, NoSuchModelError from @ai-sdk/provider) for consistent error handling across providers.

Documentation:

Troubleshooting

Quick Reference:

  • Authentication (401): Check AICORE_SERVICE_KEY or VCAP_SERVICES
  • Model not found (404): Confirm tenant/region supports the model ID
  • Rate limit (429): High-level AI SDK calls retry eligible errors with exponential backoff, bounded by maxRetries; direct provider calls do not implement retries
  • Streaming: Iterate textStream correctly; don't mix generateText and streamText

For detailed solutions, see Troubleshooting Guide covering authentication, model discovery, rate limiting, server errors, streaming, and tool calling.

Error codes: API Reference - HTTP Status Codes

Performance

  • Prefer streaming (streamText) for long outputs to reduce latency and memory.
  • Tune modelParams carefully: lower temperature for less variable results; set maxTokens to expected response size.
  • Use defaultSettings at provider creation to share configuration across models; settings are still merged and validated when models and calls are prepared.
  • Avoid unnecessary history: keep messages concise to reduce prompt size and cost.

Security

Follow security best practices when handling credentials. See Environment Setup - Security Best Practices for detailed guidance on credential management, key rotation, and secure deployment.

Debug Mode

  • Use the curl guide CURL_API_TESTING_GUIDE.md to diagnose raw API behavior independent of the SDK.
  • Log request IDs from error.responseBody (parse JSON for request_id) to correlate with backend traces.
  • Temporarily enable verbose logging in your app around provider calls; redact secrets.

Examples

The examples/ directory contains complete, runnable examples using the repository's AI SDK 7 dependency and the local ../src/index-v4 entrypoint. In an AI SDK 7 application, import from @jerome-benoit/sap-ai-provider/v4. See Installation for other AI SDK versions.

ExampleDescriptionKey Features
example-generate-text.tsBasic text generationSimple prompts, non-streaming generation
example-simple-chat-completion.tsSimple chat conversationSystem messages, user prompts
example-chat-completion-tool.tsTool calling with functionsDemo weather tool, function execution
example-streaming-chat.tsStreaming responsesReal-time text generation, SSE
example-image-recognition.tsMulti-modal with imagesVision models, image analysis
example-data-masking.tsData privacy integrationDPI masking, anonymization
example-content-filtering.tsContent filteringAzure Content Safety, orchestration
example-document-grounding.tsDocument grounding (RAG)Vector store, retrieval-augmented gen
example-translation.tsInput/output translationMulti-language support, SAP translation
example-embeddings.tsText embeddingsVector generation, semantic similarity
example-foundation-models.tsFoundation Models APIDirect model access, logprobs, seed

Running Examples:

npx tsx examples/example-generate-text.ts

Note: Configure AICORE_SERVICE_KEY locally or bind the application to SAP AI Core on SAP BTP. See Environment Setup.

Migration Guides

Upgrading from v4.x to v5.x

Version 5.0 adds AI SDK 7 support through the V4 facade and requires Node.js 22.12 or newer for both packages. The root entrypoint remains V3 for AI SDK 6; upgrading the provider does not require switching SDKs.

Key changes:

  • Runtime: Upgrade local, CI and deployment environments from Node.js 20 to Node.js 22.12 or newer.
  • Entrypoints: Use /v4 with SDK 7, the root with SDK 6, or /v2 with SDK 5. The standalone V2 package remains available for SDK 5/6.
  • Multimodal inputs: V4 tagged JPEG/PDF inputs are normalized correctly; unsupported binary objects are rejected instead of silently stringified.

See the 4.x to 5.x migration guide for installation commands, compatibility details and the migration checklist.

Upgrading from v3.x to v4.x

Version 4.0 migrates from LanguageModelV2 to LanguageModelV3 specification (AI SDK 6). Package release 4.x is not the V4 provider specification used by AI SDK 7. See the Migration Guide for complete upgrade instructions.

Key changes in direct provider results (doGenerate/doStream):

  • Finish Reason: Changed from string to object (result.finishReason.unified)
  • Usage Structure: Nested format with detailed token breakdown (result.usage.inputTokens.total)
  • Stream Events: Text blocks retain text-start, text-delta, and text-end; finish and warning payloads use the V3 format
  • Warning Types: Updated format with feature field for categorization

Impact by user type:

  • High-level API users (generateText/streamText): use AI SDK 6 with the root entrypoint. High-level token totals remain flat numbers.
  • Direct provider users: ⚠️ Update type imports (LanguageModelV2 → LanguageModelV3)
  • Custom stream parsers: ⚠️ Update parsing logic for V3 structure
Upgrading from v2.x to v3.x

Version 3.0 standardizes error handling to use Vercel AI SDK native error types. See the Migration Guide for complete upgrade instructions.

Key changes:

  • SAPAIError removed → Use APICallError from @ai-sdk/provider
  • Error properties: error.code → error.statusCode
  • Retryable error classification for the AI SDK's rate-limit/server-error retries
Upgrading from v1.x to v2.x

Version 2.0 uses the official SAP AI SDK. See the Migration Guide for complete upgrade instructions.

Key changes:

  • Authentication via AICORE_SERVICE_KEY environment variable
  • Synchronous provider creation: createSAPAIProvider() (no await)
  • Helper functions from SAP AI SDK

For detailed migration instructions with code examples, see the complete Migration Guide.

Important Note

Third-Party Provider: This SAP AI Provider (@jerome-benoit/sap-ai-provider) is developed and maintained by jerome-benoit, not by SAP SE. While it uses the official SAP AI SDK and integrates with SAP AI Core services, it is not an official SAP product.

Contributing

We welcome contributions! Please see our Contributing Guide for details.

Resources

Documentation
Community
  • 🐛 Issue Tracker - Report bugs, request features, and ask questions

License

Apache License 2.0 - see LICENSE for details.

Apache-2.0, read

History

Latest

v5.0.3

Notes

Release Date: 2026-09-14
Type: Patch - Referenced Configuration Streaming Fix


  1. v5.0.2

    Notes

    Release Date: 2026-09-13
    Type: Patch - Provider Contract Fixes & Explicit V3 Entrypoint


  2. v5.0.1

    Notes

    Release Date: 2026-09-11
    Type: Patch - Diagnostics & Contract Documentation


  3. v5.0.0

    Notes

    Release Date: 2026-09-11
    Type: Major - AI SDK 7 Support & Versioned Entrypoints


  4. v4.9.1

    Notes

    Release Date: 2026-08-23
    Type: Patch - Bug Fixes & Improvements


  5. v4.9.0

    Notes

    Release Date: 2026-08-21
    Type: Minor - Improvements & Dependency Updates


  6. v4.8.0

    Notes

    Release Date: 2026-07-03
    Type: Minor - New Features & Improvements


  7. v4.7.1

    Notes

    Release Date: 2026-06-05
    Type: Patch - Bug Fixes & Improvements


  8. v4.7.0

    Notes

    Release Date: 2026-05-28
    Type: Minor - New Features & Improvements


  9. v4.6.9

    Notes

    Release Date: 2026-05-03
    Type: Patch - Bug Fixes


  10. v4.6.8

    Notes

    Release Date: 2026-04-07
    Type: Patch - Bug Fixes


  11. v4.6.7

    Notes

    Release Date: 2026-03-29
    Type: Patch - Bug Fixes


  12. v4.6.6

    Notes

    Release Date: 2026-03-29
    Type: Patch - Bug Fixes


  13. v4.6.5

    Notes

    Release Date: 2026-03-29
    Type: Patch - Bug Fixes


  14. v4.6.4

    Notes

    Release Date: 2026-03-29
    Type: Patch - Bug Fixes


  15. v4.6.3

    Notes

    Release Date: 2026-03-29
    Type: Patch - New Features & Improvements


  16. v4.6.2

    Notes

    Release Date: 2026-03-22
    Type: Patch - Improvements


  17. v4.6.1

    Notes

    Release Date: 2026-03-22
    Type: Patch - Code Quality Improvements


  18. v4.6.0

    Notes

    Release Date: 2026-03-21
    Type: Minor - New Features & Improvements


  19. v4.5.0

    Notes

    Release Date: 2026-03-04
    Type: Minor - New Features & Improvements


  20. v4.4.18

    Notes

    Release Date: 2026-02-21
    Type: Patch - Bug Fixes


  21. v4.4.17

    Notes

    Release Date: 2026-02-21
    Type: Patch - Bug Fixes & Improvements


  22. v4.4.16

    Notes

    Release Date: 2026-02-21
    Type: Patch - Code Quality Improvements


  23. v4.4.15

    Notes

    Release Date: 2026-02-19
    Type: Patch - Bug Fixes


  24. v4.4.14

    Notes

    Release Date: 2026-02-18
    Type: Patch - Bug Fixes


  25. v4.4.13

    Notes

    Release Date: 2026-02-18
    Type: Patch - Bug Fixes & Improvements


  26. v4.4.12

    Notes

    Release Date: 2026-02-18
    Type: Patch - New Features


  27. v4.4.12-rc.0prerelease

    Notes

    Release Date: 2026-02-18
    Type: Patch - Release Candidate


  28. v4.4.11

    Notes

    Release Date: 2026-02-09
    Type: Patch - Bug Fixes & Platform Update


  29. v4.4.10

    Notes

    Release Date: 2026-02-07
    Type: Patch - New Features & Improvements


  30. v4.4.9

    Notes

    Release Date: 2026-02-07
    Type: Patch - Refactoring


  31. v4.4.8

    Notes

    Release Date: 2026-02-06
    Type: Patch - Bug Fix


  32. v4.4.6

    Notes

    Release Date: 2026-02-06
    Type: Patch - Improvements & Refactoring


  33. v4.4.5

    Notes

    Release Date: 2026-02-04
    Type: Patch - Improvements & Documentation


  34. v4.4.4

    Notes

    Release Date: 2026-02-01
    Type: Patch - Refactoring


  35. v4.4.2

    Notes

    Release Date: 2026-01-30
    Type: Patch - Features & Documentation


  36. v4.4.1

    Notes

    Release Date: 2026-01-29
    Type: Patch - Bug Fix


  37. v4.4.0

    Notes

    Release Date: 2026-01-29
    Type: Minor - New Features & Improvements


  38. v4.3.0

    Notes

    Release Date: 2026-01-27
    Type: Minor - New Features & Improvements


  39. v4.2.7

    Notes

    Release Date: 2026-01-26 Type: Patch - Maintenance


  40. v4.2.6

    Notes

    Release Date: 2026-01-22 Type: Patch - Code Quality & Testing Improvements


  41. v4.2.5

    Notes

    Release Date: 2026-01-22
    Type: Minor - New Features & Improvements


  42. v4.2.4

    Notes

    Release Date: 2026-01-21
    Type: Patch - Bug Fixes & Improvements


  43. v4.2.3

    Notes

    Release Date: 2026-01-20
    Type: Patch - New Features & Improvements


  44. v4.2.2

    Notes

    Release Date: 2026-01-20
    Type: Patch - Bug Fixes & Improvements


  45. v4.2.1

    Notes

    Release Date: 2026-01-19
    Type: Patch - Refactoring


  46. v4.2.0

    Notes

    Release Date: 2026-01-19
    Type: Minor - New Features & Improvements


  47. v4.1.3

    Notes

    Release Date: 2026-01-19
    Type: Patch - New Features & Improvements


  48. v4.1.2

    Notes

    Release Date: 2026-01-19
    Type: Patch - Code Quality Improvements


  49. v4.1.1

    Notes

    Release Date: 2026-01-18
    Type: Patch - Error Handling Improvements


  50. v4.1.0

    Notes

    Release Date: 2026-01-17
    Type: Minor - New Features & Improvements


  51. v4.0.2

    Notes

    Release Date: 2026-01-17
    Type: Patch - Dependency Updates


  52. v4.0.1

    Notes

    Release Date: 2026-01-17
    Type: Patch - Bug Fixes & Improvements


  53. v4.0.0

    Notes

    Release Date: 2026-01-15
    Type: Major Version - Breaking Changes
    Specification: LanguageModelV3 (AI SDK 6.0+)


  54. v4.0.0-rc.2prerelease

    Notes

    ⚠️ This is a pre-release (Release Candidate 2). Please test thoroughly before using in production.

    Feedback Period: Until 2026-01-22 (3-7 days from RC2 release)
    Quality: 194/194 tests passing | Coverage: 92.87% | Implementation audit: 9.8/10


  55. v4.0.0-rc.1prerelease

    Notes

    ⚠️ This is a pre-release (Release Candidate). Please test thoroughly before using in production.

    Feedback Period: Until 2026-01-21 (3-7 days)
    Quality: 184/184 tests passing | Implementation audit: 9.5/10


  56. v3.0.0dated in the atlas

    Breaking 3, Features 11

    Notes

    Breaking Changes

    Error Handling Standardization

    The custom SAPAIError class has been removed in favor of using the standard APICallError from @ai-sdk/provider. This change:

    • Aligns with AI SDK conventions - Provides consistent error handling across all AI SDK providers
    • Automatic retry with exponential backoff - Transient errors (429, 503, network issues) are now automatically retried
    • Preserves SAP metadata - All SAP-specific error information is still available via error.responseBody
    Migration Guide

    Before (v2.x):

    import { SAPAIError } from '@jerome-benoit/sap-ai-provider';
    
    try {
      const result = await generateText({ ... });
    } catch (error) {
      if (error instanceof SAPAIError) {
        console.log('SAP error:', error.code, error.message);
      }
    }

    After (v3.0.0):

    import { APICallError } from '@ai-sdk/provider';
    
    try {
      const result = await generateText({ ... });
    } catch (error) {
      if (APICallError.isInstance(error)) {
        console.log('API error:', error.statusCode, error.message);
        // SAP-specific data available in responseBody
        console.log('SAP details:', error.responseBody);
      }
    }

    See MIGRATION_GUIDE.md for complete details.


    New Features

    Orchestration v2.4/2.5 Type Exports

    Added comprehensive type exports for SAP AI Core Orchestration v2.4 and v2.5:

    • OrchestrationConfigRef - Reference existing orchestration configurations by ID
    • Translation types (InputTranslation, OutputTranslation) - Support for multi-language workflows
    • Templating enhancements (InputTemplating) - Advanced prompt templating capabilities

    Example:

    import { sapai } from '@jerome-benoit/sap-ai-provider';
    import type { OrchestrationConfigRef } from '@jerome-benoit/sap-ai-provider/types';
    
    const model = sapai('gpt-4o', {
      orchestrationConfig: {
        configRef: {
          id: 'my-config-id'
        } as OrchestrationConfigRef
      }
    });
    CI/CD Enhancements
    • OIDC Trusted Publishing - Secure, tokenless npm publishing using GitHub OIDC
    • Auto-detect repository owner - Automatically sets npm package scope based on GitHub repository owner
    • Smart npm tag selection - Publishes to next tag for release candidates, latest for stable releases

    Documentation Improvements

    Quality Score: 87.75 → ~95/100

    Comprehensive documentation audit and improvements across all major files:

    New Content
    • Tool Calling section in API_REFERENCE.md (260+ lines)

      • Model limitations comparison table
      • Parallel tool calls examples
      • Multi-turn conversation patterns
      • Error handling best practices
      • Cross-references in README.md and CURL_API_TESTING_GUIDE.md
    • Mermaid Diagram Accessibility

      • Added text descriptions before all 8 diagrams in ARCHITECTURE.md
      • Covers: High-Level Architecture, Component Flow, Tool Calling, Data Masking, OAuth2
    • AGENTS.md Expansion

      • Comprehensive AI agent onboarding instructions
      • GitHub Copilot and Cursor configuration guidance
      • Development workflow integration
    Consistency Improvements
    • Standardized warning format across 7 files:

      • ⚠️ **Important:** for critical warnings
      • > **Note:** for informational notes
    • Reduced duplication:

      • Authentication documentation consolidated in ENVIRONMENT_SETUP.md
      • Single source of truth with cross-references

  57. v3.0.0-rc.6prerelease

    Features 4, Docs 12

    Notes

    📚 Documentation Improvements

    This release focuses on improving documentation quality and consistency.

    ✨ What's New

    Documentation Quality Score: 87.75/100 → ~95/100

    🔄 Reduced Duplication
    • Simplified authentication references to link to ENVIRONMENT_SETUP.md
    • Consolidated tool calling documentation in API_REFERENCE.md
    • Eliminated redundant setup instructions across multiple files
    📋 Standardized Formatting
    • Unified warning formats across all documentation
      • ⚠️ **Important:** for critical warnings
      • > **Note:** for informational notes
    • Consistent styling in 7 documentation files
    ♿ Improved Accessibility
    • Added text descriptions before all 8 Mermaid diagrams in ARCHITECTURE.md
    • Better context for screen readers and text-based browsers
    📖 Enhanced Documentation
    • API_REFERENCE.md: New comprehensive Tool Calling section (260+ lines)
      • Model limitations comparison table
      • Parallel tool calls examples
      • Multi-turn conversations
      • Error handling patterns
      • Best practices
    • AGENTS.md: Expanded from 3 to 50+ lines
      • Clear AI agent onboarding instructions
      • GitHub Copilot and Cursor rules documentation
      • Human developer navigation section
    🔗 Better Cross-References
    • Added tool calling links in README.md and CURL_API_TESTING_GUIDE.md
    • Improved navigation between related documentation sections
    📊 Statistics
    • 7 files modified
    • 347 insertions, 15 deletions
    • All 183 tests passing ✅
    📦 Installation
    npm install @jerome-benoit/sap-ai-provider@3.0.0-rc.6
  58. v3.0.0-rc.5prerelease

  59. v3.0.0-rc.4prerelease

    Changed 3

    Notes

    Release candidate 4 for version 3.0.0

    This release will automatically publish to npm as @jerome-benoit/sap-ai-provider@3.0.0-rc.4 with the next tag using OIDC Trusted Publishing.

    Changes

    • Automated multi-repository npm publishing with OIDC
    • No manual npm tokens required
    • Package scope automatically determined by repository owner
  60. v3.0.0-rc.3prerelease

    Notes

    🔧 Testing OIDC Trusted Publishing

    This release tests the automated npm publishing workflow with OIDC trusted publishing.


    Installation:

    npm install @jerome-benoit/sap-ai-provider@next
  61. v3.0.0-rc.2prerelease

    Notes

    🚀 Features

    • Multi-repository publishing support: Workflow now automatically detects repository owner and publishes under appropriate npm scope
      • BITASIA/sap-ai-provider → @mymediset/sap-ai-provider
      • jerome-benoit/sap-ai-provider → @jerome-benoit/sap-ai-provider

    📚 Documentation

    • Enhanced documentation structure and navigation
    • Eliminated significant duplication across docs (85% reduction in error handling sections)
    • Standardized examples format
    • Improved migration guide clarity
    • Consolidated documentation validation script

    🐛 Bug Fixes

    • Fixed CI workflow to allow same version in npm publish step

    🔧 Internal

    • Refactored documentation validation into single TypeScript script
    • Improved workflow maintainability

    Full Changelog: https://github.com/jerome-benoit/sap-ai-provider/compare/v3.0.0-rc.1...v3.0.0-rc.2

    Installation: ```bash npm install @jerome-benoit/sap-ai-provider@next ```

  62. v3.0.0-rc.1prerelease

15,952downloads per week, npm
Weekly downloads for @jerome-benoit/sap-ai-provider26 complete calendar weeks from 2026-04-27 to 2026-10-25; the latest total is 15952.27 Apr – 3 May: 4364 May – 10 May: 59111 May – 17 May: 36718 May – 24 May: 29225 May – 31 May: 2,6741 Jun – 7 Jun: 34,4328 Jun – 14 Jun: 61,25215 Jun – 21 Jun: 28,99322 Jun – 28 Jun: 31,90829 Jun – 5 Jul: 35,1886 Jul – 12 Jul: 38,90913 Jul – 19 Jul: 163,71520 Jul – 26 Jul: 79,91127 Jul – 2 Aug: 135,9953 Aug – 9 Aug: 125,71910 Aug – 16 Aug: 103,16917 Aug – 23 Aug: 120,48724 Aug – 30 Aug: 110,44431 Aug – 6 Sept: 63,5257 Sept – 13 Sept: 68,87214 Sept – 20 Sept: 61,04121 Sept – 27 Sept: 84,66628 Sept – 4 Oct: 104,8335 Oct – 11 Oct: 75,87812 Oct – 18 Oct: 42,22919 Oct – 25 Oct: 15,952
LLM integration
  1. llm_clientABAP client with one interface to chat-completion LLM APIsfrom ABAP
  2. abap-agent-runtimeABAP-native MCP endpoint that drives opted-in abap2UI5 appsfrom ABAP
  3. abap_btocs_ollamaB-Tocs ABAP SDK plugin connecting to Ollama modelsfrom ABAP
  4. SAP AI CoreAI runtime on BTP with the Generative AI Hubfrom BTP/BAIP
  5. cap-java/cds-aiBridge from CAP Java to SAP AI Core, with Fiori field recommendationsfrom CAP
  6. @cap-js/aiValue-help recommendations and SAP AI Core as a CAP servicefrom CAP
  7. cap-llm-pluginGenerative AI in CAP with fields anonymised through SAP HANAfrom CAP
  8. @geertjanklaps/cds-toon-ai-protocol-adapterProtocol adapter serving CAP data as TOON instead of JSONfrom CAP
  9. abap-sdk-nwas-xABAP client library for IBM watsonx.ai APIsfrom ABAP
  10. ui5-cap-ai-featuresCDS plugin and UI5 controls for AI text features via SAP AI Corefrom CAP
  11. Microsoft AI SDK for SAPABAP library for calling Azure OpenAI and OpenAIfrom ABAP
  12. zllmABAP framework for chaining and orchestrating LLM callsfrom ABAP
  13. ABAP AI SDKSAP reuse library for calling large language models from ABAPfrom ABAP
  14. @sap-ai-sdk/ai-apiAI Core control plane API surface of SAP's AI SDKfrom CAP
  15. @sap-ai-sdk/coreShared internals of SAP's AI SDKfrom CAP
  16. @sap-ai-sdk/foundation-modelsClient for foundation models via SAP AI Core and Generative AI Hubfrom CAP
  17. @sap-ai-sdk/orchestrationOrchestration Service client for templating, grounding and maskingfrom CAP
  18. @sap-ai-sdk/prompt-registryClient for prompts kept in SAP's prompt registryfrom CAP
  19. @saptarishi/cds-plugin-llmCAP service kind putting eleven model providers behind one APIfrom CAP
  20. @shahid.la/cds-db-nlquery-mcpMCP server answering plain-English questions against a CDS schemafrom CAP
  21. @ui5/webcomponentsSAP's UI elements as standard custom elementsfrom UI5
  22. abap-sdk-nwasAn ABAP client library for IBM Watson's Discovery, Language Translator, Natural Language Understanding, Speech to Text, Text to Speech and Assistant services, installed through abapGit.from ABAP

Details

Sources5
npm registrydiscovered herechecked
The discovery passdiscovered herechecked
npm registry, @jerome-benoit/sap-ai-providerversion, releases, installschecked
github.com/git+https://github.com/jerome-benoit/sap-ai-provider.gittree, pushes, contributors, CIchecked
README.mdquoted, and what the entry declareschecked

Sources are graph entities: the same page may back several entries, and an unreachable source flags every row that rests on it.

Compatibility and provenance
latestv5.0.3
first release
releases and cadence63, ~8d median
discovered vianpm registry, The discovery pass
first seen in the atlas
ecosystem and domaincap, ai-and-agents
Contributors1

From the repository’s contributor list, .

History in the atlas5
  1. an edge with what_it_does, three sources and the two properties the capability declares
  2. What a Vercel AI SDK application keeps and what it changes, the two APIs it reaches AI Core through, the README's community-provider wording and AI SDK 5 to 7 range, and what stays the project's.
  3. Typed cds-plugin by placement, which defaults every candidate to that. It is not one.
  4. A provider for the Vercel AI SDK that speaks to SAP AI Core, so an application written against that SDK runs on SAP's models without being rewritten.
  5. First seen.
For your agent
Ref
artifact:jerome-benoit-sap-ai-provider
JSON
/artifacts/jerome-benoit-sap-ai-provider.json
MCP
Connecting an agent