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/image-url.jpg%20%22Optional%20title%22?q=api&page=132&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 25377 results for "api"(5584ms)

weekly-schedtypes.ts2 matches

@jeffroche•Updated 2 weeks ago
28}
29
30// API response types
31export interface ApiResponse<T> {
32 success: boolean;
33 data?: T;

stevensDemohandleTelegramMessage.ts7 matches

@jokecamp•Updated 2 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 });

stevensDemogetWeather.ts5 matches

@jokecamp•Updated 2 weeks ago
27async function generateConciseWeatherSummary(weatherDay) {
28 try {
29 // Get API key from environment
30 const apiKey = Deno.env.get("ANTHROPIC_API_KEY");
31 if (!apiKey) {
32 console.error("Anthropic API key is not configured.");
33 return null;
34 }
35
36 // Initialize Anthropic client
37 const anthropic = new Anthropic({ apiKey });
38
39 const response = await anthropic.messages.create({

hello-realtime-projectutils.ts8 matches

@charmaine•Updated 2 weeks ago
1const MODEL = "gpt-realtime";
2const INSTRUCTIONS = `
3 Greet the user in English, and thank them for trying the new OpenAI Realtime API.
4 Give them a brief summary based on the list below, and then ask if they have any questions.
5 Answer questions using the information below. For questions outside this scope,
7 ---
8 Short summary:
9 - The Realtime API is now generally available, and has improved instruction following, voice naturalness, and audio quality.
10 There are two new voices and it's easier to develop for. There's also a new telephony integration for phone scenarios.
11 Full list of improvements:
16 - higher audio quality
17 - improved handling of alphanumerics (eg, properly understanding credit card and phone numbers)
18 - support for the OpenAI Prompts API
19 - support for MCP-based tools
20 - auto-truncation to reduce context size
21 - native telephony support, making it simple to connect voice calls to existing Realtime API applications
22 - when using WebRTC, you can connect without needing an ephemeral token
23 - when using WebRTC, you can now control sessions (including tool calls) from the server
27const VOICE = "marin";
28
29const OPENAI_API_KEY = Deno.env.get("OPENAI_API_KEY");
30if (!OPENAI_API_KEY) {
31 throw new Error("🔴 OpenAI API key not configured");
32}
33
34export function makeHeaders(contentType?: string) {
35 const obj: Record<string, string> = {
36 Authorization: `Bearer ${OPENAI_API_KEY}`,
37 };
38 if (contentType) obj["Content-Type"] = contentType;

hello-realtime-projectsip.ts1 match

@charmaine•Updated 2 weeks ago
27
28 // Accept the call.
29 const url = `https://api.openai.com/v1/realtime/calls/${callId}/accept`;
30 const headers = makeHeaders("application/json");
31 const body = JSON.stringify(makeSession());

hello-realtime-projectrtc.ts1 match

@charmaine•Updated 2 weeks ago
7rtc.post("/", async (c) => {
8 // Create the call.
9 const url = "https://api.openai.com/v1/realtime/calls";
10 const headers = makeHeaders();
11 const fd = new FormData();

hello-realtime-projectREADME.md2 matches

@charmaine•Updated 2 weeks ago
4You can access the app via WebRTC at https://hello-realtime.val.run, or via SIP by calling 425-800-0042.
5
6This demo shows off the new SIP API, the new all-in-one WebRTC API, and the new server-side websocket interface.
7
8If you remix the app, you'll just need to pop in your own OPENAI_API_KEY (from platform.openai.com), and also the OPENAI_SIGNING_SECRET if you want to use the SIP interface.

hello-realtime-projectobserver.ts1 match

@charmaine•Updated 2 weeks ago
8observer.post("/:callId", async (c) => {
9 const callId = c.req.param("callId");
10 const url = `wss://api.openai.com/v1/realtime?call_id=${callId}`;
11 const ws = new WebSocket(url, { headers: makeHeaders() });
12 ws.on("open", () => {

hello-realtime-projectindex.html1 match

@charmaine•Updated 2 weeks ago
4 <meta charset="utf-8" />
5 <meta name="viewport" content="width=device-width, initial-scale=1" />
6 <title>OpenAI Realtime API Voice Agent</title>
7 <style>
8 :root {

mailcheckmain.js39 matches

@yawnxyz•Updated 2 weeks ago
7
8const app = new Hono();
9const serverApiKey = null; // Deno.env.get("GROQ_API_KEY");
10
11// Settings configuration (minimal)
35}
36
37async function runAsyncJob(job, apiKey, concurrency) {
38 if (!Array.isArray(job.items) || job.items.length === 0) { job.running = false; job.updatedAt = nowTs(); return; }
39 job.running = true; job.cancelled = false; job.updatedAt = nowTs();
61 if (item.status === 'done' || item.status === 'error') { job.completed++; return runNext(); }
62 try {
63 const res = await backgroundAssessEmail(apiKey, item.email, systemPrompt);
64 item.result = res;
65 item.status = 'done';
135 }
136}
137function logGroqCurl(tag, apiKey, payload) {
138 try {
139 const compact = JSON.stringify(payload);
141 const curl = [
142 'curl --request POST \\\n' +
143 ' --url https://api.groq.com/openai/v1/chat/completions \\\n' +
144 ` --header 'authorization: Bearer ${apiKey}' \\\n` +
145 " --header 'content-type: application/json' \\\n" +
146 ` --data '${esc}'`
281// Convert a plain-text analysis (Status/Message/Explanation/Evidence sections) into strict JSON
282// Schema: { status: 'person_high|person_low|person_none|spam', message: string, explanation_short: string, evidence: string[] }
283async function convertAnalysisToJson(apiKey, email, analysisText) {
284 try {
285 const convModel = 'openai/gpt-oss-20b';
298 ];
299 const convPayload = { model: convModel, messages: convMessages, stream: false, temperature: 0, response_format: { type: 'json_object' }, tool_choice: 'none' };
300 const convRes = await groqChatCompletion(apiKey, convPayload);
301 const t2 = convRes?.choices?.[0]?.message?.content || '';
302 try { return JSON.parse(t2); } catch (_) { return null; }
305 }
306}
307async function llmCompoundAssess(apiKey, email, systemPrompt) {
308 const baseSystem = [
309 'You assess whether an email belongs to a real person. Perform targeted web checks. If you cannot browse, reason only from public patterns in the address and provider; do not fabricate.',
331 const model = 'compound-beta';
332 const compoundPayload1 = { model, messages, stream: false, temperature: 0.2, tool_choice: 'none' };
333 const r1 = await groqChatCompletion(apiKey, compoundPayload1);
334 // logGroqCurl('compound r1', apiKey, compoundPayload1);
335 // try { console.log('>> [compound] r1:', JSON.stringify(r1)); } catch (_) {}
336 const t1 = r1?.choices?.[0]?.message?.content || '';
350 ];
351 const payload2 = { model, messages: messagesJson, stream: false, temperature: 0.2, response_format: { type: 'json_object' }, tool_choice: 'none' };
352 // logGroqCurl('compound r2', apiKey, payload2);
353 const r2 = await groqChatCompletion(apiKey, payload2);
354 try { console.log('>> [compound] r2:', JSON.stringify(r2)); } catch (_) {}
355 const t2 = r2?.choices?.[0]?.message?.content || '';
418
419// Browser search assessor using Groq's browser_search tool
420async function browserSearchAssess(apiKey, email, systemPrompt) {
421 const baseSystem = [
422 'Use web browsing to gather public signals about whether this email belongs to a real person; do not fabricate.',
439 const model = 'openai/gpt-oss-20b';
440 const payload = { model, messages, stream: false, temperature: 0.2, tools: [{ type: 'browser_search' }] };
441 const r1 = await groqChatCompletion(apiKey, payload);
442 logGroqCurl('browser r1', apiKey, payload);
443 // try { console.log('>> [browser] r1:', JSON.stringify(r1)); } catch (_) {}
444 const t1 = r1?.choices?.[0]?.message?.content || '';
445 const out = { fields: { bg_browser_model: model } };
446 // Second pass: convert the plain-text analysis to strict JSON
447 let parsed = await convertAnalysisToJson(apiKey, email, t1);
448
449 if (!parsed) {
487
488// Final judge to consolidate all signals
489async function finalJudgeAssess(apiKey, email, systemPrompt, evidence) {
490 console.log('>> [final judge] evidence:', email, JSON.stringify(evidence));
491 const model = 'openai/gpt-oss-120b';
512 // Ask for json_object to avoid extra parsing
513 const judgePayload = { model, messages: [ { role: 'system', content: sys + (systemPrompt ? ('\nExtra: ' + systemPrompt) : '') }, { role: 'user', content: user } ], stream: false, temperature: 0.2, response_format: { type: 'json_object' } };
514 // logGroqCurl('judge', apiKey, judgePayload);
515 const r = await groqChatCompletion(apiKey, judgePayload);
516 // try { console.log('>> [judge] r:', JSON.stringify(r)); } catch (_) {}
517 let parsed = null;
570
571
572// Check if server has API key
573app.get('/api/check-key', (c) => {
574 return c.json({ hasServerKey: !!serverApiKey });
575});
576
628
629// Academic email check (server-side; uses npm:academic-email-verifier)
630// Removed standalone academic check endpoint; academic is part of /api/check/background
631
632// Background check endpoint: runs sequential checkers server-side
633app.post('/api/check/background', async (c) => {
634 try {
635 const body = await c.req.json().catch(() => ({}));
638 const whitelist = Array.isArray(body?.whitelist) ? body.whitelist : [];
639 const blacklist = Array.isArray(body?.blacklist) ? body.blacklist : [];
640 // Prefer Authorization: Bearer <key> header, then body.userApiKey, then env
641 const authHeader = c.req.header('Authorization') || c.req.header('authorization') || '';
642 const m = authHeader.match(/^Bearer\s+(.+)$/i);
643 const headerKey = m ? m[1].trim() : '';
644 const apiKey = serverApiKey || headerKey || body?.userApiKey || Deno.env.get("GROQ_API_KEY");
645 if (!apiKey) return c.json({ error: 'No Groq API key available.' }, 400);
646 if (!email) return c.json({ error: 'email required' }, 400);
647 const out = await backgroundAssessEmail(apiKey, email, systemPrompt, whitelist, blacklist);
648 // try { console.log('>> [/api/check/background] result:', JSON.stringify(out)); } catch (_) {}
649 return c.json(out);
650 } catch (error) {
654});
655
656// Async job APIs
657// Create a job with one or more items. Body: { items: string[] | { email }[], systemPrompt?, concurrency?, userApiKey? }
658app.post('/api/jobs', async (c) => {
659 try {
660 const body = await c.req.json().catch(() => ({}));
665 const m = authHeader.match(/^Bearer\s+(.+)$/i);
666 const headerKey = m ? m[1].trim() : '';
667 const apiKey = serverApiKey || headerKey || body?.userApiKey || Deno.env.get("GROQ_API_KEY");
668 if (!apiKey) return c.json({ error: 'No Groq API key available.' }, 400);
669 // Normalize items to { id, email, status }
670 items = items.map((v) => {
676 jobRegistry.set(job.id, job);
677 // fire and forget
678 runAsyncJob(job, apiKey, concurrency);
679 return c.json(summarizeJob(job));
680 } catch (error) {
685
686// Get job status by id
687app.get('/api/jobs/:id', (c) => {
688 try {
689 const id = c.req.param('id');
698
699// Cancel a job by id
700app.post('/api/jobs/:id/cancel', (c) => {
701 try {
702 const id = c.req.param('id');
715// LLM-based email legitimacy checker
716// Asks the model to return JSON wrapped in <json>...</json> tags; retries with JSON modes if needed
717// Removed standalone llm-email endpoint; compound is part of /api/check/background
718
719export default (typeof Deno !== "undefined" && Deno.env.get("valtown")) ? app.fetch : app;

todoist-api

@scottscharl•Updated 17 hours ago

elevenLabsDialogueTester2 file matches

@dcm31•Updated 1 day ago
Public tester for ElevenLabs text-to-dialogue API
fapian
<("<) <(")> (>")>
Kapil01