FeaturesTemplatesShowcaseTownie
AI
BlogDocsPricing
Log inSign up
project logo
LladPlantfo
API for AI plant info
Public
Like
Plantfo
Home
Code
3
backend
2
README.md
test.html
Branches
2
Pull requests
Remixes
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
README.md
Code
/
README.md
Search
6/10/2025
Viewing readonly version of main branch: v52
View latest version
README.md

Plant Information API

A REST API that provides detailed plant information using OpenAI's GPT model with intelligent caching for improved performance and reduced API costs.

Features

  • Get comprehensive plant information by name
  • Structured JSON response with 8 key plant characteristics
  • Powered by OpenAI GPT-4o-mini for accurate plant data
  • Intelligent caching system - stores successful responses and serves cached data for repeated requests
  • Cache management endpoints for monitoring and administration
  • Automatic plant name normalization for consistent caching

API Endpoints

GET /

Returns API information, usage instructions, and cache statistics.

GET /plant/:name

Returns detailed information about a specific plant. If the plant information is already cached, returns the cached response immediately. Otherwise, fetches new information from OpenAI and caches it for future requests.

Parameters:

  • name (string, required): The name of the plant to look up

Response Format:

{ "name": "Common and scientific name", "description": "Detailed description of the plant", "lightNeeds": "Light requirements", "soilNeeds": "Soil type and pH requirements", "moistureNeeds": "Watering requirements", "bloomTime": "Blooming season/months", "height": "Mature height range", "spread": "Mature spread/width range", "_cached": true, "_cacheTimestamp": "2024-01-01T12:00:00.000Z" }

Cache Indicators:

  • _cached: Boolean indicating if the response came from cache (true) or OpenAI (false)
  • _cacheTimestamp: ISO timestamp of when the response was generated

Example Request:

GET /plant/rose

Example Response (from cache):

{ "name": "Rose (Rosa spp.)", "description": "Roses are woody perennial flowering plants with fragrant blooms...", "lightNeeds": "Full sun (6+ hours direct sunlight daily)", "soilNeeds": "Well-draining, fertile soil with pH 6.0-7.0", "moistureNeeds": "Regular watering, 1-2 inches per week", "bloomTime": "Late spring through fall (May-October)", "height": "1-8 feet depending on variety", "spread": "2-6 feet depending on variety", "_cached": true, "_cacheTimestamp": "2024-01-01T12:00:00.000Z" }

GET /health

Health check endpoint that returns API status.

GET /cache/stats

Returns cache statistics including total cached entries and timestamps.

Response Format:

{ "totalEntries": 15, "oldestEntry": "2024-01-01T10:00:00.000Z", "newestEntry": "2024-01-01T12:00:00.000Z" }

GET /cache/list

Returns a list of all cached plants with their normalized names and creation timestamps.

Response Format:

{ "totalEntries": 2, "plants": [ { "plantName": "Rose", "normalizedName": "rose", "createdAt": "2024-01-01T12:00:00.000Z" }, { "plantName": "Japanese Maple", "normalizedName": "japanese_maple", "createdAt": "2024-01-01T11:30:00.000Z" } ] }

POST /cache/clear

Clears all cached plant information. Useful for maintenance or testing.

Response Format:

{ "message": "Cache cleared successfully", "timestamp": "2024-01-01T12:00:00.000Z" }

Error Handling

The API returns appropriate HTTP status codes:

  • 200: Success
  • 400: Bad request (missing plant name)
  • 500: Server error (OpenAI API issues, parsing errors)

Error responses include descriptive error messages and may include additional debugging information.

Usage Examples

# Get information about a rose (will cache the response) curl https://your-api-url/plant/rose # Get information about the same rose again (will return cached response) curl https://your-api-url/plant/rose # Get information about a tomato plant curl https://your-api-url/plant/tomato # Get information about a Japanese maple (spaces are handled automatically) curl https://your-api-url/plant/japanese%20maple # Check cache statistics curl https://your-api-url/cache/stats # List all cached plants curl https://your-api-url/cache/list # Clear the cache curl -X POST https://your-api-url/cache/clear

Caching Behavior

  • Plant name normalization: Plant names are normalized (lowercased, special characters removed, spaces converted to underscores) for consistent caching
  • Cache hits: Subsequent requests for the same plant (even with different capitalization or spacing) will return cached responses instantly
  • Cache misses: New plants trigger OpenAI API calls and the responses are automatically cached
  • Performance: Cached responses are served in milliseconds vs. seconds for OpenAI API calls
  • Cost efficiency: Reduces OpenAI API usage and associated costs

Technical Details

  • Built with Hono framework
  • Uses OpenAI GPT-4o-mini model
  • SQLite database for caching with automatic table creation
  • Includes input validation and error handling
  • Returns structured JSON responses
  • Supports URL-encoded plant names
  • Intelligent plant name normalization for cache consistency
  • Cache management endpoints for monitoring and administration
Go to top
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Product
FeaturesPricing
Developers
DocsStatusAPI ExamplesNPM Package Examples
Explore
ShowcaseTemplatesNewest ValsTrending ValsNewsletter
Company
AboutBlogCareersBrandhi@val.town
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.