@@ -3,6 +3,8 @@ import { createGoogleGenerativeAI } from "@ai-sdk/google";
33import { createOpenRouter } from "@openrouter/ai-sdk-provider" ;
44import { createOllama } from "ollama-ai-provider" ;
55import { createMistral } from "@ai-sdk/mistral" ;
6+ import { createOpenAI } from "@ai-sdk/openai" ;
7+ import { createAnthropic } from "@ai-sdk/anthropic" ;
68import { generateText } from "ai" ;
79import { LingoDotDevEngine } from "@lingo.dev/_sdk" ;
810import { DictionarySchema } from "../schema" ;
@@ -20,6 +22,10 @@ import {
2022 getOpenRouterKeyFromEnv ,
2123 getMistralKey ,
2224 getMistralKeyFromEnv ,
25+ getOpenAIKey ,
26+ getOpenAIKeyFromEnv ,
27+ getAnthropicKey ,
28+ getAnthropicKeyFromEnv ,
2329 getLingoDotDevKeyFromEnv ,
2430 getLingoDotDevKey ,
2531} from "../../../utils/llm-api-key" ;
@@ -383,9 +389,49 @@ export class LCPAPI {
383389 return createMistral ( { apiKey : mistralKey } ) ( modelId ) ;
384390 }
385391
392+ case "openai" : {
393+ // Specific check for CI/CD or Docker missing OpenAI key
394+ if ( isRunningInCIOrDocker ( ) ) {
395+ const openaiFromEnv = getOpenAIKeyFromEnv ( ) ;
396+ if ( ! openaiFromEnv ) {
397+ this . _failMissingLLMKeyCi ( providerId ) ;
398+ }
399+ }
400+ const openaiKey = getOpenAIKey ( ) ;
401+ if ( ! openaiKey ) {
402+ throw new Error (
403+ "⚠️ OpenAI API key not found. Please set OPENAI_API_KEY environment variable or configure it user-wide." ,
404+ ) ;
405+ }
406+ console . log (
407+ `Creating OpenAI client for ${ targetLocale } using model ${ modelId } ` ,
408+ ) ;
409+ return createOpenAI ( { apiKey : openaiKey } ) ( modelId ) ;
410+ }
411+
412+ case "anthropic" : {
413+ // Specific check for CI/CD or Docker missing Anthropic key
414+ if ( isRunningInCIOrDocker ( ) ) {
415+ const anthropicFromEnv = getAnthropicKeyFromEnv ( ) ;
416+ if ( ! anthropicFromEnv ) {
417+ this . _failMissingLLMKeyCi ( providerId ) ;
418+ }
419+ }
420+ const anthropicKey = getAnthropicKey ( ) ;
421+ if ( ! anthropicKey ) {
422+ throw new Error (
423+ "⚠️ Anthropic API key not found. Please set ANTHROPIC_API_KEY environment variable or configure it user-wide." ,
424+ ) ;
425+ }
426+ console . log (
427+ `Creating Anthropic client for ${ targetLocale } using model ${ modelId } ` ,
428+ ) ;
429+ return createAnthropic ( { apiKey : anthropicKey } ) ( modelId ) ;
430+ }
431+
386432 default : {
387433 throw new Error (
388- `⚠️ Provider "${ providerId } " for locale "${ targetLocale } " is not supported. Only "groq", "google", "openrouter", "ollama", and "mistral " providers are supported at the moment.` ,
434+ `⚠️ Provider "${ providerId } " for locale "${ targetLocale } " is not supported. Only "groq", "google", "openrouter", "ollama", "mistral", "openai", and "anthropic " providers are supported at the moment.` ,
389435 ) ;
390436 }
391437 }
0 commit comments