sap-cloud-sdk-ai
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSAP 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@^2typescript
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@^2typescript
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 or mounted secrets.
VCAP_SERVICES将AI Core服务实例绑定到您的应用。SDK会通过或挂载的密钥自动检测。
VCAP_SERVICESLocal 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
undefinedJavaScript
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
| Package | Purpose |
|---|---|
| Chat completion, filtering, grounding |
| Direct model access (OpenAI) |
| LangChain integration |
| Deployments, artifacts, configurations |
| Pipeline, Vector, Retrieval APIs |
| Prompt template management |
| 包 | 用途 |
|---|---|
| 对话补全、过滤、检索增强生成 |
| 直接访问模型(OpenAI) |
| LangChain集成 |
| 部署、工件、配置管理 |
| 流水线、向量、检索API |
| Prompt模板管理 |
Java
Java
| Artifact | Purpose |
|---|---|
| Chat completion, filtering, grounding |
| Direct OpenAI model access |
| Base connectivity |
| Pipeline, Vector, Retrieval APIs |
| Prompt template management |
| 工件 | 用途 |
|---|---|
| 对话补全、过滤、检索增强生成 |
| 直接访问OpenAI模型 |
| 基础连接功能 |
| 流水线、向量、检索API |
| 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)
已弃用模型(请使用替代模型)
| Deprecated | Use Instead |
|---|---|
| text-embedding-ada-002 | text-embedding-3-small/large |
| gpt-35-turbo (all variants) | gpt-4o-mini |
| gpt-4-32k | gpt-4o |
| gpt-4 (base) | gpt-4o or gpt-4.1 |
| gemini-1.0-pro | gemini-2.0-flash |
| gemini-1.5-pro/flash | gemini-2.5-flash |
| mistralai--mixtral-8x7b | mistralai--mistral-small-instruct |
| 已弃用模型 | 替代模型 |
|---|---|
| text-embedding-ada-002 | text-embedding-3-small/large |
| gpt-35-turbo(所有变体) | gpt-4o-mini |
| gpt-4-32k | gpt-4o |
| gpt-4(基础版) | gpt-4o或gpt-4.1 |
| gemini-1.0-pro | gemini-2.0-flash |
| gemini-1.5-pro/flash | gemini-2.5-flash |
| mistralai--mixtral-8x7b | mistralai--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 blockedStreaming 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
参考文档
- - Foundation models and pricing
references/foundation-models-guide.md - - AI Core service API reference
references/ai-core-api-guide.md - - Orchestration service guide
references/orchestration-guide.md - - LangChain.js integration
references/langchain-guide.md - - Spring AI integration
references/spring-ai-guide.md - - Agentic workflow patterns
references/agentic-workflows.md - - Connection setup guide
references/connecting-to-ai-core.md - - Error handling patterns
references/error-handling.md - - V1 to V2 migration guide
references/v1-to-v2-migration.md
- - 基础模型及定价
references/foundation-models-guide.md - - AI Core服务API参考
references/ai-core-api-guide.md - - Orchestration服务指南
references/orchestration-guide.md - - LangChain.js集成指南
references/langchain-guide.md - - Spring AI集成指南
references/spring-ai-guide.md - - 智能代理工作流模式
references/agentic-workflows.md - - 连接设置指南
references/connecting-to-ai-core.md - - 错误处理模式
references/error-handling.md - - V1到V2迁移指南
references/v1-to-v2-migration.md
Version Information
版本信息
| SDK | Current Version | Node/Java Requirement |
|---|---|---|
| JavaScript | 2.2.0+ | Node.js 20+ |
| Java | 1.13.0 (Core) / 1.12.0 (Latest orchestration) | Java 17+ (21 LTS recommended) |
Note: Generated model classes (in packages) may change in minor releases but are safe to use.
...model| SDK | 当前版本 | Node/Java要求 |
|---|---|---|
| JavaScript | 2.2.0+ | Node.js 20+ |
| Java | 1.13.0(Core)/ 1.12.0(最新Orchestration版本) | Java 17+(推荐使用21 LTS版本) |
注意: 生成的模型类(位于包中)可能在小版本更新中发生变化,但可以安全使用。
...modelCommon Errors
常见错误
| Error | Cause | Solution |
|---|---|---|
| "Could not find service bindings for 'aicore'" | Missing AI Core binding | Bind AI Core service or set AICORE_SERVICE_KEY |
| "Orchestration deployment not found" | No deployment in resource group | Deploy orchestration in AI Core or use different resource group |
| Content filter violation | Input/output blocked | Adjust filter thresholds or modify content |
| Token limit exceeded | Response too long | Set 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:
- JS Docs: https://github.com/SAP/ai-sdk/tree/main/docs-js
- Java Docs: https://github.com/SAP/ai-sdk/tree/main/docs-java
- JS SDK: https://github.com/SAP/ai-sdk-js
- Java SDK: https://github.com/SAP/ai-sdk-java
- Release Notes: Check docs-js/release-notes.mdx and docs-java/release-notes.mdx
通过以下来源保持该技能的更新:
- JS文档: https://github.com/SAP/ai-sdk/tree/main/docs-js
- Java文档: https://github.com/SAP/ai-sdk/tree/main/docs-java
- JS SDK: https://github.com/SAP/ai-sdk-js
- Java SDK: https://github.com/SAP/ai-sdk-java
- 发布说明: 查看docs-js/release-notes.mdx和docs-java/release-notes.mdx