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=721&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 10968 results for "api"(893ms)

hiraganaWordBuildermain.tsx2 matches

@ashryanio•Updated 7 months ago
91 setIsLoading(true);
92 try {
93 const response = await fetch(`/api/image/${romaji}`);
94 if (!response.ok) {
95 throw new Error("Failed to fetch image");
264 const url = new URL(request.url);
265
266 if (url.pathname.startsWith("/api/image/")) {
267 const romaji = url.pathname.split("/").pop();
268 try {

scholarlyIvoryWombatmain.tsx2 matches

@stevekrouse•Updated 7 months ago
40
41 try {
42 const response = await fetch("/api/chat", {
43 method: "POST",
44 headers: { "Content-Type": "application/json" },
134
135async function server(request: Request): Promise<Response> {
136 if (request.method === "POST" && new URL(request.url).pathname === "/api/chat") {
137 const { messages, model } = await request.json();
138 const client = new Cerebras();

sqlitemain.tsx4 matches

@boubou007•Updated 7 months ago
1import { API_URL } from "https://esm.town/v/std/API_URL";
2import { LibsqlError, type ResultSet, type Row, type TransactionMode } from "npm:@libsql/client";
3import { z } from "npm:zod";
35
36async function execute(statement: InStatement, args?: InArgs): Promise<ResultSet> {
37 const res = await fetch(`${API_URL}/v1/sqlite/execute`, {
38 method: "POST",
39 headers: {
50
51async function batch(statements: InStatement[], mode?: TransactionMode): Promise<ResultSet[]> {
52 const res = await fetch(`${API_URL}/v1/sqlite/batch`, {
53 method: "POST",
54 headers: {
78
79/* Val Town's Turso Proxy returns rows as an array of values
80 * Yet the LibSQL API has a Row type which behave as an array or object,
81 * ie you can access it via numerical index or string
82 */

getJsonAndRenderAsImageREADME.md4 matches

@ashryanio•Updated 7 months ago
16
17To easily upload an image to your blob storage, [fork this val](
18getBlobAndRenderAsImage), run it, and enter your API key in the password input.
19
20## How it works
29
30 - The server function calls `blob.getJSON("image-test")`.
31 - This `blob.getJSON()` method makes an HTTP request to the Val Town API.
32 - The API returns a Response object containing the JSON data.
33
34
72
73- [Blob storage overview in Val Town docs](https://docs.val.town/std/blob/)
74- [Val Town REST API references for blobs](https://docs.val.town/openapi#tag/blobs)
75- [Val Town blob std lib source code](https://www.val.town/v/std/blob)

hackerNewsDigestmain.tsx1 match

@workingpleasewait•Updated 7 months ago
1// This cron emails Hacker News stories from its API every 3 days.
2
3import { email } from "https://esm.town/v/std/email";

OpenAIREADME.md3 matches

@It_FITS_Marketing•Updated 7 months ago
1# OpenAI - [Docs ↗](https://docs.val.town/std/openai)
2
3Use OpenAI's chat completion API with [`std/openai`](https://www.val.town/v/std/openai). This integration enables access to OpenAI's language models without needing to acquire API keys.
4
5For free Val Town users, [all calls are sent to `gpt-4o-mini`](https://www.val.town/v/std/openaiproxy?v=12#L85).
32If these limits are too low, let us know! You can also get around the limitation by using your own keys:
33
341. Create your own API key on [OpenAI's website](https://platform.openai.com/api-keys)
352. Create an [environment variable](https://www.val.town/settings/environment-variables?adding=true) named `OPENAI_API_KEY`
363. Use the `OpenAI` client from `npm:openai`:
37

OpenAImain.tsx7 matches

@It_FITS_Marketing•Updated 7 months ago
2
3/**
4 * API Client for interfacing with the OpenAI API. Uses Val Town credentials.
5 */
6export class OpenAI {
8
9 /**
10 * API Client for interfacing with the OpenAI API. Uses Val Town credentials.
11 *
12 * @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
14 * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
15 * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
16 * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
17 * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
18 * @param {boolean} [opts.dangerouslyAllowBrowser=false] - By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.
19 */
20 constructor(options: Omit<ClientOptions, "baseURL" | "apiKey" | "organization"> = {}) {
21 this.rawOpenAIClient = new RawOpenAI({
22 ...options,
23 baseURL: "https://std-openaiproxy.web.val.run/v1",
24 apiKey: Deno.env.get("valtown"),
25 organization: null,
26 });

stockAPImain.tsx4 matches

@pete•Updated 7 months ago
1import { parse } from "https://deno.land/std@0.181.0/flags/mod.ts";
2
3const ALPHA_VANTAGE_API_KEY = "your_api_key_here"; // Replace with your actual API key
4
5async function fetchStockData(symbol: string) {
6 const apiUrl =
7 `https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=${symbol}&apikey=${ALPHA_VANTAGE_API_KEY}`;
8 const response = await fetch(apiUrl);
9 const data = await response.json();
10

renderPoemWidgetJsonmain.tsx2 matches

@crsven•Updated 7 months ago
13 timeZone,
14 };
15 const timeForApi = date.toLocaleTimeString("en-GB", {
16 ...baseTimeParams,
17 hourCycle: "h23",
18 });
19 const poem = await getPoemForTime(timeForApi);
20 const newState = { ...poemWidgetJson };
21 newState.layouts.hello_small.layers[0].rows[0].cells[0].text.string = poem;

stockAPIREADME.md2 matches

@pete•Updated 7 months ago
1This Val accepts a stock symbol and will return current price and intraday price change.
2
3example: `https://pete-stockapi.web.val.run/symbol=MSFT`
4
5It's currently using alphavantage free tier API so it's limited to only 25 requests/day. Fork and create your own premium API key for more request.

daily-advice-app1 file match

@dcm31•Updated 1 day ago
Random advice app using Advice Slip API

gptApiTemplate1 file match

@charmaine•Updated 3 days ago
apiv1
papimark21