OpenRouter Chat Model

Interact with various AI models through OpenRouter API

Overview

This node enables interaction with multiple AI chat models via the OpenRouter API. It sends user messages along with optional system instructions to selected AI models and returns their generated responses. The node supports maintaining conversation history (memory) to enable context-aware dialogues.

Common scenarios include:

  • Automating customer support chats by integrating AI assistants.
  • Generating creative or technical text completions based on prompts.
  • Experimenting with different AI models for chat-based applications.
  • Maintaining conversational context over multiple interactions.

For example, a user can send a system message defining the assistant’s behavior, then send user queries, optionally preserving conversation history to get coherent multi-turn conversations.

Properties

Name Meaning
Model The AI model to use for chat completion. Options: GPT-4 Turbo, GPT-3.5 Turbo, Claude 3 Sonnet, Claude 3 Haiku, Llama 2 70B, Mixtral 8x7B.
System Message A system-level instruction to set the behavior or persona of the AI assistant.
Message The user message or prompt to send to the AI model.
Temperature Controls randomness in the AI response generation; ranges from 0 (deterministic) to 2 (very random).
Max Tokens Maximum number of tokens the AI is allowed to generate in the response.
Use Memory Boolean flag to enable maintaining conversation history across executions.
Memory Key The key under which conversation history is stored when memory is enabled. Defaults to "chat_history".

Output

The node outputs an array of items where each item contains a json object with the following fields:

  • response: The text content generated by the AI model in reply to the input message.
  • model: The identifier of the AI model used for generating the response.
  • usage: An object detailing token usage statistics returned by the API (e.g., tokens consumed).
  • All original input JSON data merged alongside the above fields.

No binary data output is produced by this node.

Dependencies

  • Requires an API key credential for the OpenRouter API service.
  • Makes HTTP POST requests to https://openrouter.ai/api/v1/chat/completions.
  • Needs network access to the OpenRouter API endpoint.
  • No additional environment variables are required beyond the API key credential.

Troubleshooting

  • Common issues:

    • Invalid or missing API key will cause authentication failures.
    • Exceeding max tokens or rate limits may result in API errors.
    • Improperly formatted messages or system instructions might lead to unexpected AI responses.
    • If memory is enabled but the memory key is misconfigured, conversation history may not persist correctly.
  • Error messages:

    • Errors from the API are caught and either thrown or returned as error objects depending on the node's "Continue On Fail" setting.
    • Typical error messages include authentication errors, request timeouts, or invalid parameter errors.
  • Resolutions:

    • Verify the API key is valid and has necessary permissions.
    • Adjust temperature and max tokens to reasonable values.
    • Ensure the system message and user message are properly formatted strings.
    • When using memory, confirm the memory key is consistent and that the workflow static data is accessible.

Links and References

Discussion