@lgrammel/open-meteo-tool
v0.4.0
Published
AI SDK 7 tools for Open-Meteo location lookup, weather reports, and forecasts.
Readme
@lgrammel/open-meteo-tool
AI SDK 7 tool for resolving place names and fetching current weather reports and forecasts through Open-Meteo. The package calls Open-Meteo with fetch directly and does not require an API key.
Install
bun add @lgrammel/open-meteo-tool aiUsage
import { openai } from "@ai-sdk/openai";
import { weather } from "@lgrammel/open-meteo-tool";
import { ToolLoopAgent } from "ai";
const agent = new ToolLoopAgent({
model: openai("gpt-5.5"),
instructions:
"Use the weather tool for current conditions and forecasts. Mention the resolved location and units in the answer.",
tools: {
weather,
},
});
const result = await agent.generate({
prompt: "Will I need an umbrella in Berlin tomorrow?",
});
console.log(result.text);Tools
weather: resolves a place name through Open-Meteo geocoding, then fetches current weather, daily forecasts, and near-term hourly forecasts for the best matching location. Input is{ query }. Output includes the resolvedlocationandforecast.
Optional configuration lives in toolsContext and is validated by the tool's contextSchema, so the model cannot choose forecast horizon, unit preferences, timezone, API hosts, or returned hourly output size.
Context
baseUrl: Open-Meteo Forecast API base URL. Defaults tohttps://api.open-meteo.com.geocodingBaseUrl: Open-Meteo Geocoding API base URL. Defaults tohttps://geocoding-api.open-meteo.com.userAgent: optionalUser-Agentheader for Open-Meteo requests.language: geocoding result language. Defaults toen.forecastDays: number of forecast days to request. Defaults to7and is capped at16.hourlyForecastHours: number of hourly forecast entries returned from the start of the forecast. Defaults to24and is capped at384. Use0to omit hourly output.timezone: timezone used by Open-Meteo for forecast timestamps. Defaults toauto.temperatureUnit: temperature unit used by Open-Meteo. Defaults tocelsius. Supported values arecelsiusandfahrenheit.windSpeedUnit: wind speed unit used by Open-Meteo. Defaults tokmh. Supported values arekmh,ms,mph, andkn.precipitationUnit: precipitation unit used by Open-Meteo. Defaults tomm. Supported values aremmandinch.
