Advanced Topics

Choosing an AI Provider with AIProviderType

AIProviderType.XAI, OpenAI, and Anthropic are the three AI providers GPAL supports. Picking one does more than label the provider. It wires in the correct API base URL, endpoint, authentication header style, and a default model, all at once.

Picking a Provider

AIProviderType is a closed enum with three values: XAI, OpenAI, and Anthropic. Each is wired to a concrete implementation that knows the correct API base URL, endpoint path, and authentication header style for that provider. .WithProvider(AIProviderType.Anthropic) carries all of that behavior automatically. GPAL does not need to pattern-match a string at runtime.

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

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

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();

What Each Value Configures

Each provider value wires in the correct API base, endpoint path, authentication header style, and a sensible default model. Anthropic's API has a different shape from the other two -- different header names, a required field the others don't use -- but none of that shows up in your workflow code. WithProvider is all it takes, and WithModel overrides the default model for any provider the same way regardless of which one you picked.

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.