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//%22$%7BvalTownUrl%7D/%22?q=api&page=3&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 25434 results for "api"(1055ms)

TownieREADME.md12 matches

@Skywalker•Updated 2 hours ago
1# Usage Dashboard
2
3A dashboard for monitoring API usage and inference calls.
4
5## Features
20 index.ts # Main entry point and routing
21 auth.ts # Authentication logic
22 /api/
23 index.ts # API request handler
24 requests.ts # API endpoints for requests data
25 inference-calls.ts # API endpoints for inference calls
26 user-summary.ts # API endpoints for user summary data
27 /views/
28 layout.ts # Common layout template
54 - Links back to the associated request
55
56### API Endpoints
57
58- `/api/requests` - Get paginated requests
59- `/api/requests?usage_id=123` - Get a specific request
60- `/api/inference-calls` - Get paginated inference calls
61- `/api/inference-calls?usage_id=123` - Get inference calls for a specific request
62- `/api/user-summary` - Get user summary data
63
64## Debugging

Towniequeries.tsx4 matches

@Skywalker•Updated 2 hours ago
157 branch_id,
158 model,
159 our_api_token,
160 num_images,
161 tablePrefix = "",
165 branch_id: string;
166 model: string;
167 our_api_token: boolean;
168 num_images: number;
169 tablePrefix?: string;
178 branch_id,
179 model,
180 our_api_token,
181 num_images
182 ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
189 branch_id,
190 model,
191 our_api_token ? 1 : 0,
192 num_images,
193 ],

Towniequeries_test.tsx1 match

@Skywalker•Updated 2 hours ago
38 branch_id,
39 model,
40 our_api_token,
41 num_images
42 ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)

Towniepurchase-credits.ts6 matches

@Skywalker•Updated 2 hours ago
14const stripe = stripeSecretKey
15 ? new Stripe(stripeSecretKey, {
16 apiVersion: "2024-04-10",
17 })
18 : null;
57 // user_id: user.id,
58 // username: user.username,
59 // purchase_source: source || "api", // e.g., "insufficient_credits", "settings_page"
60 // },
61 // description: `Townie credits purchase - $${amount} for ${user.username}`,
62 // api_key: stripeSecretKey,
63 // });
64
69 "metadata[user_id]": user.id,
70 "metadata[username]": user.username,
71 "metadata[purchase_source]": source || "api",
72 description: `Townie credits purchase - $${amount} for ${user.username}`,
73 });
74
75 const response = await fetch("https://api.stripe.com/v1/payment_intents", {
76 method: "POST",
77 headers: {
84 const paymentIntent = await response.json();
85 if (!response.ok) {
86 throw new Error(`Stripe API error: ${paymentIntent.error?.message || "Unknown error"}`);
87 }
88

TowniePurchaseCreditsRoute.tsx2 matches

@Skywalker•Updated 2 hours ago
15 const fetchBalance = async () => {
16 try {
17 const response = await fetch("/api/credit-balance");
18 if (response.ok) {
19 const data = await response.json();
35
36 try {
37 const response = await fetch("/api/purchase-credits", {
38 method: "POST",
39 headers: { "Content-Type": "application/json" },

Townieindex.ts4 matches

@Skywalker•Updated 2 hours ago
49app.get("/shared/*", (c) => serveFile(c.req.path, import.meta.url));
50
51// token middleware for API requests
52app.all("/api/*", async (c, next) => {
53 if (c.req.path === "/api/stripe-webhook") {
54 return next();
55 }
63});
64
65app.route("/api", backend);
66
67app.get("/favicon.svg", (c) => {

Townieindex.ts9 matches

@Skywalker•Updated 2 hours ago
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { getCreditAdditions } from "./api/credit-additions.ts";
3import { handleApiRequest } from "./api/index.ts";
4import { getInferenceCalls } from "./api/inference-calls.ts";
5import {
6 getInferenceCallsForRequest,
8 getRequestById,
9 getRequests,
10} from "./api/requests.ts";
11import { getUserSummary } from "./api/user-summary.ts";
12import { getValSummary } from "./api/val-summary.ts";
13import { basicAuthMiddleware } from "./auth.ts";
14import { renderCreditAdditions } from "./views/credit-additions.ts";
31});
32
33// API routes
34app.all("/api/*", async (c) => {
35 return handleApiRequest(c.req.raw);
36});
37

Townieindex.ts5 matches

@Skywalker•Updated 2 hours ago
5
6/**
7 * Handle API requests
8 */
9export async function handleApiRequest(req: Request): Promise<Response> {
10 const url = new URL(req.url);
11 const path = url.pathname.replace("/api/", "");
12
13 try {
14 // Route to the appropriate API handler
15 if (path === "requests") {
16 const usageId = url.searchParams.get("usage_id");
67 }
68 } catch (error) {
69 console.error("API error:", error);
70 return new Response(JSON.stringify({ error: error.message }), {
71 status: 500,

TownieHome.tsx5 matches

@Skywalker•Updated 2 hours ago
41 <ol>
42 <li>
43 Login with your Val Town API token (with projects:read, projects:write, user:read permissions)
44 </li>
45 <li>Select a project to work on</li>
79 </div>
80 <h3>Cost Tracking</h3>
81 <p>See estimated API usage costs for each interaction</p>
82 </div>
83 </section>
88 <ul>
89 <li>React frontend with TypeScript</li>
90 <li>Hono API server backend</li>
91 <li>Web Audio API for sound notifications</li>
92 <li>AI SDK for Claude integration</li>
93 </ul>
94 <p>
95 The application proxies requests to the Anthropic API and Val Town API, allowing Claude to view and edit your
96 project files directly.
97 </p>

Townie.cursorrules10 matches

@Skywalker•Updated 2 hours ago
13- Generate code in TypeScript or TSX
14- Add appropriate TypeScript types and interfaces for all data structures
15- Prefer official SDKs or libraries than writing API calls directly
16- Ask the user to supply API or library documentation if you are at all unsure about it
17- **Never bake in secrets into the code** - always use environment variables
18- Include comments explaining complex logic (avoid commenting obvious operations)
23### 1. HTTP Trigger
24
25- Create web APIs and endpoints
26- Handle HTTP requests and responses
27- Example structure:
173However, it's *extremely importing* to note that `parseProject` and other Standard Library utilities ONLY RUN ON THE SERVER.
174If you need access to this data on the client, run it in the server and pass it to the client by splicing it into the HTML page
175or by making an API request for it.
176
177## Val Town Platform Specifics
181- **AI Image:** To inline generate an AI image use: `<img src="https://maxm-imggenurl.web.val.run/the-description-of-your-image" />`
182- **Storage:** DO NOT use the Deno KV module for storage
183- **Browser APIs:** DO NOT use the `alert()`, `prompt()`, or `confirm()` methods
184- **Weather Data:** Use open-meteo for weather data (doesn't require API keys) unless otherwise specified
185- **View Source:** Add a view source link by importing & using `import.meta.url.replace("ems.sh", "val.town)"` (or passing this data to the client) and include `target="_top"` attribute
186- **Error Debugging:** Add `<script src="https://esm.town/v/std/catch"></script>` to HTML to capture client-side errors
187- **Error Handling:** Only use try...catch when there's a clear local resolution; Avoid catches that merely log or return 500s. Let errors bubble up with full context
188- **Environment Variables:** Use `Deno.env.get('keyname')` when you need to, but generally prefer APIs that don't require keys
189- **Imports:** Use `https://esm.sh` for npm and Deno dependencies to ensure compatibility on server and browser
190- **Storage Strategy:** Only use backend storage if explicitly required; prefer simple static client-side sites
224### Backend (Hono) Best Practices
225
226- Hono is the recommended API framework
227- Main entry point should be `backend/index.ts`
228- **Static asset serving:** Use the utility functions to read and serve project files:
248 });
249 ```
250- Create RESTful API routes for CRUD operations
251- Always include this snippet at the top-level Hono app to re-throwing errors to see full stack traces:
252 ```ts
285 - For files in the project, use `readFile` helpers
286
2875. **API Design:**
288 - `fetch` handler is the entry point for HTTP vals
289 - Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`

PixelPixelApiMonitor1 file match

@selfire1•Updated 10 hours ago
Regularly polls the API and messages on an error.

weatherApp1 file match

@dcm31•Updated 16 hours ago
A simple weather app with dropdown cities using Open-Meteo API
fapian
<("<) <(")> (>")>
Kapil01