Embedding
Initialize the AzureOpenAiEmbeddingClient by following the instructions in the Client Initialization section.
Currently, the client sends request with Azure OpenAI API version 2024-10-21.
We are continuously updating the client to match the latest API specification.
You can overwrite the API version by setting the api-version parameter in the CustomRequestConfig object.
Refer to the Custom Request Configuration section for more details.
Making Requests
const response = await client.run({
input: 'AI is fascinating'
});
const embedding = response.getEmbedding();
Resilience
The @sap-cloud-sdk/resilience package uses the SAP Cloud SDK for JavaScript HTTP client, which provides built-in resilience features to handle transient failures and improve reliability.
Retry
The HTTP client automatically retries failed requests on transient errors (e.g., network issues, temporary server errors). You can customize retry behavior using the resilience library.
For example, to set a custom retry count:
const request = {
input: 'What is the capital of Germany?'
};
const response = await client.run(request, {
middleware: [
retry({ maxRetries: 3, backoffType: 'exponential', initialDelay: 1000 })
]
});
Timeout
Configure timeout for requests to prevent hanging connections. The default timeout is 10 seconds.
const request = {
input: 'Create a 10-15 sentence long story involving a train ride.'
};
const response = await client.run(request, {
timeout: 30000 // 30 seconds
});
Combining Resilience Patterns
You can combine multiple resilience patterns for comprehensive protection.
const request = {
input: 'Generate a creative story about space exploration.'
};
const response = await client.run(request, {
middleware: [
retry({ maxRetries: 3, backoffType: 'exponential', initialDelay: 1000 }),
circuitBreaker({ failureThreshold: 5, recoveryTimeout: 60000 }),
timeout(30000)
]
});
For advanced resilience patterns, refer to the SAP Cloud SDK documentation on resilience.