CherryHQ/cherry-studio · error · Error
Use embeddingModel() for embedding endpoint type
Error message
Use embeddingModel() for embedding endpoint type
What it means
Thrown by createNewApi's createChatModel() when endpointType === 'embedding'. The provider deliberately separates chat-language resolution from embedding resolution: embedding-typed models must go through provider.embeddingModel(), not provider()/languageModel()/chatModel(). The throw converts a silent wrong-SDK instantiation into an immediate, explicit failure.
Source
Thrown at src/main/ai/provider/custom/newapiProvider.ts:130
provider: `${NEWAPI_PROVIDER_NAME}.chat`,
url,
headers: authHeaders,
fetch: customFetch
})
const createChatModel = (modelId: string): LanguageModelV3 => {
switch (endpointType) {
case 'anthropic':
return createAnthropicModel(modelId)
case 'gemini':
return createGeminiModel(modelId)
case 'openai-response':
return createResponsesModel(modelId)
case 'openai':
case 'image-generation':
return createCompatibleModel(modelId)
case 'embedding':
throw new Error('Use embeddingModel() for embedding endpoint type')
case 'jina-rerank':
throw new Error('Use rerankingModel() for jina-rerank endpoint type')
default:
return createCompatibleModel(modelId)
}
}
const provider = (modelId: string) => createChatModel(modelId)
provider.specificationVersion = 'v3' as const
provider.languageModel = createChatModel
provider.embeddingModel = (modelId: string) =>
new OpenAICompatibleEmbeddingModel(modelId, {
provider: `${NEWAPI_PROVIDER_NAME}.embedding`,
url,
headers: authHeaders,
fetch: customFetchView on GitHub (pinned to 726446b54c)
Solutions
- Route embedding-typed NewAPI models through provider.embeddingModel(modelId) — not through the chat/language path.
- Fix the upstream endpoint_type assignment: a chat-capable model should have endpoint_type 'openai'/'anthropic'/'gemini', not 'embedding'.
- Before resolving a model, check resolveEffectiveEndpoint(provider, model).endpointType and dispatch to the matching provider method.
- Catch and surface a user-facing message: 'This model is configured as an embedding endpoint; switch the endpoint type or pick a chat model.'
Example fix
// before const model = newApiProvider.languageModel(modelId) // throws if endpointType==='embedding' // after — dispatch by endpoint type const ep = resolveEffectiveEndpoint(provider, model).endpointType const model = ep === 'embedding' ? newApiProvider.embeddingModel(modelId) : newApiProvider.languageModel(modelId)
Defensive patterns
Strategy: validation
Validate before calling
// Dispatch by endpoint type before model resolution
const ep = resolveEffectiveEndpoint(provider, model).endpointType
if (ep === 'embedding') {
throw new Error('Use provider.embeddingModel() for embedding-typed models')
} Type guard
export function isEmbeddingEndpointMisroute(e: unknown): boolean {
return e instanceof Error && /Use embeddingModel\(\)/.test(e.message)
} Try / catch
try {
newApiProvider.languageModel(modelId)
} catch (e) {
if (isEmbeddingEndpointMisroute(e)) return newApiProvider.embeddingModel(modelId)
throw e
} Prevention
- Always consult endpoint_type before choosing the resolution method.
- Keep the endpoint_type in model config accurate to the model's real capability.
- Add a unit test that asserts chat resolution throws for embedding/jina-rerank types.
When it happens
Trigger: A NewAPI model record whose endpoint_type is 'embedding' is routed through the chat path — i.e. provider(modelId), provider.languageModel(modelId), or provider.chatModel(modelId) is invoked. Typically caused by the endpoint-type resolver returning 'embedding' for a model the caller intends to use for chat.
Common situations: Misconfigured endpoint_type in the provider/model config (e.g. an embedding model flagged as a chat model), or generic code that always calls provider() without consulting the endpoint type.
Related errors
- Use rerankingModel() for jina-rerank endpoint type
- Image generation job: no async transport for '${sdkConfig.pr
- Provider extension "${id}" not found. Did you forget to regi
- [theme-contract] ${label} contains duplicate names
- [theme-contract] ${label} has an invalid or duplicate surfac
AI-assisted analysis of CherryHQ/cherry-studio@726446b54c (2026-08-12).
Data as JSON: /api/errors/1554d4b6885240fb.
Report an issue: GitHub.