How to Connect an OpenAI-Compatible Model to AI Agent?

I have tried with two different AI Platforms that provide OpenAI-Compatible API for their AI Service,
(one of them being OpenRouter, to make sure this isn’t the problem with my other AI Provider)

and couldn’t create the Credentials to connect to the API using OpenAI Model Node (since its the closest node we can use for this)

this work flow works, yet when i enter the API Key and Base URL in OpenAI Credentials, it won’t work.

what am I doing wrong ? is it even possible to use OpenAI-Compatible Models with AI Agent Nodes ?

  • n8n version: 1.105.3
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main): Default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Ubuntu

Yes, it is possible. Confirm you aren’t using open AI keys with openrouter’s End point url.

you have to use and generate Openrouter API key with Openrouter endpoint url

Hello there, why you use OpenAI node? Since you can use Basic LLM Chain if you won’t use AI Agent.

n8n already have OpenRouter node for the model tools.

since I’ve posted this problem i have been in contact with the other provider that I couldn’t use in OpenAI Node, and it turns out, they have implemented a bit of an unconventional API system (in comparison on OpenAI API) so that was why the n8n couldn’t connect with the API Credentials.

the only method to connect to their API was to Set the Model Name by ID Expression in OpenAI Model Node.

thanks everybody for you’re replies

P.S: I’ve been testing with OpenRouter to check if OpenRotuer which is a OpenAI Compatible API would work with OpenAI Node or not, but clearly there was some difference that created the need for its own node.