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?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 11513 results for "api"(928ms)

163
164 try {
165 const url = `https://api.github.com/repos/${repo}/pulls/${prNumber}`;
166 console.log("🔍 Sending title update request to:", url);
167
179 });
180
181 console.log("🔍 GitHub API response status:", response.status);
182
183 if (response.ok) {
189 try {
190 const error = await response.json();
191 console.error("❌ GitHub API error:", JSON.stringify(error));
192 errorMessage = error.message || errorMessage;
193 } catch (e) {
194 const errorText = await response.text();
195 console.error("❌ GitHub API error text:", errorText);
196 }
197 return { success: false, message: errorMessage };
198 }
199 } catch (error) {
200 console.error("❌ Exception during API call:", error);
201 return { success: false, message: error.message };
202 }

realtimemain.js5 matches

@emarrefUpdated 8 hours ago
5// ❗❗❗ DO NOT USE YOUR TOKEN IN THE BROWSER FOR PRODUCTION. It should be kept and used server-side.
6const APP_TOKEN = process.env.APP_TOKEN;
7// We'll use this for authentication when making requests to the Calls API.
8const headers = {
9 Authorization: `Bearer ${APP_TOKEN}`,
10};
11const API_BASE = `https://rtc.live.cloudflare.com/v1/apps/${APP_ID}`;
12
13const echoMagic = crypto.randomUUID();
21
22const channel1resp = await fetch(
23 `${API_BASE}/sessions/${session1.sessionId}/datachannels/new`,
24 {
25 method: "POST",
45
46const channel1SubscribeResp = await fetch(
47 `${API_BASE}/sessions/${session2.sessionId}/datachannels/new`,
48 {
49 method: "POST",
136 );
137 const { sessionId, sessionDescription } = await fetch(
138 `${API_BASE}/sessions/new`,
139 {
140 method: "POST",

blob_adminmain.tsx6 matches

@wolfUpdated 9 hours ago
14
15// Public route without authentication
16app.get("/api/public/:id", async (c) => {
17 const key = `__public/${c.req.param("id")}`;
18 const { blob } = await import("https://esm.town/v/std/blob");
132};
133
134app.get("/api/blobs", checkAuth, async (c) => {
135 const prefix = c.req.query("prefix") || "";
136 const limit = parseInt(c.req.query("limit") || "20", 10);
141});
142
143app.get("/api/blob", checkAuth, async (c) => {
144 const key = c.req.query("key");
145 if (!key) return c.text("Missing key parameter", 400);
149});
150
151app.put("/api/blob", checkAuth, async (c) => {
152 const key = c.req.query("key");
153 if (!key) return c.text("Missing key parameter", 400);
158});
159
160app.delete("/api/blob", checkAuth, async (c) => {
161 const key = c.req.query("key");
162 if (!key) return c.text("Missing key parameter", 400);
166});
167
168app.post("/api/blob", checkAuth, async (c) => {
169 const { file, key } = await c.req.parseBody();
170 if (!file || !key) return c.text("Missing file or key", 400);

blob_adminapp.tsx19 matches

@wolfUpdated 9 hours ago
70 const menuRef = useRef(null);
71 const isPublic = blob.key.startsWith("__public/");
72 const publicUrl = isPublic ? `${window.location.origin}/api/public/${encodeURIComponent(blob.key.slice(9))}` : null;
73
74 useEffect(() => {
234 setLoading(true);
235 try {
236 const response = await fetch(`/api/blobs?prefix=${encodeKey(searchPrefix)}&limit=${limit}`);
237 const data = await response.json();
238 setBlobs(data);
261 setBlobContentLoading(true);
262 try {
263 const response = await fetch(`/api/blob?key=${encodeKey(clickedBlob.key)}`);
264 const content = await response.text();
265 setSelectedBlob({ ...clickedBlob, key: decodeKey(clickedBlob.key) });
275 const handleSave = async () => {
276 try {
277 await fetch(`/api/blob?key=${encodeKey(selectedBlob.key)}`, {
278 method: "PUT",
279 body: editContent,
287 const handleDelete = async (key) => {
288 try {
289 await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
290 setBlobs(blobs.filter(b => b.key !== key));
291 if (selectedBlob && selectedBlob.key === key) {
304 const key = `${searchPrefix}${file.name}`;
305 formData.append("key", encodeKey(key));
306 await fetch("/api/blob", { method: "POST", body: formData });
307 const newBlob = { key, size: file.size, lastModified: new Date().toISOString() };
308 setBlobs([newBlob, ...blobs]);
326 try {
327 const fullKey = `${searchPrefix}${key}`;
328 await fetch(`/api/blob?key=${encodeKey(fullKey)}`, {
329 method: "PUT",
330 body: "",
341 const handleDownload = async (key) => {
342 try {
343 const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
344 const blob = await response.blob();
345 const url = window.URL.createObjectURL(blob);
360 if (newKey && newKey !== oldKey) {
361 try {
362 const response = await fetch(`/api/blob?key=${encodeKey(oldKey)}`);
363 const content = await response.blob();
364 await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
365 method: "PUT",
366 body: content,
367 });
368 await fetch(`/api/blob?key=${encodeKey(oldKey)}`, { method: "DELETE" });
369 setBlobs(blobs.map(b => b.key === oldKey ? { ...b, key: newKey } : b));
370 if (selectedBlob && selectedBlob.key === oldKey) {
380 const newKey = `__public/${key}`;
381 try {
382 const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
383 const content = await response.blob();
384 await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
385 method: "PUT",
386 body: content,
387 });
388 await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
389 setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
390 if (selectedBlob && selectedBlob.key === key) {
399 const newKey = key.slice(9); // Remove "__public/" prefix
400 try {
401 const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
402 const content = await response.blob();
403 await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
404 method: "PUT",
405 body: content,
406 });
407 await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
408 setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
409 if (selectedBlob && selectedBlob.key === key) {
554 onClick={() =>
555 copyToClipboard(
556 `${window.location.origin}/api/public/${encodeURIComponent(selectedBlob.key.slice(9))}`,
557 )}
558 className="text-blue-400 hover:text-blue-300 text-sm"
577 >
578 <img
579 src={`/api/blob?key=${encodeKey(selectedBlob.key)}`}
580 alt="Blob content"
581 className="max-w-full h-auto"

TownieHome.tsx5 matches

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

TownieLoginRoute.tsx8 matches

@valdottownUpdated 12 hours ago
8 const { isAuthenticated, authenticate, error } = useAuth();
9 const [tokenValue, setTokenValue] = useState("");
10 const [apiKey, setApiKey] = useState("");
11 // const [invalid, setInvalid] = useState(""); // TODO
12
13 const handleSubmit = (e) => {
14 e.preventDefault();
15 authenticate(tokenValue, apiKey);
16 };
17
36 >
37 <div>
38 <label htmlFor="valtown-token" className="label">Val Town API Token</label>
39 <div style={{ fontSize: "0.8em", color: "#666" }}>
40 <p>
41 <a href="https://www.val.town/settings/api/new" target="_blank" rel="noreferrer">
42 Create a Val Town token here
43 </a>
58 </div>
59 <div>
60 <label htmlFor="anthropic-api-key" className="label">Anthropic API Key (optional)</label>
61 <input
62 type="password"
63 id="anthropic-api-key"
64 name="anthropic-key"
65 value={apiKey}
66 onChange={e => {
67 setApiKey(e.target.value);
68 }}
69 />

telegramBotStartersendTelegramMessage.tsx4 matches

@asdfgUpdated 13 hours ago
1/**
2 * Sends a message to a Telegram chat via the Telegram Bot API
3 * Requires a Telegram Bot token as an environment variable
4 */
10 }
11
12 const telegramApiUrl = `https://api.telegram.org/bot${botToken}/sendMessage`;
13
14 const response = await fetch(telegramApiUrl, {
15 method: 'POST',
16 headers: {
25 if (!response.ok) {
26 const errorBody = await response.text();
27 throw new Error(`Telegram API error: ${response.status} ${errorBody}`);
28 }
29

Towniesend-message.ts6 matches

@valdottownUpdated 13 hours ago
20 }
21
22 const { messages, project, branchId, anthropicApiKey, selectedFiles, images } = await c.req.json();
23 // console.log("Original messages:", JSON.stringify(messages, null, 2));
24 // console.log("Images received:", JSON.stringify(images, null, 2));
25
26 const apiKey = anthropicApiKey || Deno.env.get("ANTHROPIC_API_KEY");
27 const our_api_token = apiKey === Deno.env.get("ANTHROPIC_API_KEY");
28
29 if (our_api_token) {
30 if (await overLimit(bearerToken)) {
31 return Response.json("You have reached the limit of Townie in a 24 hour period.", { status: 403 });
34
35 const anthropic = createAnthropic({
36 apiKey,
37 });
38
159 onFinish: async (result: any) => {
160 await trackUsage({
161 our_api_token,
162 bearerToken, // will look up the userId from this
163 branch_id: branchId,

Townieusage-dashboard.ts3 matches

@valdottownUpdated 13 hours ago
76 SUM(num_images) as total_images
77 FROM ${USAGE_TABLE}
78 WHERE our_api_token = 1
79 GROUP BY user_id, username
80 ORDER BY total_price DESC
256 <th>Finish</th>
257 <th>Images</th>
258 <th>Our API</th>
259 </tr>
260 </thead>
276 <td>${row.finish_reason}</td>
277 <td>${formatNumber(row.num_images)}</td>
278 <td>${formatBoolean(row.our_api_token)}</td>
279 </tr>
280 `).join("")

Townieschema.tsx2 matches

@valdottownUpdated 13 hours ago
17 finish_reason: string;
18 num_images: number;
19 our_api_token: boolean;
20}
21
37 finish_reason TEXT,
38 num_images INTEGER,
39 our_api_token INTEGER NOT NULL
40 )
41 `);

gptApiTemplate2 file matches

@charmaineUpdated 20 hours ago

mod-interview-api1 file match

@twschillerUpdated 1 day ago
apiv1
papimark21