MCPcopy
hub / github.com/nashsu/llm_wiki / getProviderConfig

Function getProviderConfig

src/lib/llm-providers.ts:801–993  ·  view source on GitHub ↗
(config: LlmConfig)

Source from the content-addressed store, hash-verified

799}
800
801export function getProviderConfig(config: LlmConfig): ProviderConfig {
802 const { provider, apiKey, model, ollamaUrl, customEndpoint } = config
803
804 switch (provider) {
805 case "openai":
806 return {
807 url: "https://api.openai.com/v1/chat/completions",
808 headers: {
809 "Content-Type": JSON_CONTENT_TYPE,
810 Authorization: `Bearer ${apiKey}`,
811 },
812 buildBody: (messages, overrides) => ({
813 ...buildOpenAiCompatibleBody(config, messages, overrides),
814 model,
815 }),
816 parseStream: parseOpenAiLine,
817 }
818
819 case "anthropic": {
820 const url = buildAnthropicUrl("https://api.anthropic.com")
821 return {
822 url,
823 headers: buildAnthropicHeaders(apiKey, url),
824 buildBody: (messages, overrides) => {
825 assertMiniMaxImageSupport(url, model, messages)
826 return {
827 ...buildAnthropicBodyWithReasoning(config, messages, overrides),
828 model,
829 }
830 },
831 parseStream: parseAnthropicLine,
832 }
833 }
834
835 case "google": {
836 // Encode the model segment — users sometimes paste OpenRouter-style
837 // ids with slashes (e.g. "google/gemini-3-pro-preview") and bare
838 // interpolation would produce a broken URL. encodeURIComponent
839 // handles that plus any other path-illegal characters.
840 const encodedModel = encodeURIComponent(model)
841 return {
842 url: `https://generativelanguage.googleapis.com/v1beta/models/${encodedModel}:streamGenerateContent?alt=sse`,
843 headers: {
844 "Content-Type": JSON_CONTENT_TYPE,
845 "x-goog-api-key": apiKey,
846 },
847 buildBody: (messages, overrides) => buildGoogleBody(messages, {
848 ...(overrides ?? {}),
849 reasoning: effectiveReasoning(config, overrides),
850 }),
851 parseStream: parseGoogleLine,
852 }
853 }
854
855 case "azure": {
856 return {
857 url: buildAzureOpenAiUrl(
858 customEndpoint,

Callers 3

streamChatFunction · 0.90

Calls 11

buildAzureOpenAiUrlFunction · 0.90
isAzureOpenAiEndpointFunction · 0.90
buildAnthropicUrlFunction · 0.85
buildAnthropicHeadersFunction · 0.85
buildGoogleBodyFunction · 0.85
effectiveReasoningFunction · 0.85
localLlmOriginHeaderFunction · 0.85

Tested by

no test coverage detected