{"record":{"id":"1554d4b6885240fb","repo":"CherryHQ/cherry-studio","slug":"use-embeddingmodel-for-embedding-endpoint-type","errorCode":null,"errorMessage":"Use embeddingModel() for embedding endpoint type","messagePattern":"Use embeddingModel\\(\\) for embedding endpoint type","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/main/ai/provider/custom/newapiProvider.ts","lineNumber":130,"sourceCode":"      provider: `${NEWAPI_PROVIDER_NAME}.chat`,\n      url,\n      headers: authHeaders,\n      fetch: customFetch\n    })\n\n  const createChatModel = (modelId: string): LanguageModelV3 => {\n    switch (endpointType) {\n      case 'anthropic':\n        return createAnthropicModel(modelId)\n      case 'gemini':\n        return createGeminiModel(modelId)\n      case 'openai-response':\n        return createResponsesModel(modelId)\n      case 'openai':\n      case 'image-generation':\n        return createCompatibleModel(modelId)\n      case 'embedding':\n        throw new Error('Use embeddingModel() for embedding endpoint type')\n      case 'jina-rerank':\n        throw new Error('Use rerankingModel() for jina-rerank endpoint type')\n      default:\n        return createCompatibleModel(modelId)\n    }\n  }\n\n  const provider = (modelId: string) => createChatModel(modelId)\n  provider.specificationVersion = 'v3' as const\n\n  provider.languageModel = createChatModel\n\n  provider.embeddingModel = (modelId: string) =>\n    new OpenAICompatibleEmbeddingModel(modelId, {\n      provider: `${NEWAPI_PROVIDER_NAME}.embedding`,\n      url,\n      headers: authHeaders,\n      fetch: customFetch","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/CherryHQ/cherry-studio/blob/726446b54cd69ffe51a276638672f6d95ca0768c/src/main/ai/provider/custom/newapiProvider.ts#L112-L148","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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.'"],"exampleFix":"// before\nconst model = newApiProvider.languageModel(modelId) // throws if endpointType==='embedding'\n// after — dispatch by endpoint type\nconst ep = resolveEffectiveEndpoint(provider, model).endpointType\nconst model = ep === 'embedding'\n  ? newApiProvider.embeddingModel(modelId)\n  : newApiProvider.languageModel(modelId)","handlingStrategy":"validation","validationCode":"// Dispatch by endpoint type before model resolution\nconst ep = resolveEffectiveEndpoint(provider, model).endpointType\nif (ep === 'embedding') {\n  throw new Error('Use provider.embeddingModel() for embedding-typed models')\n}","typeGuard":"export function isEmbeddingEndpointMisroute(e: unknown): boolean {\n  return e instanceof Error && /Use embeddingModel\\(\\)/.test(e.message)\n}","tryCatchPattern":"try {\n  newApiProvider.languageModel(modelId)\n} catch (e) {\n  if (isEmbeddingEndpointMisroute(e)) return newApiProvider.embeddingModel(modelId)\n  throw e\n}","preventionTips":["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."],"tags":["newapi","endpoint-type","configuration","misroute"],"backgroundTag":null,"analyzedSha":"726446b54cd69ffe51a276638672f6d95ca0768c","analyzedAt":"2026-08-12T17:30:37.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}