Skip to main content
This guide explains how to integrate Refile’s PDF generation capabilities with LangChain.js in just a few lines of code. This integration allows LLMs to generate PDFs directly from markdown content as part of their response flow.

Prerequisites

  • A refile API key (available from your refile dashboard)
  • Node.js project with LangChain.js installed
  • Basic familiarity with LangChain.js usage patterns

Quick Start

  1. Install the dependencies:
  1. Copy the refile tool code and use it with LangChain:
  1. Replace <token> with your refile API key and start generating PDFs!

How It Works

The integration follows these steps:
  1. Create the tool: The createRefileTool function creates a LangChain-compatible tool that connects to the Refile API
  2. Bind the tool to the model: Use LangChain’s bindTools method to give the model access to the PDF generation capability
  3. Process tool calls: When the model decides to generate a PDF, it makes a tool call which your code executes
  4. Return results: The final result includes the URL of the generated PDF

Customization Options

Want a different look? Just change these parameters when calling createRefileTool():
Remember to keep your API key safe by using environment variables in production and never exposing your key in client side code! For a detailed explanation of the API and all configuration options, visit the API reference.