Loading...
Loading...
Integrates SAP Cloud SDK for AI into JavaScript/TypeScript and Java applications. Use when building applications with SAP AI Core, Generative AI Hub, or Orchestration Service. Covers chat completion, embedding, streaming, function calling, content filtering, data masking, document grounding, prompt registry, and LangChain/Spring AI integration. Supports OpenAI GPT-4o, Claude, Gemini, Amazon Nova, and other foundation models via SAP BTP.
npx skill4agent add secondsky/sap-skills sap-cloud-sdk-aiNote: 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.
npm install @sap-ai-sdk/orchestration@^2import { 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());<dependency>
<groupId>com.sap.ai.sdk</groupId>
<artifactId>orchestration</artifactId>
<version>${ai-sdk.version}</version>
</dependency>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());VCAP_SERVICESexport AICORE_SERVICE_KEY='{"clientid":"...","clientsecret":"...","url":"...","serviceurls":{"AI_API_URL":"..."}}'# JavaScript
cds bind -2 <AICORE_INSTANCE> && cds-tsx watch --profile hybrid
# Java
cds bind --to aicore --exec mvn spring-boot:runreferences/connecting-to-ai-core.md| Package | Purpose |
|---|---|
| Chat completion, filtering, grounding |
| Direct model access (OpenAI) |
| LangChain integration |
| Deployments, artifacts, configurations |
| Pipeline, Vector, Retrieval APIs |
| Prompt template management |
| Artifact | Purpose |
|---|---|
| Chat completion, filtering, grounding |
| Direct OpenAI model access |
| Base connectivity |
| Pipeline, Vector, Retrieval APIs |
| Prompt template management |
| 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 |
// JavaScript
const stream = client.stream({
placeholderValues: { question: 'Explain SAP CAP' }
});
for await (const chunk of stream.toContentStream()) {
process.stdout.write(chunk);
}// Java
client.streamChatCompletion(prompt, config)
.forEach(chunk -> System.out.print(chunk.getDeltaContent()));// 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();// 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' })
}
});// 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' }]
}]
}
});// 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' }]
}
});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 blockedconst stream = client.stream({ placeholderValues });
for await (const chunk of stream.toContentStream()) {
process.stdout.write(chunk);
}
// After stream ends:
stream.getFinishReason();
stream.getTokenUsage();references/orchestration-guide.mdreferences/foundation-models-guide.mdreferences/langchain-guide.mdreferences/spring-ai-guide.mdreferences/ai-core-api-guide.mdreferences/foundation-models-guide.mdreferences/ai-core-api-guide.mdreferences/orchestration-guide.mdreferences/langchain-guide.mdreferences/spring-ai-guide.mdreferences/agentic-workflows.mdreferences/connecting-to-ai-core.mdreferences/error-handling.mdreferences/v1-to-v2-migration.md| 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) |
...model| 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 |