MCPcopy Create free account
hub / github.com/anomalyco/opencode / model

Function model

packages/opencode/src/session/llm/native-request.ts:153–179  ·  view source on GitHub ↗
(input: Provider.Model | RequestInput, headers?: Record<string, string>)

Source from the content-addressed store, hash-verified

151}
152
153export const model = (input: Provider.Model | RequestInput, headers?: Record<string, string>) => {
154 const model = "model" in input ? input.model : input
155 const url = baseURL(input)
156 const options = {
157 ...("model" in input && input.apiKey ? { apiKey: input.apiKey } : {}),
158 ...(url ? { baseURL: url } : {}),
159 headers: Object.keys({ ...model.headers, ...headers }).length === 0 ? undefined : { ...model.headers, ...headers },
160 limits: {
161 context: model.limit.context,
162 output: model.limit.output,
163 },
164 }
165 if (model.api.npm === "@ai-sdk/openai") return OpenAI.configure(options).responses(model.api.id)
166 if (model.api.npm === "@ai-sdk/azure")
167 return Azure.configure({ ...options, baseURL: requireBaseURL(model, url) }).responses(model.api.id)
168 if (model.api.npm === "@ai-sdk/anthropic") return Anthropic.configure(options).model(model.api.id)
169 if (model.api.npm === "@ai-sdk/google") return Google.configure(options).model(model.api.id)
170 if (model.api.npm === "@ai-sdk/amazon-bedrock") return AmazonBedrock.configure(options).model(model.api.id)
171 if (model.api.npm === "@ai-sdk/openai-compatible")
172 return OpenAICompatible.configure({
173 ...options,
174 provider: String(model.providerID),
175 baseURL: requireBaseURL(model, url),
176 }).model(model.api.id)
177 if (model.api.npm === "@openrouter/ai-sdk-provider") return OpenRouter.configure(options).model(model.api.id)
178 throw new Error(`Native LLM request adapter does not support provider package ${model.api.npm}`)
179}
180
181export const request = (input: RequestInput) => {
182 const converted = messages(input.messages)

Callers 2

requestFunction · 0.70
RunFooterViewFunction · 0.50

Calls 4

baseURLFunction · 0.85
requireBaseURLFunction · 0.85
responsesMethod · 0.80
modelMethod · 0.80

Tested by

no test coverage detected