OpenLink

AI Tools

Use openlink as a tool for LLMs and AI agents.

OpenLink is perfect for AI applications that need to fetch link metadata. Use it as a tool for function calling with any LLM.

OpenAI Function Calling

import OpenAI from "openai"
import { preview } from "openlink"

const openai = new OpenAI()

const tools = [
  {
    type: "function",
    function: {
      name: "get_link_preview",
      description: "Get metadata and preview information for a URL",
      parameters: {
        type: "object",
        properties: {
          url: {
            type: "string",
            description: "The URL to get preview data for"
          }
        },
        required: ["url"]
      }
    }
  }
]

async function handleToolCall(name: string, args: { url: string }) {
  if (name === "get_link_preview") {
    return await preview(args.url)
  }
}

const response = await openai.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "user", content: "What is github.com about?" }],
  tools
})

if (response.choices[0].message.tool_calls) {
  const call = response.choices[0].message.tool_calls[0]
  const result = await handleToolCall(
    call.function.name,
    JSON.parse(call.function.arguments)
  )
  console.log(result)
}

Anthropic Claude

import Anthropic from "@anthropic-ai/sdk"
import { preview } from "openlink"

const anthropic = new Anthropic()

const tools = [
  {
    name: "get_link_preview",
    description: "Get metadata and preview information for a URL",
    input_schema: {
      type: "object",
      properties: {
        url: {
          type: "string",
          description: "The URL to get preview data for"
        }
      },
      required: ["url"]
    }
  }
]

const response = await anthropic.messages.create({
  model: "claude-sonnet-4-20250514",
  max_tokens: 1024,
  tools,
  messages: [{ role: "user", content: "Summarize vercel.com for me" }]
})

for (const block of response.content) {
  if (block.type === "tool_use" && block.name === "get_link_preview") {
    const data = await preview(block.input.url)
    console.log(data)
  }
}

Vercel AI SDK

import { openai } from "@ai-sdk/openai"
import { generateText, tool } from "ai"
import { preview } from "openlink"
import { z } from "zod"

const result = await generateText({
  model: openai("gpt-4o"),
  tools: {
    linkPreview: tool({
      description: "Get metadata for a URL",
      parameters: z.object({
        url: z.string().describe("The URL to preview")
      }),
      execute: async ({ url }) => preview(url)
    })
  },
  prompt: "What is stripe.com about?"
})

console.log(result.text)

LangChain

import { ChatOpenAI } from "@langchain/openai"
import { DynamicStructuredTool } from "@langchain/core/tools"
import { preview } from "openlink"
import { z } from "zod"

const linkPreviewTool = new DynamicStructuredTool({
  name: "link_preview",
  description: "Get metadata and preview information for a URL",
  schema: z.object({
    url: z.string().describe("The URL to get preview data for")
  }),
  func: async ({ url }) => {
    const data = await preview(url)
    return JSON.stringify(data)
  }
})

const model = new ChatOpenAI({ model: "gpt-4o" })
const modelWithTools = model.bindTools([linkPreviewTool])

const response = await modelWithTools.invoke("What is github.com?")

Use Cases

Use CaseDescription
Link summarizationExtract title and description for AI to summarize
Content analysisAnalyze page metadata for categorization
Research agentsGather information from multiple URLs
Chat assistantsShow rich previews when users share links
Content curationAutomatically extract metadata for saved links

Best Practices

Error Handling

import { preview, PreviewError } from "openlink"

async function safePreview(url: string) {
  try {
    return await preview(url)
  } catch (error) {
    if (error instanceof PreviewError) {
      return { error: error.message, code: error.code }
    }
    return { error: "Unknown error" }
  }
}

Timeout for AI Tools

Set a reasonable timeout to avoid blocking AI responses:

const data = await preview(url, { timeout: 5000 })

Include Raw Data

For more context, include raw metadata:

const data = await preview(url, { includeRaw: true })

On this page