API Documentation
All edge functions, their inputs, outputs, and example usage.
google-maps-key
Securely serves the Google Maps API key to the frontend. The key is stored as a Cloud secret and never exposed in client code.
Method
GET (via supabase.functions.invoke)
Auth Required
No (anon access)
Secret
GOOGLE_MAPS_API_KEY
Response
{ "key": "AIza..." }Error Response
{ "error": "GOOGLE_MAPS_API_KEY not configured" }Usage Example
const { data, error } = await supabase.functions.invoke('google-maps-key');
if (data?.key) {
// Load Google Maps script with key
}suggest-stops
AI-powered stop suggestions for a trip day. Uses Lovable AI Gateway + Google Places verification.
Method
POST
Auth Required
No (available to guests)
Request Body
{
"startLocation": "Barcelona, Spain",
"endLocation": "Skopje, North Macedonia",
"day": { "dayNumber": 2, "date": "2026-03-15", "distanceKm": 420 },
"preferences": ["food", "scenic"],
"existingStops": [{ "name": "Gas Station A", "type": "fuel" }],
"currency": "EUR"
}Response
{
"suggestions": [{
"name": "Casa Pepe",
"type": "food",
"description": "Traditional tapas bar",
"estimatedCost": 15,
"reasoning": "Along your route, great local reviews",
"lat": 41.65,
"lng": 2.16,
"placeId": "ChIJ..."
}]
}Secrets
LOVABLE_API_KEY, GOOGLE_MAPS_API_KEY
directions
Fetches real driving route from Google Directions API. Returns distance, duration, and polyline for map drawing.
Method
POST
Request Body
{
"origin": "Barcelona, Spain",
"destination": "Skopje, North Macedonia",
"waypoints": [
{ "lat": 41.65, "lng": 2.16 }
]
}Response
{
"totalDistanceKm": 2150,
"totalDurationMinutes": 1280,
"polyline": "encoded_polyline_string",
"legs": [{
"distanceKm": 420,
"durationMinutes": 260,
"startAddress": "Barcelona",
"endAddress": "Marseille"
}]
}Client-Side Utility Functions
generateTrip(setup)src/lib/tripEngine.tsGenerates a Trip object with days, distances, and fuel calculations from setup data.
Returns: Trip
formatDistance(km, units)src/lib/tripEngine.tsFormats distance as "X km" or "X mi" based on unit preference.
Returns: string
formatCost(amount, currency)src/lib/tripEngine.tsFormats a number as currency using Intl.NumberFormat.
Returns: string
getCurrencySymbol(currency)src/types/trip.tsReturns the symbol ($, €, £) for a currency code.
Returns: string