Val Town Code SearchReturn to Val Town

API Access

You can access search results via JSON API by adding format=json to your query:

https://codesearch.val.run/?q=api&page=278&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=api

Returns an array of strings in format "username" or "username/projectName"

Found 12041 results for "api"(1377ms)

blogTesting001-makingVtCli.md4 matches

@wolfโ€ขUpdated 3 weeks ago
46![](https://wolf-mermelstein-personal-website.s3.us-east-2.amazonaws.com/37c9a2a8-3f0a-4b52-a9c7-cf7c0cc0799b.webp)
47
48Unfortunately `vtfs` no longer works anymore and because of breaking API
49changes, and, while there was work in progress on `vtfs` to add support for val
50town projects, development has paused on the project in favor of `vt`.
175beginning, my plan for this was to implement "git" behavior first (pushing and
176pulling), and then just doing file system watching to add live syncing using
177[Deno.watchFs](https://docs.deno.com/api/deno/~/Deno.watchFs) to handle file
178system events.
179
295
296For `vtfs` I was using
297[Openapi Generator](https://github.com/OpenAPITools/openapi-generator), and it
298turned out that Val Town's OpenAPI specification didn't accept file sizes on the
299order of my tests -- where the response would include the file size, it was an
300integer, not a `format: int64` (long).

wondrousMaroonPeafowlmain.tsx38 matches

@allโ€ขUpdated 3 weeks ago
6import "jsr:@std/dotenv/load"; // needed for deno run; not req for smallweb or valtown
7
8// Function to handle audio transcription using Groq's Whisper API
9export const audioTranscriptionHandler = async (c) => {
10 console.log("๐ŸŽค Audio transcription request received");
20 }
21
22 // Get API key from environment variable
23 const apiKey = Deno.env.get("GROQ_API_KEY");
24 if (!apiKey) {
25 console.error("โŒ Transcription error: Missing API key");
26 return c.json({ error: "API key not configured" }, 500);
27 }
28
49 }
50
51 // Prepare the form data for Groq API
52 const groqFormData = new FormData();
53
64 groqFormData.append("timestamp_granularities[]", "word");
65
66 // Call Groq API
67 console.log("๐ŸŽค Sending request to Groq Whisper API");
68 const start = Date.now();
69 const response = await fetch("https://api.groq.com/openai/v1/audio/transcriptions", {
70 method: "POST",
71 headers: {
72 "Authorization": `Bearer ${apiKey}`,
73 },
74 body: groqFormData,
75 });
76 const elapsed = Date.now() - start;
77 console.log(`๐ŸŽค Groq Whisper API response received in ${elapsed}ms, status: ${response.status}`);
78
79 // Get response content type
96 } else {
97 errorMessage = `Server error: ${response.status} ${response.statusText}`;
98 console.error("โŒ Transcription API error response:", {
99 status: response.status,
100 statusText: response.statusText,
105 }
106 } catch (parseError) {
107 console.error("โŒ Error parsing Groq API response:", parseError);
108 errorMessage = "Failed to parse error response from server";
109 }
110
111 return c.json({
112 error: `Groq API error: ${errorMessage}`,
113 status: response.status,
114 }, response.status);
147 console.log(`๐Ÿ”ต Last user message: "${messages.find(m => m.role === "user")?.content?.substring(0, 50)}..."`);
148
149 const GROQ_API_KEY = Deno.env.get("GROQ_API_KEY");
150 if (!GROQ_API_KEY) {
151 console.error("โŒ Missing GROQ_API_KEY environment variable");
152 return c.json({ error: "GROQ_API_KEY environment variable is not set" }, 500);
153 }
154
155 console.log("๐Ÿ”ต Sending request to Groq API");
156 const start = Date.now();
157 const response = await fetch("https://api.groq.com/openai/v1/chat/completions", {
158 method: "POST",
159 headers: {
160 "Content-Type": "application/json",
161 "Authorization": `Bearer ${GROQ_API_KEY}`,
162 },
163 body: JSON.stringify({
168 });
169 const elapsed = Date.now() - start;
170 console.log(`๐Ÿ”ต Groq API response received in ${elapsed}ms, status: ${response.status}`);
171
172 if (!response.ok) {
173 const errorData = await response.json();
174 console.error("โŒ Chat API error:", errorData);
175 return c.json({ error: "Failed to get chat completion", details: errorData }, response.status);
176 }
203 }
204
205 const apiKey = Deno.env.get("GROQ_API_KEY");
206 if (!apiKey) {
207 console.error("โŒ TTS error: Missing API key");
208 return c.json({ error: "API key not configured" }, 500);
209 }
210
211 console.log("๐Ÿ”Š Sending request to Groq Speech API");
212 const start = Date.now();
213 const response = await fetch("https://api.groq.com/openai/v1/audio/speech", {
214 method: "POST",
215 headers: {
216 "Content-Type": "application/json",
217 "Authorization": `Bearer ${apiKey}`,
218 },
219 body: JSON.stringify({
225 });
226 const elapsed = Date.now() - start;
227 console.log(`๐Ÿ”Š Groq Speech API response received in ${elapsed}ms, status: ${response.status}`);
228
229 if (!response.ok) {
232 const errorData = await response.json();
233 errorMessage = errorData.error?.message || JSON.stringify(errorData);
234 console.error("โŒ TTS API error:", errorData);
235 } catch {
236 errorMessage = `Server error: ${response.status} ${response.statusText}`;
237 console.error("โŒ TTS API non-JSON error:", errorMessage);
238 }
239 return c.json({ error: errorMessage }, response.status);
460 async sendAIRequest() {
461 try {
462 const apiMessages = this.messages.map(({ role, content }) => ({ role, content }));
463 if (apiMessages[0].role === 'system') {
464 apiMessages[0].content = this.chatMode === 'concise'
465 ? 'You are a helpful assistant powered by the Llama-3.3-70b-versatile model. Keep your responses short, concise and conversational. Aim for 1-3 sentences when possible.'
466 : 'You are a helpful assistant powered by the Llama-3.3-70b-versatile model. Respond conversationally and accurately to the user.';
469 method: 'POST',
470 headers: { 'Content-Type': 'application/json' },
471 body: JSON.stringify({ messages: apiMessages })
472 });
473 if (chatResponse.ok) {

stevensDemosendDailyBrief.ts8 matches

@hashbrownโ€ขUpdated 3 weeks ago
97
98export async function sendDailyBriefing(chatId?: string, today?: DateTime) {
99 // Get API keys from environment
100 const apiKey = Deno.env.get("ANTHROPIC_API_KEY");
101 const telegramToken = Deno.env.get("TELEGRAM_TOKEN");
102
106 }
107
108 if (!apiKey) {
109 console.error("Anthropic API key is not configured.");
110 return;
111 }
122
123 // Initialize Anthropic client
124 const anthropic = new Anthropic({ apiKey });
125
126 // Initialize Telegram bot
162
163 // disabled title for now, it seemes unnecessary...
164 // await bot.api.sendMessage(chatId, `*${title}*`, { parse_mode: "Markdown" });
165
166 // Then send the main content
169
170 if (content.length <= MAX_LENGTH) {
171 await bot.api.sendMessage(chatId, content, { parse_mode: "Markdown" });
172 // Store the briefing in chat history
173 await storeChatMessage(
198 // Send each chunk as a separate message and store in chat history
199 for (const chunk of chunks) {
200 await bot.api.sendMessage(chatId, chunk, { parse_mode: "Markdown" });
201 // Store each chunk in chat history
202 await storeChatMessage(

stevensDemoREADME.md1 match

@hashbrownโ€ขUpdated 3 weeks ago
53You'll need to set up some environment variables to make it run.
54
55- `ANTHROPIC_API_KEY` for LLM calls
56- You'll need to follow [these instructions](https://docs.val.town/integrations/telegram/) to make a telegram bot, and set `TELEGRAM_TOKEN`. You'll also need to get a `TELEGRAM_CHAT_ID` in order to have the bot remember chat contents.
57- For the Google Calendar integration you'll need `GOOGLE_CALENDAR_ACCOUNT_ID` and `GOOGLE_CALENDAR_CALENDAR_ID`. See [these instuctions](https://www.val.town/v/stevekrouse/pipedream) for details.

stevensDemoREADME.md5 matches

@hashbrownโ€ขUpdated 3 weeks ago
8## Hono
9
10This app uses [Hono](https://hono.dev/) as the API framework. You can think of Hono as a replacement for [ExpressJS](https://expressjs.com/) that works in serverless environments like Val Town or Cloudflare Workers. If you come from Python or Ruby, Hono is also a lot like [Flask](https://github.com/pallets/flask) or [Sinatra](https://github.com/sinatra/sinatra), respectively.
11
12## Serving assets to the frontend
20### `index.html`
21
22The most complicated part of this backend API is serving index.html. In this app (like most apps) we serve it at the root, ie `GET /`.
23
24We *bootstrap* `index.html` with some initial data from the server, so that it gets dynamically injected JSON data without having to make another round-trip request to the server to get that data on the frontend. This is a common pattern for client-side rendered apps.
25
26## CRUD API Routes
27
28This app has two CRUD API routes: for reading and inserting into the messages table. They both speak JSON, which is standard. They import their functions from `/backend/database/queries.ts`. These routes are called from the React app to refresh and update data.
29
30## Errors
31
32Hono and other API frameworks have a habit of swallowing up Errors. We turn off this default behavior by re-throwing errors, because we think most of the time you'll want to see the full stack trace instead of merely "Internal Server Error". You can customize how you want errors to appear.

stevensDemoNotebookView.tsx5 matches

@hashbrownโ€ขUpdated 3 weeks ago
8import { type Memory } from "../../shared/types.ts";
9
10const API_BASE = "/api/memories";
11const MEMORIES_PER_PAGE = 20;
12
71 setError(null);
72 try {
73 const response = await fetch(API_BASE);
74 if (!response.ok) {
75 throw new Error(`HTTP error! status: ${response.status}`);
100
101 try {
102 const response = await fetch(API_BASE, {
103 method: "POST",
104 headers: { "Content-Type": "application/json" },
123
124 try {
125 const response = await fetch(`${API_BASE}/${id}`, {
126 method: "DELETE",
127 });
155
156 try {
157 const response = await fetch(`${API_BASE}/${editingMemory.id}`, {
158 method: "PUT",
159 headers: { "Content-Type": "application/json" },

stevensDemoindex.ts11 matches

@hashbrownโ€ขUpdated 3 weeks ago
26});
27
28// --- API Routes for Memories ---
29
30// GET /api/memories - Retrieve all memories
31app.get("/api/memories", async (c) => {
32 const memories = await getAllMemories();
33 return c.json(memories);
34});
35
36// POST /api/memories - Create a new memory
37app.post("/api/memories", async (c) => {
38 const body = await c.req.json<Omit<Memory, "id">>();
39 if (!body.text) {
44});
45
46// PUT /api/memories/:id - Update an existing memory
47app.put("/api/memories/:id", async (c) => {
48 const id = c.req.param("id");
49 const body = await c.req.json<Partial<Omit<Memory, "id">>>();
66});
67
68// DELETE /api/memories/:id - Delete a memory
69app.delete("/api/memories/:id", async (c) => {
70 const id = c.req.param("id");
71 try {
83// --- Blob Image Serving Routes ---
84
85// GET /api/images/:filename - Serve images from blob storage
86app.get("/api/images/:filename", async (c) => {
87 const filename = c.req.param("filename");
88

stevensDemoindex.html2 matches

@hashbrownโ€ขUpdated 3 weeks ago
12 type="image/svg+xml"
13 />
14 <link rel="preconnect" href="https://fonts.googleapis.com" />
15 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
16 <link
17 href="https://fonts.googleapis.com/css2?family=Pixelify+Sans:wght@400..700&display=swap"
18 rel="stylesheet"
19 />

stevensDemohandleUSPSEmail.ts5 matches

@hashbrownโ€ขUpdated 3 weeks ago
85 console.log(e.text);
86
87 // Get Anthropic API key from environment
88 const apiKey = Deno.env.get("ANTHROPIC_API_KEY");
89 if (!apiKey) {
90 console.error("Anthropic API key is not configured for this val.");
91 return;
92 }
93
94 // Initialize Anthropic client
95 const anthropic = new Anthropic({ apiKey });
96
97 // Process each image attachment serially

stevensDemohandleTelegramMessage.ts7 matches

@hashbrownโ€ขUpdated 3 weeks ago
92
93/**
94 * Format chat history for Anthropic API
95 */
96function formatChatHistoryForAI(history) {
321bot.on("message", async (ctx) => {
322 try {
323 // Get Anthropic API key from environment
324 const apiKey = Deno.env.get("ANTHROPIC_API_KEY");
325 if (!apiKey) {
326 console.error("Anthropic API key is not configured.");
327 ctx.reply(
328 "I apologize, but I'm not properly configured at the moment. Please inform the household administrator."
332
333 // Initialize Anthropic client
334 const anthropic = new Anthropic({ apiKey });
335
336 // Get message text and user info
502 // Set webhook if it is not set yet
503 if (!isEndpointSet) {
504 await bot.api.setWebhook(req.url, {
505 secret_token: SECRET_TOKEN,
506 });

social_data_api_project3 file matches

@tsuchi_yaโ€ขUpdated 17 hours ago

simple-scrabble-api1 file match

@bryโ€ขUpdated 4 days ago
papimark21
socialdata
Affordable & reliable alternative to Twitter API: โžก๏ธ Access user profiles, tweets, followers & timeline data in real-time โžก๏ธ Monitor profiles with nearly instant alerts for new tweets, follows & profile updates โžก๏ธ Simple integration