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=117&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 13543 results for "api"(904ms)

TowniePreview.tsx1 match

@th3nolo•Updated 4 days ago
86 value={customPath}
87 onChange={handlePathChange}
88 placeholder="Path (e.g., /api/data)"
89 />
90 </div>

TownieLoginRoute.tsx9 matches

@th3nolo•Updated 4 days 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
32 <div>
33 <label htmlFor="valtown-token" className="label">
34 Val Town API Token
35 </label>
36 <div style={{ fontSize: "0.8em", color: "#666" }}>
37 <p>
38 <a
39 href="https://www.val.town/settings/api/new"
40 target="_blank"
41 rel="noreferrer"
60 </div>
61 <div>
62 <label htmlFor="anthropic-api-key" className="label">
63 Anthropic API Key (optional)
64 </label>
65 <input
66 type="password"
67 id="anthropic-api-key"
68 name="anthropic-key"
69 value={apiKey}
70 onChange={(e) => {
71 setApiKey(e.target.value);
72 }}
73 />

Townieindex.ts3 matches

@th3nolo•Updated 4 days ago
41);
42
43// token middleware for API requests
44app.all("/api/*", async (c, next) => {
45 const sessionCookie = getCookie(c, "_session");
46 if (!sessionCookie) {
52});
53
54app.route("/api", backend);
55
56app.get("/frontend/*", (c) => {

Townieindex.ts7 matches

@th3nolo•Updated 4 days ago
1import { basicAuthMiddleware } from "./auth.ts";
2import { handleApiRequest } from "./api/index.ts";
3import { getRequests } from "./api/requests.ts";
4import { getUserSummary } from "./api/user-summary.ts";
5import { getInferenceCalls } from "./api/inference-calls.ts";
6import { renderDashboard } from "./views/dashboard.ts";
7import { renderRequests } from "./views/requests.ts";
22 const path = url.pathname;
23
24 // Handle API requests
25 if (path.startsWith("/api/")) {
26 return handleApiRequest(req);
27 }
28

Townieindex.ts5 matches

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

TownieHome.tsx6 matches

@th3nolo•Updated 4 days ago
38 <ol>
39 <li>
40 Login with your Val Town API token (with projects:read,
41 projects:write, user:read permissions)
42 </li>
77 </div>
78 <h3>Cost Tracking</h3>
79 <p>See estimated API usage costs for each interaction</p>
80 </div>
81 </section>
86 <ul>
87 <li>React frontend with TypeScript</li>
88 <li>Hono API server backend</li>
89 <li>Web Audio API for sound notifications</li>
90 <li>AI SDK for Claude integration</li>
91 </ul>
92 <p>
93 The application proxies requests to the Anthropic API and Val Town
94 API, allowing Claude to view and edit your project files directly.
95 </p>
96 <div>

Townie.cursorrules10 matches

@th3nolo•Updated 4 days 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`

untitled-5701README.md3 matches

@ihrodrigues•Updated 4 days ago
12## Estrutura do Projeto
13
14- `/backend`: API e lógica do servidor
15 - `/database`: Configuração e consultas do banco de dados
16 - `/routes`: Rotas da API
17- `/frontend`: Interface do usuário
18 - `/components`: Componentes da interface
21## Tecnologias
22
23- Backend: Hono (framework API), SQLite (banco de dados)
24- Frontend: HTML, JavaScript, TailwindCSS
25- Compartilhado: TypeScript para tipagem

gordwameREADME.md1 match

@alexwein•Updated 5 days ago
21### make boardstrings work with urls
22
23- [x] add an api route "/play/:boardstring" to backend/index.js
24- [x] validate that the boardstring:
25 - [x] only contains letters of the alphabet

posthog-proxyhenry.posthogProxy.ts3 matches

@henrywilliams•Updated 5 days ago
9const POSTHOG_HOST = Deno.env.get("POSTHOG_HOST") ?? "https://app.posthog.com";
10const POSTHOG_PROJECT_ID = Deno.env.get("POSTHOG_PROJECT_ID")!;
11const POSTHOG_API_KEY = Deno.env.get("POSTHOG_API_KEY")!;
12
13/* ───── constants ───── */
95 try {
96 const upstream = await fetch(
97 `${POSTHOG_HOST}/api/projects/${POSTHOG_PROJECT_ID}/query/`,
98 {
99 method: "POST",
100 headers: {
101 "Authorization": `Bearer ${POSTHOG_API_KEY}`,
102 "Content-Type": "application/json",
103 },

create-val-api-demo1 file match

@shouser•Updated 3 hours ago

new-val-api-demo

@shouser•Updated 4 hours ago
This is an example of using the API to create a val.
snartapi
Kapil01