chatprovider

package
v2.36.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2026 License: AGPL-3.0 Imports: 28 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// HeaderCoderOwnerID identifies the Coder user who owns the chat.
	HeaderCoderOwnerID = "X-Coder-Owner-Id"
	// HeaderCoderChatID identifies the top-level (parent) chat.
	// For root chats this is the chat's own ID; for subchats it
	// is the parent chat's ID.
	HeaderCoderChatID = "X-Coder-Chat-Id"
	// HeaderCoderSubchatID identifies the current subchat. Only
	// present when the request originates from a child chat.
	HeaderCoderSubchatID = "X-Coder-Subchat-Id"
	// HeaderCoderWorkspaceID identifies the workspace associated
	// with the chat, if any.
	HeaderCoderWorkspaceID = "X-Coder-Workspace-Id"
)

Header constants sent on upstream LLM API requests so that intermediaries (e.g. aibridged) can correlate traffic back to Coder entities.

View Source
const AnthropicBetaContext1M = "context-1m-2025-08-07"

AnthropicBetaContext1M is the beta token for Anthropic's 1M context window.

View Source
const HeaderAnthropicBeta = "Anthropic-Beta"

HeaderAnthropicBeta names Anthropic's beta feature header.

Variables

This section is empty.

Functions

func AcceptsFilePartMediaType added in v2.35.0

func AcceptsFilePartMediaType(provider, modelID, mediaType string) bool

AcceptsFilePartMediaType reports whether provider accepts mediaType as a file content part rather than silently dropping it. modelID distinguishes API paths within a provider (e.g. OpenAI Responses vs Chat Completions). Unknown providers return false so callers convert text-family content to text and guarantee the model still sees it.

func AgentsSupportsProvider added in v2.35.0

func AgentsSupportsProvider(provider string) bool

AgentsSupportsProvider reports whether the Agents harness can use the provider type.

func AnthropicThinkingDisplayFromChat added in v2.35.0

func AnthropicThinkingDisplayFromChat(value *string) *fantasyanthropic.ThinkingDisplay

AnthropicThinkingDisplayFromChat normalizes chat-config thinking display values for Anthropic and returns the canonical provider display value.

func ApplyReasoningEffort added in v2.36.0

func ApplyReasoningEffort(
	model fantasy.LanguageModel,
	options fantasy.ProviderOptions,
	effort *string,
) fantasy.ProviderOptions

func BetaHeadersFromCallConfig added in v2.36.0

func BetaHeadersFromCallConfig(providerName string, config *codersdk.ChatModelCallConfig) map[string]string

BetaHeadersFromCallConfig returns beta feature headers for Anthropic and Bedrock calls.

func CoderHeaders

func CoderHeaders(chat database.Chat) map[string]string

CoderHeaders builds the set of Coder identity headers to attach to outgoing LLM API requests for the given chat.

func InlineImageCapBytes added in v2.34.0

func InlineImageCapBytes(provider string) (int, bool)

InlineImageCapBytes returns the per-image byte cap for inline image parts, or (0, false) when no documented cap applies. Bedrock shares Anthropic's cap because fantasy's bedrock provider wraps the anthropic client.

func IsValidReasoningEffort added in v2.36.0

func IsValidReasoningEffort(value string) bool

func ModelFromConfig

func ModelFromConfig(
	providerHint string,
	modelName string,
	providerKeys ProviderAPIKeys,
	userAgent string,
	extraHeaders map[string]string,
	httpClient *http.Client,
) (fantasy.LanguageModel, error)

ModelFromConfig resolves a provider/model pair and constructs a fantasy language model client using the provided provider credentials. The userAgent is sent as the User-Agent header on every outgoing LLM API request. extraHeaders, when non-nil, are sent as additional HTTP headers on every request. httpClient, when non-nil, is used for all provider HTTP requests.

func NormalizeProvider

func NormalizeProvider(provider string) string

NormalizeProvider canonicalizes a provider name.

func ProviderAllowsAmbientCredentials added in v2.33.0

func ProviderAllowsAmbientCredentials(provider string) bool

ProviderAllowsAmbientCredentials reports whether provider can use ambient credentials from the Coder server instead of an explicit API key.

func ProviderBaseURLHostname added in v2.34.1

func ProviderBaseURLHostname(baseURL string) string

ProviderBaseURLHostname returns the normalized hostname from a provider base URL.

func ProviderDisplayName

func ProviderDisplayName(provider string) string

ProviderDisplayName returns a default display name for a provider.

func ProviderOptionsFromChatModelConfig

func ProviderOptionsFromChatModelConfig(
	model fantasy.LanguageModel,
	options *codersdk.ChatModelProviderOptions,
) fantasy.ProviderOptions

ProviderOptionsFromChatModelConfig converts chat model provider options to fantasy provider options used for inference calls.

func PruneDisabledProviderKeys

func PruneDisabledProviderKeys(keys *ProviderAPIKeys, enabledProviders map[string]struct{})

PruneDisabledProviderKeys removes entries from keys that do not belong to an enabled provider. It clears ByProvider, BaseURLByProvider, and RegionByProvider entries for disabled providers and zeroes the legacy OpenAI and Anthropic fields when those providers are not enabled.

func ReasoningEffortLessOrEqual added in v2.36.0

func ReasoningEffortLessOrEqual(a, b string) bool

ReasoningEffortLessOrEqual reports whether a is lower than or equal to b on the global effort scale. Unknown values return false.

func ResolveModelWithProviderHint

func ResolveModelWithProviderHint(modelName, providerHint string) (provider string, model string, err error)

func ResolveReasoningEffort added in v2.36.0

func ResolveReasoningEffort(
	requested *string,
	config *codersdk.ChatModelReasoningEffortConfig,
) *string

ResolveReasoningEffort computes the effective reasoning effort for a generation. The requested per-turn value wins over the config's default, and the result is clamped to the config's max on the global scale. Returns nil when the model config has no reasoning effort configured, no usable value remains, or the max is unknown.

func SelectableReasoningEfforts added in v2.36.0

func SelectableReasoningEfforts(
	config *codersdk.ChatModelReasoningEffortConfig,
) []string

func UnsupportedProviders added in v2.35.0

func UnsupportedProviders(configured []ConfiguredProvider) []codersdk.ChatUnsupportedProvider

UnsupportedProviders returns the configured providers the Agents harness cannot use, deduplicated by provider type.

func UserAgent

func UserAgent() string

UserAgent returns the User-Agent string sent on all outgoing LLM API requests made by Coder's built-in chat (chatd). The format mirrors conventions used by other coding agents so that LLM providers can identify traffic originating from Coder.

Example: coder-agents/v2.21.0 (linux/amd64)

Types

type ConfiguredModel

type ConfiguredModel struct {
	Provider    string
	Model       string
	DisplayName string
}

ConfiguredModel is an enabled model loaded from database config.

type ConfiguredProvider

type ConfiguredProvider struct {
	ProviderID                 uuid.UUID
	Provider                   string
	APIKey                     string
	BaseURL                    string
	Region                     string
	CentralAPIKeyEnabled       bool
	AllowUserAPIKey            bool
	AllowCentralAPIKeyFallback bool
}

ConfiguredProvider is an enabled provider loaded from database config.

type ModelCatalog

type ModelCatalog struct{}

func NewModelCatalog

func NewModelCatalog() *ModelCatalog

func (*ModelCatalog) ListConfiguredModels

func (*ModelCatalog) ListConfiguredModels(
	configuredProviders []ConfiguredProvider,
	configuredModels []ConfiguredModel,
	availabilityByProvider map[string]ProviderAvailability,
	enabledProviders map[string]struct{},
) (codersdk.ChatModelsResponse, bool)

ListConfiguredModels returns a model catalog from enabled DB-backed model configs. The second return value reports whether DB-backed models were used.

func (*ModelCatalog) ListConfiguredProviderAvailability

func (*ModelCatalog) ListConfiguredProviderAvailability(
	availabilityByProvider map[string]ProviderAvailability,
	enabledProviders map[string]struct{},
) codersdk.ChatModelsResponse

ListConfiguredProviderAvailability returns provider availability derived from the policy-aware availability map for enabled providers.

type ProviderAPIKeys

type ProviderAPIKeys struct {
	OpenAI            string
	Anthropic         string
	ByProvider        map[string]string
	BaseURLByProvider map[string]string
	RegionByProvider  map[string]string
}

ProviderAPIKeys contains API keys for provider calls.

func MergeProviderAPIKeys

func MergeProviderAPIKeys(fallback ProviderAPIKeys, providers []ConfiguredProvider) ProviderAPIKeys

MergeProviderAPIKeys overlays configured provider keys over fallback keys.

func ResolveUserProviderKeys

func ResolveUserProviderKeys(
	fallback ProviderAPIKeys,
	providers []ConfiguredProvider,
	userKeys []UserProviderKey,
) (ProviderAPIKeys, map[string]ProviderAvailability)

ResolveUserProviderKeys computes effective API keys and per-provider availability for a given user. It considers the provider's credential policy flags alongside central (DB/deployment) keys and the user's personal keys.

func (ProviderAPIKeys) APIKey

func (k ProviderAPIKeys) APIKey(provider string) string

APIKey returns the effective API key for a provider.

func (ProviderAPIKeys) BaseURL

func (k ProviderAPIKeys) BaseURL(provider string) string

BaseURL returns the configured base URL for a provider.

func (ProviderAPIKeys) Empty added in v2.34.0

func (k ProviderAPIKeys) Empty() bool

Empty reports whether no provider keys or base URL overrides are set.

func (ProviderAPIKeys) HasProvider added in v2.33.0

func (k ProviderAPIKeys) HasProvider(provider string) bool

HasProvider reports whether a provider has an explicit resolved entry in the provider key map, even when the resolved key is empty.

func (ProviderAPIKeys) Region added in v2.35.0

func (k ProviderAPIKeys) Region(provider string) string

Region returns the configured region for a provider.

type ProviderAvailability

type ProviderAvailability struct {
	Available         bool
	UnavailableReason codersdk.ChatModelProviderUnavailableReason
}

ProviderAvailability describes whether a provider has a usable API key and, if not, why.

type UserProviderKey

type UserProviderKey struct {
	ChatProviderID uuid.UUID
	APIKey         string
}

UserProviderKey is a user-supplied API key for a specific provider.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL