Skip to main content
Version: v1

Getting Started

What You'll Build​

In this quickstart, you'll use the OpenAI GPT-4o model via the Orchestration Service of AI Core to generate text. The application will send a prompt to the AI model and display the generated response.

Prerequisites​

Refer to prerequisites outlined here.

This quickstart assumes you are using the default resource group of your AI Core instance. If you need to use a different resource group, make sure it has an orchestration deployment available.

Add @sap-ai-sdk/orchestration as a Dependency​

npm install @sap-ai-sdk/orchestration

Use the Orchestration API​

Initialize an orchestration client with an LLM model and a prompt template.

import { OrchestrationClient } from '@sap-ai-sdk/orchestration';

const orchestrationClient = new OrchestrationClient({
llm: {
model_name: 'gpt-4o'
},
templating: {
template: [{ role: 'user', content: 'Answer the question: {{?question}}' }]
}
});

Next, send a chat completion request with a value defined for the question input parameter. The value replaces the {{?question}} placeholder in the template.

const response = await orchestrationClient.chatCompletion({
inputParams: {
question: 'Why is the phrase "Hello world!" so famous?'
}
});
console.log(response.getContent());

Use getContent() method to get the generated text.

Run the Application Locally​

Define the AICORE_SERVICE_KEY environment variable with your AI Core service key in a .env file.

AICORE_SERVICE_KEY='{
"clientid": "...",
...
}'

Load the .env file by using dotenv or running node --env-file=.env ....

Refer to Providing a Service Binding Locally section for more information.