sap-cloud-sdk-ai

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

SAP Cloud SDK for AI

SAP Cloud SDK for AI

The official SDK for SAP AI Core, SAP Generative AI Hub, and Orchestration Service.
这是SAP AI Core、SAP Generative AI Hub和Orchestration Service的官方SDK。

When to Use This Skill

何时使用该技能

Use this skill when:
  • Integrating AI/LLM capabilities into SAP BTP applications
  • Building chat completion or embedding features
  • Using GPT-4o, Claude, Gemini, or other models via SAP AI Core
  • Implementing content filtering, data masking, or document grounding
  • Creating agentic workflows with LangChain or Spring AI
  • Managing prompts via Prompt Registry
  • Deploying AI models on SAP AI Core
在以下场景中使用该技能:
  • 在SAP BTP应用中集成AI/LLM能力
  • 构建对话补全或嵌入功能
  • 通过SAP AI Core使用GPT-4o、Claude、Gemini或其他模型
  • 实现内容过滤、数据掩码或文档检索增强生成
  • 借助LangChain或Spring AI创建智能代理工作流
  • 通过Prompt Registry管理提示词
  • 在SAP AI Core上部署AI模型

Table of Contents

目录

Quick Start

快速开始

Note: This skill uses SAP Cloud SDK for AI v2.2.0+. If you're migrating from v1.x, see V1 to V2 Migration Guide for breaking changes.
注意: 该技能使用SAP Cloud SDK for AI v2.2.0及以上版本。如果从v1.x版本迁移,请查看V1到V2迁移指南了解破坏性变更。

JavaScript/TypeScript

JavaScript/TypeScript

bash
npm install @sap-ai-sdk/orchestration@^2
typescript
import { OrchestrationClient } from '@sap-ai-sdk/orchestration';

const client = new OrchestrationClient({
  promptTemplating: {
    model: { name: 'gpt-4o' },
    prompt: [{ role: 'user', content: '{{?question}}' }]
  }
});

const response = await client.chatCompletion({
  placeholderValues: { question: 'What is SAP?' }
});
console.log(response.getContent());
bash
npm install @sap-ai-sdk/orchestration@^2
typescript
import { OrchestrationClient } from '@sap-ai-sdk/orchestration';

const client = new OrchestrationClient({
  promptTemplating: {
    model: { name: 'gpt-4o' },
    prompt: [{ role: 'user', content: '{{?question}}' }]
  }
});

const response = await client.chatCompletion({
  placeholderValues: { question: 'What is SAP?' }
});
console.log(response.getContent());

Java

Java

xml
<dependency>
  <groupId>com.sap.ai.sdk</groupId>
  <artifactId>orchestration</artifactId>
  <version>${ai-sdk.version}</version>
</dependency>
java
var client = new OrchestrationClient();
var config = new OrchestrationModuleConfig()
    .withLlmConfig(OrchestrationAiModel.GPT_4O);
var prompt = new OrchestrationPrompt("What is SAP?");
var result = client.chatCompletion(prompt, config);
System.out.println(result.getContent());
xml
<dependency>
  <groupId>com.sap.ai.sdk</groupId>
  <artifactId>orchestration</artifactId>
  <version>${ai-sdk.version}</version>
</dependency>
java
var client = new OrchestrationClient();
var config = new OrchestrationModuleConfig()
    .withLlmConfig(OrchestrationAiModel.GPT_4O);
var prompt = new OrchestrationPrompt("What is SAP?");
var result = client.chatCompletion(prompt, config);
System.out.println(result.getContent());

Prerequisites

前提条件

  • Node.js 20+ (JavaScript) or Java 17+ (Java)
  • SAP AI Core service instance (extended or sap-internal plan)
  • Orchestration deployment in AI Core (default resource group has this)
  • Node.js 20+(JavaScript)或Java 17+(Java)
  • SAP AI Core服务实例(扩展版或sap-internal计划)
  • AI Core中的Orchestration部署(默认资源组已包含该部署)

Connection Setup

连接设置

BTP Runtime (Cloud Foundry/Kyma)

BTP运行时(Cloud Foundry/Kyma)

Bind AI Core service instance to your application. SDK auto-detects via
VCAP_SERVICES
or mounted secrets.
将AI Core服务实例绑定到您的应用。SDK会通过
VCAP_SERVICES
或挂载的密钥自动检测。

Local Development

本地开发

Set environment variable:
bash
export AICORE_SERVICE_KEY='{"clientid":"...","clientsecret":"...","url":"...","serviceurls":{"AI_API_URL":"..."}}'
Or use CAP hybrid mode:
bash
undefined
设置环境变量:
bash
export AICORE_SERVICE_KEY='{"clientid":"...","clientsecret":"...","url":"...","serviceurls":{"AI_API_URL":"..."}}'
或使用CAP混合模式:
bash
undefined

JavaScript

JavaScript

cds bind -2 <AICORE_INSTANCE> && cds-tsx watch --profile hybrid
cds bind -2 <AICORE_INSTANCE> && cds-tsx watch --profile hybrid

Java

Java

cds bind --to aicore --exec mvn spring-boot:run

For detailed connection options, see `references/connecting-to-ai-core.md`
cds bind --to aicore --exec mvn spring-boot:run

有关详细的连接选项,请查看`references/connecting-to-ai-core.md`

Available Packages

可用包

JavaScript/TypeScript

JavaScript/TypeScript

PackagePurpose
@sap-ai-sdk/orchestration
Chat completion, filtering, grounding
@sap-ai-sdk/foundation-models
Direct model access (OpenAI)
@sap-ai-sdk/langchain
LangChain integration
@sap-ai-sdk/ai-api
Deployments, artifacts, configurations
@sap-ai-sdk/document-grounding
Pipeline, Vector, Retrieval APIs
@sap-ai-sdk/prompt-registry
Prompt template management
用途
@sap-ai-sdk/orchestration
对话补全、过滤、检索增强生成
@sap-ai-sdk/foundation-models
直接访问模型(OpenAI)
@sap-ai-sdk/langchain
LangChain集成
@sap-ai-sdk/ai-api
部署、工件、配置管理
@sap-ai-sdk/document-grounding
流水线、向量、检索API
@sap-ai-sdk/prompt-registry
Prompt模板管理

Java

Java

ArtifactPurpose
orchestration
Chat completion, filtering, grounding
openai
(foundationmodels)
Direct OpenAI model access
core
Base connectivity
document-grounding
Pipeline, Vector, Retrieval APIs
prompt-registry
Prompt template management
工件用途
orchestration
对话补全、过滤、检索增强生成
openai
(foundationmodels)
直接访问OpenAI模型
core
基础连接功能
document-grounding
流水线、向量、检索API
prompt-registry
Prompt模板管理

Supported Models

支持的模型

Recommended

推荐模型

  • OpenAI: gpt-4o, gpt-4o-mini, o1, o3-mini
  • Anthropic (AWS): Claude 3.5 Sonnet, Claude 4
  • Amazon: Nova Pro, Nova Lite, Nova Micro
  • Google: Gemini 2.5 Flash, Gemini 2.0 Flash
  • Mistral: Medium, Large
  • OpenAI: gpt-4o, gpt-4o-mini, o1, o3-mini
  • Anthropic (AWS): Claude 3.5 Sonnet, Claude 4
  • Amazon: Nova Pro, Nova Lite, Nova Micro
  • Google: Gemini 2.5 Flash, Gemini 2.0 Flash
  • Mistral: Medium, Large

Deprecated Models (Use Replacements)

已弃用模型(请使用替代模型)

DeprecatedUse Instead
text-embedding-ada-002text-embedding-3-small/large
gpt-35-turbo (all variants)gpt-4o-mini
gpt-4-32kgpt-4o
gpt-4 (base)gpt-4o or gpt-4.1
gemini-1.0-progemini-2.0-flash
gemini-1.5-pro/flashgemini-2.5-flash
mistralai--mixtral-8x7bmistralai--mistral-small-instruct
已弃用模型替代模型
text-embedding-ada-002text-embedding-3-small/large
gpt-35-turbo(所有变体)gpt-4o-mini
gpt-4-32kgpt-4o
gpt-4(基础版)gpt-4o或gpt-4.1
gemini-1.0-progemini-2.0-flash
gemini-1.5-pro/flashgemini-2.5-flash
mistralai--mixtral-8x7bmistralai--mistral-small-instruct

Core Features

核心功能

Chat Completion with Streaming

带流式传输的对话补全

typescript
// JavaScript
const stream = client.stream({
  placeholderValues: { question: 'Explain SAP CAP' }
});

for await (const chunk of stream.toContentStream()) {
  process.stdout.write(chunk);
}
java
// Java
client.streamChatCompletion(prompt, config)
    .forEach(chunk -> System.out.print(chunk.getDeltaContent()));
typescript
// JavaScript
const stream = client.stream({
  placeholderValues: { question: 'Explain SAP CAP' }
});

for await (const chunk of stream.toContentStream()) {
  process.stdout.write(chunk);
}
java
// Java
client.streamChatCompletion(prompt, config)
    .forEach(chunk -> System.out.print(chunk.getDeltaContent()));

Function/Tool Calling

函数/工具调用

typescript
// JavaScript
const tools = [{
  type: 'function',
  function: {
    name: 'get_weather',
    parameters: { type: 'object', properties: { city: { type: 'string' } } }
  }
}];

const response = await client.chatCompletion({
  placeholderValues: { question: 'Weather in Berlin?' }
}, { tools });

const toolCalls = response.getToolCalls();
typescript
// JavaScript
const tools = [{
  type: 'function',
  function: {
    name: 'get_weather',
    parameters: { type: 'object', properties: { city: { type: 'string' } } }
  }
}];

const response = await client.chatCompletion({
  placeholderValues: { question: 'Weather in Berlin?' }
}, { tools });

const toolCalls = response.getToolCalls();

Content Filtering

内容过滤

typescript
// JavaScript
import { buildAzureContentSafetyFilter } from '@sap-ai-sdk/orchestration';

const client = new OrchestrationClient({
  promptTemplating: { model: { name: 'gpt-4o' } },
  filtering: {
    input: buildAzureContentSafetyFilter({ Hate: 'ALLOW_SAFE' }),
    output: buildAzureContentSafetyFilter({ Violence: 'ALLOW_SAFE' })
  }
});
typescript
// JavaScript
import { buildAzureContentSafetyFilter } from '@sap-ai-sdk/orchestration';

const client = new OrchestrationClient({
  promptTemplating: { model: { name: 'gpt-4o' } },
  filtering: {
    input: buildAzureContentSafetyFilter({ Hate: 'ALLOW_SAFE' }),
    output: buildAzureContentSafetyFilter({ Violence: 'ALLOW_SAFE' })
  }
});

Data Masking

数据掩码

typescript
// JavaScript
const client = new OrchestrationClient({
  promptTemplating: { model: { name: 'gpt-4o' } },
  masking: {
    masking_providers: [{
      type: 'sap_data_privacy_integration',
      method: 'anonymization',
      entities: [{ type: 'profile-email' }, { type: 'profile-person' }]
    }]
  }
});
typescript
// JavaScript
const client = new OrchestrationClient({
  promptTemplating: { model: { name: 'gpt-4o' } },
  masking: {
    masking_providers: [{
      type: 'sap_data_privacy_integration',
      method: 'anonymization',
      entities: [{ type: 'profile-email' }, { type: 'profile-person' }]
    }]
  }
});

Document Grounding

文档检索增强生成

typescript
// JavaScript
const client = new OrchestrationClient({
  promptTemplating: { model: { name: 'gpt-4o' } },
  grounding: {
    grounding_input: ['{{?question}}'],
    grounding_output: ['{{?context}}'],
    data_repositories: [{ type: 'vector', id: 'my-repo-id' }]
  }
});
typescript
// JavaScript
const client = new OrchestrationClient({
  promptTemplating: { model: { name: 'gpt-4o' } },
  grounding: {
    grounding_input: ['{{?question}}'],
    grounding_output: ['{{?context}}'],
    data_repositories: [{ type: 'vector', id: 'my-repo-id' }]
  }
});

Response Helpers

响应辅助方法

JavaScript SDK provides helper methods:
typescript
const response = await client.chatCompletion({ placeholderValues });

response.getContent();          // Model output string
response.getTokenUsage();       // { prompt_tokens, completion_tokens, total_tokens }
response.getFinishReason();     // 'stop', 'length', 'tool_calls', etc.
response.getToolCalls();        // Array of function calls
response.getDeltaToolCalls();   // Partial tool calls (streaming)
response.getAllMessages();      // Full message history
response.getAssistantMessage(); // Assistant response only
response.getRefusal();          // Refusal message if blocked
Streaming response methods:
typescript
const stream = client.stream({ placeholderValues });
for await (const chunk of stream.toContentStream()) {
  process.stdout.write(chunk);
}
// After stream ends:
stream.getFinishReason();
stream.getTokenUsage();
JavaScript SDK提供以下辅助方法:
typescript
const response = await client.chatCompletion({ placeholderValues });

response.getContent();          // 模型输出字符串
response.getTokenUsage();       // { prompt_tokens, completion_tokens, total_tokens }
response.getFinishReason();     // 'stop', 'length', 'tool_calls'等
response.getToolCalls();        // 函数调用数组
response.getDeltaToolCalls();   // 部分函数调用(流式传输场景)
response.getAllMessages();      // 完整消息历史
response.getAssistantMessage(); // 仅助手响应
response.getRefusal();          // 若内容被拦截则返回拒绝消息
流式响应方法:
typescript
const stream = client.stream({ placeholderValues });
for await (const chunk of stream.toContentStream()) {
  process.stdout.write(chunk);
}
// 流式传输结束后:
stream.getFinishReason();
stream.getTokenUsage();

Advanced Topics

高级主题

For detailed guidance:
  • Orchestration features:
    references/orchestration-guide.md
  • Foundation models (direct OpenAI):
    references/foundation-models-guide.md
  • LangChain integration:
    references/langchain-guide.md
  • Spring AI integration:
    references/spring-ai-guide.md
  • AI Core management:
    references/ai-core-api-guide.md

如需详细指导,请查看:
  • Orchestration功能:
    references/orchestration-guide.md
  • 基础模型(直接访问OpenAI):
    references/foundation-models-guide.md
  • LangChain集成:
    references/langchain-guide.md
  • Spring AI集成:
    references/spring-ai-guide.md
  • AI Core管理:
    references/ai-core-api-guide.md

Bundled Resources

捆绑资源

Reference Documentation

参考文档

  • references/foundation-models-guide.md
    - Foundation models and pricing
  • references/ai-core-api-guide.md
    - AI Core service API reference
  • references/orchestration-guide.md
    - Orchestration service guide
  • references/langchain-guide.md
    - LangChain.js integration
  • references/spring-ai-guide.md
    - Spring AI integration
  • references/agentic-workflows.md
    - Agentic workflow patterns
  • references/connecting-to-ai-core.md
    - Connection setup guide
  • references/error-handling.md
    - Error handling patterns
  • references/v1-to-v2-migration.md
    - V1 to V2 migration guide
  • references/foundation-models-guide.md
    - 基础模型及定价
  • references/ai-core-api-guide.md
    - AI Core服务API参考
  • references/orchestration-guide.md
    - Orchestration服务指南
  • references/langchain-guide.md
    - LangChain.js集成指南
  • references/spring-ai-guide.md
    - Spring AI集成指南
  • references/agentic-workflows.md
    - 智能代理工作流模式
  • references/connecting-to-ai-core.md
    - 连接设置指南
  • references/error-handling.md
    - 错误处理模式
  • references/v1-to-v2-migration.md
    - V1到V2迁移指南

Version Information

版本信息

SDKCurrent VersionNode/Java Requirement
JavaScript2.2.0+Node.js 20+
Java1.13.0 (Core) / 1.12.0 (Latest orchestration)Java 17+ (21 LTS recommended)
Note: Generated model classes (in
...model
packages) may change in minor releases but are safe to use.
SDK当前版本Node/Java要求
JavaScript2.2.0+Node.js 20+
Java1.13.0(Core)/ 1.12.0(最新Orchestration版本)Java 17+(推荐使用21 LTS版本)
注意: 生成的模型类(位于
...model
包中)可能在小版本更新中发生变化,但可以安全使用。

Common Errors

常见错误

ErrorCauseSolution
"Could not find service bindings for 'aicore'"Missing AI Core bindingBind AI Core service or set AICORE_SERVICE_KEY
"Orchestration deployment not found"No deployment in resource groupDeploy orchestration in AI Core or use different resource group
Content filter violationInput/output blockedAdjust filter thresholds or modify content
Token limit exceededResponse too longSet max_tokens parameter
错误原因解决方案
"Could not find service bindings for 'aicore'"缺少AI Core绑定绑定AI Core服务或设置AICORE_SERVICE_KEY环境变量
"Orchestration deployment not found"资源组中无对应部署在AI Core中部署Orchestration或使用其他资源组
内容过滤器违规输入/输出被拦截调整过滤器阈值或修改内容
令牌限制超出响应内容过长设置max_tokens参数

Documentation Sources

文档来源

Keep this skill updated using these sources:
通过以下来源保持该技能的更新: