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/$%7Bsuccess?q=api&page=1527&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 20548 results for "api"(4354ms)

survivalRPGAdventuremain.tsx1 match

@ayehUpdated 5 months ago
164 injury_risk: state.injury_risk + 60,
165 }),
166 narrative: "You wade into the freezing, rapid river. The fishing is dangerous, but potentially rewarding.",
167 },
168 {

zanyCyanHookwormmain.tsx33 matches

@nvpkpUpdated 5 months ago
10
11const WikiSearch = () => {
12 const [apiKey, setApiKey] = useState("");
13 const [model, setModel] = useState("claude-3-opus-20240229");
14 const [query, setQuery] = useState("");
30
31 useEffect(() => {
32 const savedApiKey = localStorage.getItem("anthropic_api_key");
33 const savedModel = localStorage.getItem("anthropic_model");
34
35 if (savedApiKey) {
36 setApiKey(savedApiKey);
37 setStatus({ message: "API key loaded", type: "success" });
38 }
39 if (savedModel) {
53 };
54
55 const saveApiSettings = (e) => {
56 e.preventDefault();
57 if (apiKey.trim()) {
58 localStorage.setItem("anthropic_api_key", apiKey);
59 localStorage.setItem("anthropic_model", model);
60 setStatus({ message: "API settings saved successfully", type: "success" });
61 setIsConfigOpen(false);
62 } else {
63 setStatus({ message: "Please enter an API key", type: "error" });
64 }
65 };
66
67 const callAnthropicAPI = async (prompt) => {
68 const response = await fetch("https://api.anthropic.com/v1/messages", {
69 method: "POST",
70 headers: {
71 "Content-Type": "application/json",
72 "x-api-key": apiKey,
73 "anthropic-version": "2023-06-01",
74 },
82 if (!response.ok) {
83 const error = await response.text();
84 throw new Error(`API Error: ${error}`);
85 }
86
90
91 const searchWikipedia = async (searchQuery, language = "en") => {
92 const apiUrl = `https://${language}.wikipedia.org/w/api.php`;
93 const params = new URLSearchParams({
94 action: "query",
101 });
102
103 const response = await fetch(`${apiUrl}?${params}`);
104 const data = await response.json();
105 const pages = data.query.pages;
111 e.preventDefault();
112
113 if (!apiKey) {
114 setStatus({ message: "Please configure your API key first", type: "error" });
115 setIsConfigOpen(true);
116 return;
124 const language = detectLanguage(query);
125
126 const suggestion = await callAnthropicAPI(
127 `Based on this question: "${query}", tell me exactly what Wikipedia article I should look up. Respond with just the article title, nothing else.`,
128 );
132 setResults(prev => ({ ...prev, wikiExtract }));
133
134 const finalAnswer = await callAnthropicAPI(
135 `Question: "${query}"
136 Wikipedia excerpt: "${wikiExtract}"
153 {/* Header */}
154 <div className="bg-gradient-to-r from-blue-600 to-blue-700 p-6 text-white">
155 <h1 className="text-2xl md:text-3xl font-bold">Wikipedia Search with Anthropic API</h1>
156 <div className="mt-2 flex items-center gap-2 text-sm text-blue-100">
157 <span className="text-base">{Icons.Settings}</span>
158 <span>Using: {modelNames[model]}</span>
159 {!apiKey && (
160 <span className="bg-red-500/20 text-white px-2 py-0.5 rounded-full text-xs">(API key required)</span>
161 )}
162 </div>
165 {/* Main content */}
166 <div className="p-6 space-y-6">
167 {/* API Configuration */}
168 <div className="space-y-2">
169 <button
174 <span className="font-medium flex items-center gap-2">
175 <span className="text-blue-600">{Icons.Settings}</span>
176 API Configuration
177 </span>
178 <span className="text-gray-500">{isConfigOpen ? Icons.ChevronUp : Icons.ChevronDown}</span>
181 {isConfigOpen && (
182 <div className="p-4 bg-gray-50 rounded-lg border border-gray-200">
183 <form onSubmit={saveApiSettings} className="space-y-4">
184 <div>
185 <label htmlFor="apiKey" className="block text-sm font-medium text-gray-700 mb-1">
186 Anthropic API Key:
187 </label>
188 <input
189 type="password"
190 id="apiKey"
191 value={apiKey}
192 onChange={(e) => setApiKey(e.target.value)}
193 className="w-full p-2.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
194 placeholder="Enter your Anthropic API key"
195 />
196 </div>
218 className="w-full bg-blue-600 text-white px-4 py-2.5 rounded-lg hover:bg-blue-700 transition-colors"
219 >
220 Save API Settings
221 </button>
222 </form>

unassumingAzureLungfishREADME.md2 matches

@JohnerUpdated 5 months ago
6
71. Sign up for [Cerebras](https://cloud.cerebras.ai/)
82. Get a Cerebras API Key
93. Save it in a [Val Town environment variable](https://www.val.town/settings/environment-variables) called `CEREBRAS_API_KEY`
10
11# Todos

unassumingAzureLungfishmain.tsx5 matches

@JohnerUpdated 5 months ago
212 } catch (error) {
213 Toastify({
214 text: "We may have hit our Cerebras Usage limits. Try again later or fork this and use your own API key.",
215 position: "center",
216 duration: 3000,
1024 };
1025 } else {
1026 const client = new Cerebras({ apiKey: Deno.env.get("CEREBRAS_API_KEY") });
1027 const completion = await client.chat.completions.create({
1028 messages: [
1149 <meta name="viewport" content="width=device-width, initial-scale=1.0">
1150 <title>CerebrasCoder</title>
1151 <link rel="preconnect" href="https://fonts.googleapis.com" />
1152 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
1153 <link
1154 href="https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,300;0,400;0,500;1,300;1,400;1,500&family=DM+Sans:ital,opsz,wght@0,9..40,100..1000;1,9..40,100..1000&display=swap"
1155 rel="stylesheet"
1156 />
1165 <meta property="og:description" content="Turn your ideas into fully functional apps in less than a second – powered by Llama3.3-70b on Cerebras's super-fast wafer chips. Code is 100% open-source, hosted on Val Town."">
1166 <meta property="og:type" content="website">
1167 <meta property="og:image" content="https://stevekrouse-blob_admin.web.val.run/api/public/CerebrasCoderOG.jpg">
1168
1169

cheerfulTurquoiseAnacondamain.tsx1 match

@amine0077Updated 5 months ago
12 },
13 {
14 prompt: "weather dashboard for nyc using open-meteo API for NYC with icons",
15 title: "Weather App",
16 code:

fascinatingBrownKrillREADME.md2 matches

@amine0077Updated 5 months ago
6
71. Sign up for [Cerebras](https://cloud.cerebras.ai/)
82. Get a Cerebras API Key
93. Save it in a [Val Town environment variable](https://www.val.town/settings/environment-variables) called `CEREBRAS_API_KEY`
10
11# Todos

fascinatingBrownKrillmain.tsx5 matches

@amine0077Updated 5 months ago
212 } catch (error) {
213 Toastify({
214 text: "We may have hit our Cerebras Usage limits. Try again later or fork this and use your own API key.",
215 position: "center",
216 duration: 3000,
1024 };
1025 } else {
1026 const client = new Cerebras({ apiKey: Deno.env.get("CEREBRAS_API_KEY") });
1027 const completion = await client.chat.completions.create({
1028 messages: [
1149 <meta name="viewport" content="width=device-width, initial-scale=1.0">
1150 <title>CerebrasCoder</title>
1151 <link rel="preconnect" href="https://fonts.googleapis.com" />
1152 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
1153 <link
1154 href="https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,300;0,400;0,500;1,300;1,400;1,500&family=DM+Sans:ital,opsz,wght@0,9..40,100..1000;1,9..40,100..1000&display=swap"
1155 rel="stylesheet"
1156 />
1165 <meta property="og:description" content="Turn your ideas into fully functional apps in less than a second – powered by Llama3.3-70b on Cerebras's super-fast wafer chips. Code is 100% open-source, hosted on Val Town."">
1166 <meta property="og:type" content="website">
1167 <meta property="og:image" content="https://stevekrouse-blob_admin.web.val.run/api/public/CerebrasCoderOG.jpg">
1168
1169

blob_adminmain.tsx25 matches

@dave_smithUpdated 5 months ago
73 const menuRef = useRef(null);
74 const isPublic = blob.key.startsWith("__public/");
75 const publicUrl = isPublic ? `${window.location.origin}/api/public/${encodeURIComponent(blob.key.slice(9))}` : null;
76
77 useEffect(() => {
237 setLoading(true);
238 try {
239 const response = await fetch(`/api/blobs?prefix=${encodeKey(searchPrefix)}&limit=${limit}`);
240 const data = await response.json();
241 setBlobs(data);
264 setBlobContentLoading(true);
265 try {
266 const response = await fetch(`/api/blob?key=${encodeKey(clickedBlob.key)}`);
267 const content = await response.text();
268 setSelectedBlob({ ...clickedBlob, key: decodeKey(clickedBlob.key) });
278 const handleSave = async () => {
279 try {
280 await fetch(`/api/blob?key=${encodeKey(selectedBlob.key)}`, {
281 method: "PUT",
282 body: editContent,
290 const handleDelete = async (key) => {
291 try {
292 await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
293 setBlobs(blobs.filter(b => b.key !== key));
294 if (selectedBlob && selectedBlob.key === key) {
307 const key = `${searchPrefix}${file.name}`;
308 formData.append("key", encodeKey(key));
309 await fetch("/api/blob", { method: "POST", body: formData });
310 const newBlob = { key, size: file.size, lastModified: new Date().toISOString() };
311 setBlobs([newBlob, ...blobs]);
329 try {
330 const fullKey = `${searchPrefix}${key}`;
331 await fetch(`/api/blob?key=${encodeKey(fullKey)}`, {
332 method: "PUT",
333 body: "",
344 const handleDownload = async (key) => {
345 try {
346 const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
347 const blob = await response.blob();
348 const url = window.URL.createObjectURL(blob);
363 if (newKey && newKey !== oldKey) {
364 try {
365 const response = await fetch(`/api/blob?key=${encodeKey(oldKey)}`);
366 const content = await response.blob();
367 await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
368 method: "PUT",
369 body: content,
370 });
371 await fetch(`/api/blob?key=${encodeKey(oldKey)}`, { method: "DELETE" });
372 setBlobs(blobs.map(b => b.key === oldKey ? { ...b, key: newKey } : b));
373 if (selectedBlob && selectedBlob.key === oldKey) {
383 const newKey = `__public/${key}`;
384 try {
385 const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
386 const content = await response.blob();
387 await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
388 method: "PUT",
389 body: content,
390 });
391 await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
392 setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
393 if (selectedBlob && selectedBlob.key === key) {
402 const newKey = key.slice(9); // Remove "__public/" prefix
403 try {
404 const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
405 const content = await response.blob();
406 await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
407 method: "PUT",
408 body: content,
409 });
410 await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
411 setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
412 if (selectedBlob && selectedBlob.key === key) {
557 onClick={() =>
558 copyToClipboard(
559 `${window.location.origin}/api/public/${encodeURIComponent(selectedBlob.key.slice(9))}`,
560 )}
561 className="text-blue-400 hover:text-blue-300 text-sm"
580 >
581 <img
582 src={`/api/blob?key=${encodeKey(selectedBlob.key)}`}
583 alt="Blob content"
584 className="max-w-full h-auto"
660
661// Public route without authentication
662app.get("/api/public/:id", async (c) => {
663 const key = `__public/${c.req.param("id")}`;
664 const { blob } = await import("https://esm.town/v/std/blob");
766};
767
768app.get("/api/blobs", checkAuth, async (c) => {
769 const prefix = c.req.query("prefix") || "";
770 const limit = parseInt(c.req.query("limit") || "20", 10);
775});
776
777app.get("/api/blob", checkAuth, async (c) => {
778 const key = c.req.query("key");
779 if (!key) return c.text("Missing key parameter", 400);
783});
784
785app.put("/api/blob", checkAuth, async (c) => {
786 const key = c.req.query("key");
787 if (!key) return c.text("Missing key parameter", 400);
792});
793
794app.delete("/api/blob", checkAuth, async (c) => {
795 const key = c.req.query("key");
796 if (!key) return c.text("Missing key parameter", 400);
800});
801
802app.post("/api/blob", checkAuth, async (c) => {
803 const { file, key } = await c.req.parseBody();
804 if (!file || !key) return c.text("Missing file or key", 400);

compassionateBlackCatfishmain.tsx14 matches

@gigmxUpdated 5 months ago
2
3export default async function(req: Request): Promise<Response> {
4 const LEPTON_API_TOKEN = Deno.env.get('LEPTON_API_TOKEN') || '';
5
6 return new Response(
33 <div id="connection-status" class="absolute top-0 left-0 right-0 text-center z-50 hidden">
34 <div class="bg-red-900 text-red-300 p-2 text-sm">
35 ⚠️ NETWORK DISRUPTION: API CONNECTION LOST
36 </div>
37 </div>
75 <script>
76 (()=>{
77 const API_URL = "/api/chat";
78 const messages = [];
79 const messagesContainer = document.querySelector(".messages");
164
165 try {
166 const response = await fetch(API_URL, {
167 method: "POST",
168 headers: {
229
230 try {
231 const response = await fetch(API_URL, {
232 method: "POST",
233 headers: {
301}
302
303// Add a separate API route handler for chat
304export async function handler(req: Request) {
305 if (req.method !== 'POST') {
308
309 try {
310 const LEPTON_API_TOKEN = Deno.env.get('LEPTON_API_TOKEN') || '';
311 const openai = new OpenAI({
312 apiKey: LEPTON_API_TOKEN,
313 baseURL: 'https://llama3-3-70b.lepton.run/api/v1/',
314 dangerouslyAllowBrowser: true
315 });
317 const { messages, config = {} } = await req.json();
318
319 // Robust API configuration with sensible defaults
320 const apiConfig = {
321 model: "llama3.3-70b",
322 messages: messages,
329 };
330
331 const response = await openai.chat.completions.create(apiConfig);
332
333 return new Response(JSON.stringify(response), {
334 headers: {
335 'Content-Type': 'application/json',
336 'X-AI-Model': apiConfig.model,
337 'X-Token-Usage': 'proxied'
338 }
339 });
340 } catch (error) {
341 console.error('API Error:', error);
342
343 // Detailed error response for debugging

stellarCrimsonPandaREADME.md2 matches

@myyUpdated 5 months ago
6
71. Sign up for [Cerebras](https://cloud.cerebras.ai/)
82. Get a Cerebras API Key
93. Save it in a [Val Town environment variable](https://www.val.town/settings/environment-variables) called `CEREBRAS_API_KEY`
10
11# Todos

claude-api1 file match

@ziyanwouldUpdated 22 hours ago

api-workshop

@danarddanielsjrUpdated 2 days ago
apiry
snartapi