9```ts
10const resyBotCron = async () => {
11const bookingInfo = await api(@vtdocs.resyBot, {
12slug: 'amaro-bar',
13city: 'ldn',
119try {
120// Load secrets from Val Town
121const airtableApiKey = await val.secrets.AIRTABLE_API_KEY;
122const airtableBaseId = await val.secrets.AIRTABLE_BASE_ID;
123const airtableTableId = await val.secrets.AIRTABLE_TABLE_ID;
128129do {
130const url = new URL(`https://api.airtable.com/v0/${airtableBaseId}/${airtableTableId}`);
131if (offset) {
132url.searchParams.set('offset', offset);
135const airtableResp = await fetch(url.toString(), {
136headers: {
137Authorization: `Bearer ${airtableApiKey}`,
138'Content-Type': 'application/json',
139},
141142if (!airtableResp.ok) {
143throw new Error(`Airtable API error: ${airtableResp.statusText}`);
144}
145
contentTemplateAppmain.tsx14 matches
58const fetchContent = async () => {
59try {
60const response = await fetch("/api/content");
61const data = await response.json();
62if (data.records) {
99const analyzeContent = async (item: AirtableRecord) => {
100try {
101const response = await fetch("/api/analyze", {
102method: "POST",
103headers: {
240const url = new URL(req.url);
241242if (url.pathname === "/api/content") {
243const apiToken = "patXZjAXzGvcAyCcv.f35f12a672442df9c98a9a30f081dc21aa56b072addc93f4c53bc389fb22defd";
244const baseId = "appe6CB5XnPgGVQHw";
245const tableId = "tblldKWyq3kppzUoP";
246247const airtableUrl = `https://api.airtable.com/v0/${baseId}/${tableId}`;
248249const headers = new Headers({
250'Authorization': `Bearer ${apiToken}`,
251'Content-Type': 'application/json',
252'Access-Control-Allow-Origin': '*',
262const response = await fetch(airtableUrl, {
263headers: {
264'Authorization': `Bearer ${apiToken}`,
265'Content-Type': 'application/json',
266},
280});
281}
282} else if (url.pathname === "/api/analyze") {
283if (req.method === 'POST') {
284const { OpenAI } = await import("https://esm.town/v/std/openai");
366*/
367368// Example 2: Making an API call to /api/content endpoint
369/*
370async function fetchContent() {
371try {
372const response = await fetch('https://awhitter-contenttemplateapp.web.val.run/api/content');
373const data = await response.json();
374console.log('Content:', data);
4202. Add an HTTP module as the first step
4213. Configure the HTTP module as follows:
422- URL: https://awhitter-contenttemplateapp.web.val.run/api/content
423- Method: GET
424- Headers: None required
4254. In the next module, you can process the JSON response from the API
426The response will contain an array of records with the content from Airtable
427*/
433import { Data, animate, Override, Animatable } from "framer"
434435// This function fetches the content from the API
436async function fetchContent() {
437try {
438const response = await fetch('https://awhitter-contenttemplateapp.web.val.run/api/content')
439const data = await response.json()
440return data.records
2930const anthropic = createAnthropic({
31// apiKey = Deno.env.get("ANTHROPIC_API_KEY");
32apiKey: Deno.env.get("ANTHROPIC_API_KEY_COVERSHEET"),
33});
3435const openai = createOpenAI({
36// apiKey = Deno.env.get("OPENAI_API_KEY");
37apiKey: Deno.env.get("OPENAI_API_KEY_COVERSHEET"),
38});
3940const groq = createOpenAI({
41baseURL: "https://api.groq.com/openai/v1",
42apiKey: Deno.env.get("GROQ_API_KEY"),
43});
4445const perplexity = createOpenAI({
46apiKey: Deno.env.get("PERPLEXITY_API_KEY") ?? "",
47baseURL: "https://api.perplexity.ai/",
48});
4950const googleProvider = createGoogleGenerativeAI({
51apiKey: Deno.env.get("GOOGLE_GENERATIVE_AI_API_KEY"),
52});
53300if (toolResults && toolResults.length > 0) {
301// we have to do this bc the AI SDK doesn't seem to let you carry over function calling results,
302// so we pretend to be the user instead of using the official role: tool API, which breaks everything
303for (const toolResult of toolResults) {
304options.messages.push({
619return c.json(response);
620} catch (error) {
621console.error("API error:", error);
622return c.text("Error occurred.", 500);
623}
665return c.json(response);
666} catch (error) {
667console.error("API error:", error);
668return c.text("Error occurred.", 500);
669}
1# Val Town API URL
23When Val Town code is run on Val Town servers we use a local URL so we can save time by skipping a roundtrip to the public internet. However, if you want to run your vals that use our API, ie std library vals, locally, you'll want to use our public API's URL, `https://api.val.town`. We recommend importing and using `std/API_URL` whenever you use our API so that you are always using the most efficient route.
45## Example Usage
67```ts
8import { API_URL } from "https://esm.town/v/std/API_URL";
910const response = await fetch(`${API_URL}/v1/me`, {
11headers: {
12Authorization: `Bearer ${Deno.env.get("valtown")}`,
1import { API_URL } from "https://esm.town/v/std/API_URL";
2import { LibsqlError, type TransactionMode } from "npm:@libsql/client";
3import { z } from "npm:zod";
3536async function execute(statement: InStatement): Promise<ResultSet> {
37const res = await fetch(`${API_URL}/v1/sqlite/execute`, {
38method: "POST",
39headers: {
4950async function batch(statements: InStatement[], mode?: TransactionMode): Promise<ResultSet[]> {
51const res = await fetch(`${API_URL}/v1/sqlite/batch`, {
52method: "POST",
53headers: {
cerebras_coderREADME.md2 matches
671. 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`
cerebras_codermain.tsx5 matches
212} catch (error) {
213Toastify({
214text: "We may have hit our Cerebras Usage limits. Try again later or fork this and use your own API key.",
215position: "center",
216duration: 3000,
1024};
1025} else {
1026const client = new Cerebras({ apiKey: Deno.env.get("CEREBRAS_API_KEY") });
1027const completion = await client.chat.completions.create({
1028messages: [
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
1154href="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"
1155rel="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
alluringCoralParrotREADME.md2 matches
671. 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`
1011# Todos
alluringCoralParrotmain.tsx4 matches
212} catch (error) {
213Toastify({
214text: "We may have hit our Cerebras Usage limits. Try again later or fork this and use your own API key.",
215position: "center",
216duration: 3000,
1024};
1025} else {
1026const client = new Cerebras({ apiKey: Deno.env.get("CEREBRAS_API_KEY") });
1027const completion = await client.chat.completions.create({
1028messages: [
1148<meta name="viewport" content="width=device-width, initial-scale=1.0">
1149<title>CerebrasCoder</title>
1150<link rel="preconnect" href="https://fonts.googleapis.com" />
1151<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
1152<link
1153href="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"
1154rel="stylesheet"
1155/>