Advanced Topics

Choosing an AI Provider with AIProviderType

Built-in Providers and Custom Strings

AIProviderType is an open-ended struct, not a closed enum. XAI, OpenAI, and Anthropic are named constants you can use directly, but you can also pass any string -- including a provider name you define in AIProvidersConfig.yaml. At runtime GPAL looks up the matching definition by name and wires in the correct base URL, endpoint path, authentication header style, and default model. The three built-in providers work with no config file on disk.

GPALTextArea inputArea = GPAL.TextArea.WithName("input").ToGPALObject();

GPALTextArea outputArea = GPAL.TextArea.WithName("output").ToGPALObject();


// Built-in providers work with no config file

IGPALAI aiTask = GPAL.AI

.WithProvider(AIProviderType.Anthropic)

.WithCredentials(GPAL.CredentialsFor(CredentialServiceType.StaticKey)

.WithKeyFromEnv("ANTKEY")

.ToGPALObject())

.WithTask(AITask.Summarization)

.WithModel(AIModel.Claude35Sonnet)

.WithInputFrom(inputArea)

.WithOutputTo(outputArea)

.ToGPALObject();


// Any string implicitly converts

IGPALAI customTask = GPAL.AI

.WithProvider("Mistral")

.WithCredentials(...)

.WithTask(AITask.Summarization)

.WithInputFrom(inputArea)

.WithOutputTo(outputArea)

.ToGPALObject();

AIProvidersConfig.yaml: Adding and Overriding Providers

Provider details -- the API base URL, endpoint path, auth header name and prefix, default model, and response format -- all live in AIProvidersConfig.yaml. GPAL tries to load this file silently on startup: no event if it is absent, an INFO event if it loads successfully. Call AIProvidersConfig.Save() without arguments to write the current built-in definitions to disk as a starting template. Add custom entries or adjust defaults and they take effect on the next run without recompiling.

# AIProvidersConfig.yaml

providers:

- name: Anthropic

baseUrl: https://api.anthropic.com/v1

chatEndpoint: /messages

defaultModel: claude-opus-4-8-20251101

authHeader: x-api-key

authPrefix: ""

responseFormat: anthropic

additionalHeaders:

anthropic-version: "2023-06-01"

- name: XAI

baseUrl: https://api.x.ai/v1

chatEndpoint: /chat/completions

defaultModel: grok-3-mini

authHeader: Authorization

authPrefix: "Bearer "

responseFormat: openai

- name: Mistral

baseUrl: https://api.mistral.ai/v1

chatEndpoint: /chat/completions

defaultModel: mistral-large-latest

authHeader: Authorization

authPrefix: "Bearer "

responseFormat: openai

Credentials Are Still Separate

AIProviderType only selects which provider's request shape and endpoints to use -- it does not supply the API key. That still comes from WithCredentials, built with GPAL.CredentialsFor(CredentialServiceType.StaticKey) (see Static API Key Credentials). The two are configured independently -- GPAL does not check that the key and provider match.

WARNING

Supplying an xAI key while using AIProviderType.OpenAI will compile and run. The mismatch only surfaces as an authentication error at request time.

💬 Ask GPAL