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/?q=api&page=436&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 4574 results for "api"(414ms)

pluckyGreenHyenamain.tsx16 matches

@stevekrouse•Updated 6 months ago
6function App() {
7 const [messages, setMessages] = useState([]);
8 const [apiKey, setApiKey] = useState("");
9 const [generatedHtml, setGeneratedHtml] = useState("");
10 const [isLoading, setIsLoading] = useState(false);
12
13 useEffect(() => {
14 const savedApiKey = localStorage.getItem("cerebras_api_key");
15 if (savedApiKey) {
16 setApiKey(savedApiKey);
17 }
18 }, []);
19
20 const handleApiKeyChange = (e) => {
21 const newApiKey = e.target.value;
22 setApiKey(newApiKey);
23 if (newApiKey) {
24 localStorage.setItem("cerebras_api_key", newApiKey);
25 } else {
26 localStorage.removeItem("cerebras_api_key");
27 }
28 };
41 const startTime = Date.now();
42 try {
43 const client = new Cerebras({ apiKey });
44 const completionCreateResponse = await client.chat.completions.create({
45 messages: [
83 <input
84 type="password"
85 value={apiKey}
86 onChange={handleApiKeyChange}
87 className="w-full border border-gray-300 rounded-lg p-2"
88 placeholder="Enter your Cerebras API key"
89 />
90 </div>
111 placeholder="Type your instruction..."
112 required
113 disabled={!apiKey || isLoading}
114 />
115
117 type="submit"
118 className="bg-blue-500 text-white px-4 py-2 rounded-lg hover:bg-blue-600 flex-shrink-0 disabled:opacity-50"
119 disabled={!apiKey || isLoading}
120 >
121 {isLoading ? "Loading..." : "Send"}

runescapeWoodCuttingmain.tsx1 match

@charmaine•Updated 6 months ago
155 <head>
156 <title>RuneVal</title>
157 <link href="https://fonts.googleapis.com/css2?family=VT323&display=swap" rel="stylesheet">
158 <style>${css}</style>
159 </head>

anthropicCachingmain.tsx30 matches

@stevekrouse•Updated 6 months ago
1/**
2 * This val creates an interactive webpage that demonstrates the functionality of the Anthropic API.
3 * It uses a React frontend with an input for the API key and buttons to trigger different operations.
4 * The Anthropic API key is stored in the frontend state and sent with each API request.
5 */
6
10
11function App() {
12 const [apiKey, setApiKey] = useState("");
13 const [outputs, setOutputs] = useState({
14 nonCachedCall: "",
23
24 const runOperation = async (operation: string) => {
25 if (!apiKey) {
26 alert("Please enter your Anthropic API key first.");
27 return;
28 }
35 "Content-Type": "application/json",
36 },
37 body: JSON.stringify({ apiKey }),
38 });
39 const result = await response.text();
52 <a href="https://github.com/anthropics/anthropic-cookbook/blob/7786b9f39db8ba65202792f564c59697a5222531/misc/prompt_caching.ipynb#L402">
53 this python notebook
54 </a>. Enter in your Anthropic API key (which is not saved) and click the buttons to see the results.
55 </p>
56 <p>
60 <input
61 type="password"
62 placeholder="Enter Anthropic API Key"
63 value={apiKey}
64 onChange={(e) => setApiKey(e.target.value)}
65 />
66 </div>
67 <div>
68 <button onClick={() => runOperation("nonCachedCall")} disabled={loading.nonCachedCall}>
69 Non-cached API Call
70 </button>
71 <button onClick={() => runOperation("cachedCall")} disabled={loading.cachedCall}>Cached API Call</button>
72 <button onClick={() => runOperation("multiTurn")} disabled={loading.multiTurn}>Multi-turn Conversation</button>
73 </div>
74 <h2>Non-cached API Call Output:</h2>
75 <pre>{loading.nonCachedCall ? "Loading..." : outputs.nonCachedCall}</pre>
76 <h2>Cached API Call Output:</h2>
77 <pre>{loading.cachedCall ? "Loading..." : outputs.cachedCall}</pre>
78 <h2>Multi-turn Conversation Output:</h2>
95 if (url.pathname === "/run") {
96 const operation = url.searchParams.get("operation");
97 const { apiKey } = await request.json();
98
99 if (!apiKey) {
100 return new Response("API key is required", { status: 400 });
101 }
102
104
105 if (operation === "nonCachedCall") {
106 result = await runNonCachedCall(apiKey);
107 } else if (operation === "cachedCall") {
108 result = "Making two calls, first one to cache...\n\n";
109 result += await runCachedCall(apiKey);
110 result += "\n\nNow the cached call...\n\n";
111 result += await runCachedCall(apiKey);
112 } else if (operation === "multiTurn") {
113 result = await runMultiTurnConversation(apiKey);
114 } else {
115 return new Response("Invalid operation", { status: 400 });
146}
147
148async function runNonCachedCall(apiKey: string): Promise<string> {
149 const { default: anthropic } = await import("npm:@anthropic-ai/sdk@0.26.1");
150 const client = new anthropic.Anthropic({ apiKey });
151 const MODEL_NAME = "claude-3-5-sonnet-20240620";
152
175 const elapsedTime = (endTime - startTime) / 1000;
176
177 return `Non-cached API call time: ${elapsedTime.toFixed(2)} seconds
178Input tokens: ${response.usage.input_tokens}
179Output tokens: ${response.usage.output_tokens}
182}
183
184async function runCachedCall(apiKey: string): Promise<string> {
185 const { default: anthropic } = await import("npm:@anthropic-ai/sdk@0.26.1");
186 const client = new anthropic.Anthropic({ apiKey });
187 const MODEL_NAME = "claude-3-5-sonnet-20240620";
188
212 const elapsedTime = (endTime - startTime) / 1000;
213
214 return `Cached API call time: ${elapsedTime.toFixed(2)} seconds
215Input tokens: ${response.usage.input_tokens}
216Output tokens: ${response.usage.output_tokens}
221}
222
223async function runMultiTurnConversation(apiKey: string): Promise<string> {
224 const { default: anthropic } = await import("npm:@anthropic-ai/sdk@0.26.1");
225 const client = new anthropic.Anthropic({ apiKey });
226 const MODEL_NAME = "claude-3-5-sonnet-20240620";
227

evalREADME.md1 match

@maxm•Updated 6 months ago
19```
20
21You can use this library with https://www.val.town/v/maxm/transformEvalCode to return the last value without needing to export it. This is how the /eval api endpoint used to work and makes the library preform similarly to a repl.
22
23```ts

mlbScoreFetchermain.tsx4 matches

@charmaine•Updated 6 months ago
14 const fetchScores = async () => {
15 try {
16 const response = await fetch('/api/scores');
17 if (!response.ok) {
18 throw new Error('Failed to fetch scores');
47 <p>
48 <small>
49 Data source: <a href="http://statsapi.mlb.com">MLB Stats API</a> |{" "}
50 <a href={import.meta.url.replace("esm.town", "val.town")}>View source</a>
51 </small>
66 const url = new URL(request.url);
67
68 if (url.pathname === '/api/scores') {
69 try {
70 const mlbResponse = await fetch('https://statsapi.mlb.com/api/v1/schedule/games/?sportId=1');
71 const mlbData = await mlbResponse.json();
72

twitterRecentMentionsmain.tsx1 match

@charmaine•Updated 6 months ago
1// This val fetches recent tweets about @SnapAR or Lens Studio
2// Updated to use Social Data instead of Twitter API
3
4import { socialDataSearch } from "https://esm.town/v/stevekrouse/socialDataSearch";

socialDataUpdatemain.tsx1 match

@charmaine•Updated 6 months ago
1// This val fetches recent tweets about @SnapAR or Lens Studio, removes duplicates,
2// and displays them as embedded tweets with preview images on a dark background.
3// Updated to use Social Data instead of Twitter API
4
5import { socialDataSearch } from "https://esm.town/v/stevekrouse/socialDataSearch?v=5";

tvshowsmain.tsx2 matches

@tmcw•Updated 6 months ago
27 for (var i = 0; i < TV_SHOWS_WATCHED.length; ++i) {
28 const show_id = TV_SHOWS_WATCHED[i]
29 const url = `https://api.themoviedb.org/3/tv/${show_id}?api_key=${process.env.tmdb_api_key}`
30 const resp = await fetch(url)
31 const show = await resp.json()
43 title: "My TV Shows",
44 link: "https://www.val.town/Glench.tvshows",
45 description: "Personal shows from tmdb api and val.town",
46 item: {
47 title: (x) =>

generateRAdioDjRssmain.tsx2 matches

@tmcw•Updated 6 months ago
5export const generateRAdioDjRss = async () => {
6 const rssItems = previousDjs.map((dj) => {
7 const djImgSrc = `https://r-a-d.io/api/dj-image/${
8 encodeURIComponent(
9 dj.djimage,
33 link: "https://r-a-d.io/",
34 description: "Informing you of when the DJ changes on r/a/dio with only a 15 minute delay!",
35 rssLink: "https://api.val.town/v1/express/pettan.generateRAdioDjRss",
36 })
37 return new Response(rssBody, { headers: { "Content-Type": "application/rss+xml" } })

createGitHubContribGraphmain.tsx2 matches

@tmcw•Updated 7 months ago
380 <title>Code Symphony</title>
381 <style>${css}</style>
382 <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
383 </head>
384 <body>
417 `
418
419 const response = await fetch("https://api.github.com/graphql", {
420 method: "POST",
421 headers: {

PassphraseAPI2 file matches

@wolf•Updated 1 day ago

openapi2 file matches

@stevekrouse•Updated 4 days ago
artivilla
founder @outapint.io vibe coding on val.town. dm me to build custom vals: https://artivilla.com
fiberplane
Purveyors of Hono tooling, API Playground enthusiasts, and creators of 🪿 HONC 🪿 (https://honc.dev)