A4F icon

A4F

Use the A4F API

Overview

This node integrates with the A4F API to generate chat completions using specified AI language models. It is designed to send a sequence of messages (with roles such as system, user, or assistant) to the API and receive a generated response based on those inputs.

Common scenarios where this node is beneficial include:

  • Automating conversational agents or chatbots.
  • Generating AI-driven responses in customer support workflows.
  • Creating content or text completions based on prior conversation context.
  • Experimenting with different AI models for natural language generation.

For example, you can provide a series of messages representing a dialogue history and get the next assistant reply generated by the model.

Properties

Name Meaning
Model The AI model to use for generating the chat completion. Example: "provider-1/chatgpt-4o-latest".
Messages A collection of messages forming the conversation history. Each message has:
- Role: The role of the message sender (System, User, or Assistant).
- Content: The textual content of the message.
Options Additional optional parameters to customize the completion:
- Temperature: Controls randomness (0 to 2). Lower values make output more deterministic.
- Max Tokens: Maximum tokens to generate.
- Top P: Controls diversity via nucleus sampling (0 to 1).

Output

The node outputs an array of JSON objects, each containing the full response from the A4F API under the json property. This response includes the generated chat completion data as returned by the API.

No binary data output is produced by this node.

Dependencies

  • Requires an active connection to the A4F API service.
  • Needs an API authentication token configured in n8n credentials (referred generically as "an API key credential").
  • Network access to https://api.a4f.co/v1/chat/completions.

Troubleshooting

  • Common issues:

    • Invalid or missing API credentials will cause authentication failures.
    • Incorrectly formatted messages (e.g., missing roles or content) may lead to API errors.
    • Exceeding token limits or invalid parameter values (temperature, max tokens, top_p) might cause request rejections.
  • Error messages:

    • Errors thrown by the API are caught and either stop execution or, if "Continue On Fail" is enabled, return an error object in the output.
    • Typical error messages relate to authentication failure, invalid parameters, or rate limiting.
  • Resolution tips:

    • Verify that the API key credential is correctly set up.
    • Ensure all required properties are provided and valid.
    • Adjust parameters like temperature and max tokens within allowed ranges.
    • Use "Continue On Fail" cautiously to handle partial failures gracefully.

Links and References

Discussion