davidmigloz / langchain_dart

Build LLM-powered Dart/Flutter applications.
https://langchaindart.dev
MIT License
403 stars 69 forks source link

CORS error with openrouter #510

Closed richardchui closed 2 months ago

richardchui commented 2 months ago

Using openrouter will encounter a CORS issue. No problem with other services such as TogetherAI and Groq.

Have tried using openrouter with another dart package (dart_openai) and everything works fine.

davidmigloz commented 2 months ago

Hey @richardchui,

OpenRouter doesn't allow the OpenAI-Beta header in its CORS configuration. The OpenAIClient sets this header by default to enable the assistants API which is still in beta. You can remove this header by settings beta: null:

final client = OpenAIClient(
  apiKey: Platform.environment['OPEN_ROUTER_API_KEY'],
  baseUrl: 'https://openrouter.ai/api/v1',
  beta: null,
);
richardchui commented 2 months ago

Problem sovled. Cannot thank you enough for this.