Back to Mastra

Bird Checker with Express JS

examples/bird-checker-with-express/README.md

2025-12-181.8 KB
Original Source

Bird Checker with Express JS

An Express.js server that has an API that can get a random image from Unsplash that matches a selected query and another API that uses Mastra AI Agent to determine if an image is a bird or not. It also has braintrust eval to use evaluate the llm prompt

Features

  • 🕊️ Get random image from unspash that matches a selected query
  • 🤖 AI agent that returns a structured response

Prerequisites

  • Node.js 22.13.0 or later
  • pnpm (recommended) or npm
  • Anthropic API Key
  • Unsplash Access Key

Getting Started

  1. Clone the repository:
bash
git clone <repository-url>
cd bird-checker-with-express
  1. Install dependencies:
bash
pnpm install
  1. Copy the environment variables file:
bash
cp .env.example .env.local
  1. Configure your environment variables:
env
# Required for getting image
UNSPLASH_ACCESS_KEY=your_unsplash_access_key

# Required for AI processing
ANTHROPIC_API_KEY=your_anthropic_key

# The port you want your server to run on (optional)
PORT=your_preferred_port
  1. Start the development server:
bash
pnpm start

Usage

Open Postman or your preferred platofrom for testing APIs

Test getRandomImage tool that uses unspash image

Enter http://localhost:${PORT}/api/get-unsplash-image?query=bird in the url to get image from unsplash. This is a get request. The query can be edited to any of the following - wildlife | bird | feathers | flying

Test Mastra AI agent

Enter http://localhost:${PORT}/api/image-metadata in the url to get information about an image. This is a post request. The payload for this request:

bash
{
  imageUrl: "" //the image url
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.