External Content and APIs
Sup patches can interact with external content through both direct fetching and pre-built integrations.
Fetch
You can use sup.fetch() to make HTTP requests to external APIs and websites. This function works similarly to the browser’s fetch API, without the need for async and await.
function main() { const response = sup.fetch("https://api.example.com/data"); const data = response.json(); return data;}POST Requests
function main() { const response = sup.fetch("https://api.example.com/post", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ key: "value" }), }); const result = response.json(); return result;}Working with Different Data Formats
// JSON dataconst jsonData = response.json();
// Text contentconst textContent = response.text();
// Binary dataconst blob = response.blob();
// Audioconst audio = response.audio();
// Videoconst video = response.video();
// Imageconst image = response.image();
// File (returns a SupFile)const file = response.file();Webpages
You can use sup.scrape to extract data from webpages.
function main() { const scrape = sup.scrape( "https://en.wikipedia.org/wiki/Wikipedia:On_this_day/Today", "Summarize the events listed on this page." ); return scrape;}The scrape function takes an optional second argument to provide a prompt for AI processing.
Integrations
Sup provides pre-built integrations for popular services through the sup.ex package. These integrations handle authentication and data formatting for you.
Fal
Fal AI provides fast access to AI models. Use it through sup.ex.fal:
function main() { const result = sup.ex.fal( "fal-ai/fast-sdxl", { prompt: "a smiling pair of cherries", num_inference_steps: 20, }, sup.secret("FAL_KEY") ); return result;}ElevenLabs
ElevenLabs provides high-quality text-to-speech. Use it through sup.ex.elevenlabs:
function main() { const text = sup.input.text; if (!text) return "Please provide text to convert to speech";
// Convert text to speech const audio = sup.ex.elevenlabs( "CJvvY4cO767O6IVtXUG1", text, sup.secret("ELEVENLABS_API_KEY"); );
return audio;}OpenRouter
OpenRouter provides access to multiple AI models including GPT, Claude, and others:
function main() { // Use specific models through OpenRouter const response = sup.ex.openrouter( "anthropic/claude-3-haiku", "Explain quantum computing in simple terms" ); return response;}Hugging Face
Hugging Face provides access to thousands of AI models:
function main() { const response = sup.ex.huggingface( "microsoft/DialoGPT-medium", "What is machine learning?", sup.secret("HUGGINGFACE_API_KEY") ); return response;}Glif
Glif provides access to various AI apps. Use it through sup.ex.glif:
function main() { // Use a Glif endpoint const result = sup.ex.glif( "clxa7m2f80004lkozza8ralld", { "image-input1": sup.input.image }, sup.secret("GLIF_API_KEY") );
return result;}