Documentation
¶
Overview ¶
Package sapaicore implements the ADK Go v2 model.LLM interface for SAP AI Core.
It bridges Google's Agent Development Kit with SAP AI Core's inference API, supporting two modes of operation:
Orchestration: a single deployment handles all models via the SAP AI Core harmonized API. Supports extended thinking, response format, tool calling, and server-side timeout/retry configuration.
Foundation-models: per-model deployment IDs with a direct OpenAI-compatible chat completions API.
Quick Start ¶
provider, err := sapaicore.NewProvider(
sapaicore.WithEndpoint("https://api.ai.prod.us-east-1.aws.ml.hana.ondemand.com"),
sapaicore.WithAuth(clientID, clientSecret, authURL),
sapaicore.WithOrchestration(), // auto-discovers deployment
)
if err != nil {
log.Fatal(err)
}
llm, err := provider.Model("gpt-4.1")
Both streaming and non-streaming generation are supported via the standard ADK model.LLM interface.
Index ¶
- Variables
- type ModelOption
- type Option
- func WithAuth(clientID, clientSecret, authURL string) Option
- func WithDeploymentID(id string) Option
- func WithDeployments(deployments map[string]string) Option
- func WithEndpoint(endpoint string) Option
- func WithHTTPClient(client *http.Client) Option
- func WithHeaders(headers http.Header) Option
- func WithMaxRetries(n int) Option
- func WithOrchestration() Option
- func WithResourceGroup(group string) Option
- func WithTimeout(seconds int) Option
- type Provider
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrMissingConfig = errors.New("sapaicore: missing required configuration") ErrDeploymentNotFound = errors.New("sapaicore: deployment not found for model") ErrDiscovery = errors.New("sapaicore: orchestration deployment discovery") )
Sentinel errors.
Functions ¶
This section is empty.
Types ¶
type ModelOption ¶
type ModelOption func(*modelConfig)
ModelOption configures a specific model instance returned by Provider.Model.
func WithModelParams ¶
func WithModelParams(params map[string]any) ModelOption
WithModelParams adds extra parameters forwarded directly to the model. In orchestration mode these go into model.params (e.g. thinking, reasoning_effort). In foundation-models mode these are merged into the top-level request body.
Example ¶
package main
import (
"context"
"fmt"
"log"
sapaicore "github.com/PedroKlein/adk-provider-sapaicore"
)
func main() {
provider, err := sapaicore.NewProvider(context.Background(),
sapaicore.WithEndpoint("https://api.ai.prod.us-east-1.aws.ml.hana.ondemand.com"),
sapaicore.WithAuth("client-id", "client-secret", "https://auth.example.com/oauth/token"),
sapaicore.WithDeploymentID("d1234abc"),
)
if err != nil {
log.Fatal(err)
}
// Enable extended thinking for Claude models.
llm, err := provider.Model("anthropic--claude-4.5-sonnet",
sapaicore.WithModelParams(map[string]any{
"thinking": map[string]any{"type": "enabled", "budget_tokens": 16384},
"max_tokens": 64000,
}),
)
if err != nil {
log.Fatal(err)
}
fmt.Println(llm.Name())
}
Output: anthropic--claude-4.5-sonnet
type Option ¶
type Option func(*providerConfig)
Option configures a Provider. Pass options to NewProvider.
func WithAuth ¶
WithAuth sets the OAuth2 client credentials. authURL is the token endpoint, e.g. "https://xxx.authentication.xxx.hana.ondemand.com/oauth/token".
func WithDeploymentID ¶
WithDeploymentID enables orchestration mode using a specific deployment ID.
func WithDeployments ¶
WithDeployments enables foundation-models mode with per-model deployment IDs.
func WithEndpoint ¶
WithEndpoint sets the SAP AI Core API base URL.
func WithHTTPClient ¶
WithHTTPClient sets a custom HTTP client for all requests.
func WithHeaders ¶
WithHeaders adds custom HTTP headers to every request.
func WithMaxRetries ¶
WithMaxRetries sets the server-side retry count for LLM requests. Default is 2 retries.
func WithOrchestration ¶
func WithOrchestration() Option
WithOrchestration enables orchestration mode by automatically discovering the orchestration deployment. It queries the SAP AI Core deployments API at provider creation time to find the running orchestration deployment.
func WithResourceGroup ¶
WithResourceGroup sets the SAP AI Core resource group. Defaults to "default".
Example ¶
package main
import (
"context"
"fmt"
"log"
sapaicore "github.com/PedroKlein/adk-provider-sapaicore"
)
func main() {
provider, err := sapaicore.NewProvider(context.Background(),
sapaicore.WithEndpoint("https://api.ai.prod.us-east-1.aws.ml.hana.ondemand.com"),
sapaicore.WithAuth("client-id", "client-secret", "https://auth.example.com/oauth/token"),
sapaicore.WithDeploymentID("d1234abc"),
sapaicore.WithResourceGroup("my-team-rg"),
)
if err != nil {
log.Fatal(err)
}
llm, err := provider.Model("gpt-4.1")
if err != nil {
log.Fatal(err)
}
fmt.Println(llm.Name())
}
Output: gpt-4.1
func WithTimeout ¶
WithTimeout sets the server-side LLM request timeout in seconds. Default is 600 seconds.
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider creates model.LLM instances backed by SAP AI Core deployments.
func NewProvider ¶
NewProvider validates the given options and returns a ready-to-use Provider. It returns ErrMissingConfig if required options are absent.
If no mode is specified, orchestration auto-discovery is used by default. NewProvider makes an HTTP call to discover the orchestration deployment ID when auto-discovery is active.
ctx is used for any HTTP calls made during provider initialization (e.g. orchestration deployment discovery). It does not affect subsequent Model() or GenerateContent() calls.
Example (FoundationModels) ¶
package main
import (
"context"
"fmt"
"log"
sapaicore "github.com/PedroKlein/adk-provider-sapaicore"
)
func main() {
provider, err := sapaicore.NewProvider(context.Background(),
sapaicore.WithEndpoint("https://api.ai.prod.us-east-1.aws.ml.hana.ondemand.com"),
sapaicore.WithAuth("client-id", "client-secret", "https://auth.example.com/oauth/token"),
sapaicore.WithDeployments(map[string]string{
"gpt-4.1": "d1234abc",
"gpt-4.1-mini": "d5678def",
}),
)
if err != nil {
log.Fatal(err)
}
llm, err := provider.Model("gpt-4.1")
if err != nil {
log.Fatal(err)
}
fmt.Println(llm.Name())
}
Output: gpt-4.1
Example (Orchestration) ¶
package main
import (
"context"
"fmt"
"log"
sapaicore "github.com/PedroKlein/adk-provider-sapaicore"
)
func main() {
provider, err := sapaicore.NewProvider(context.Background(),
sapaicore.WithEndpoint("https://api.ai.prod.us-east-1.aws.ml.hana.ondemand.com"),
sapaicore.WithAuth("client-id", "client-secret", "https://auth.example.com/oauth/token"),
sapaicore.WithDeploymentID("d1234abc"), // or use WithOrchestration() for auto-discovery
)
if err != nil {
log.Fatal(err)
}
llm, err := provider.Model("gpt-4.1")
if err != nil {
log.Fatal(err)
}
fmt.Println(llm.Name())
}
Output: gpt-4.1
func (*Provider) Model ¶
Model returns a model.LLM for the given model name.
In orchestration mode, name is any SAP AI Core model identifier (e.g. "gpt-4.1", "anthropic--claude-4.5-sonnet").
In foundation-models mode, name must exist in the map provided to WithDeployments. Returns ErrDeploymentNotFound if the name is not registered.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
auth
Package auth manages OAuth2 client-credentials tokens with thread-safe caching.
|
Package auth manages OAuth2 client-credentials tokens with thread-safe caching. |
|
convert
Package convert transforms between Google genai types and OpenAI-compatible wire types.
|
Package convert transforms between Google genai types and OpenAI-compatible wire types. |
|
foundation
Package foundation implements the SAP AI Core foundation-models mode strategy.
|
Package foundation implements the SAP AI Core foundation-models mode strategy. |
|
openai
Package openai defines wire types for the OpenAI-compatible chat completions format used by both SAP AI Core API modes.
|
Package openai defines wire types for the OpenAI-compatible chat completions format used by both SAP AI Core API modes. |
|
orchestration
Package orchestration implements the SAP AI Core orchestration mode strategy.
|
Package orchestration implements the SAP AI Core orchestration mode strategy. |
|
request
Package request provides shared HTTP execution for SAP AI Core inference requests.
|
Package request provides shared HTTP execution for SAP AI Core inference requests. |
|
stream
Package stream handles Server-Sent Events parsing and incremental aggregation of streaming chat completion responses.
|
Package stream handles Server-Sent Events parsing and incremental aggregation of streaming chat completion responses. |
|
Package smoketest provides integration tests against a live SAP AI Core instance.
|
Package smoketest provides integration tests against a live SAP AI Core instance. |