1# OpenAI - [Docs ↗](https://docs.val.town/std/openai)
23Use 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.
45For free Val Town users, [all calls are sent to `gpt-4o-mini`](https://www.val.town/v/std/openaiproxy?v=12#L85).
67## Basic Usage
89```ts title="Example" val
10import { OpenAI } from "https://esm.town/v/std/openai";
1112const openai = new OpenAI();
1314const completion = await openai.chat.completions.create({
15messages: [
16{ role: "user", content: "Say hello in a creative way" },
58## Limits
5960While our wrapper simplifies the integration of OpenAI, there are a few limitations to keep in mind:
6162* **Usage Quota**: We limit each user to 10 requests per minute.
65If these limits are too low, let us know! You can also get around the limitation by using your own keys:
66671. Create your own API key on [OpenAI's website](https://platform.openai.com/api-keys)
682. Create an [environment variable](https://www.val.town/settings/environment-variables?adding=true) named `OPENAI_API_KEY`
693. Use the `OpenAI` client from `npm:openai`:
7071```ts title="Example" val
72import { OpenAI } from "npm:openai";
7374const openai = new OpenAI();
75```
767778[📝 Edit docs](https://github.com/val-town/val-town-docs/edit/main/src/content/docs/std/openai.mdx)
7980Migrated from folder: openai/openai
openaiproxyREADME.md3 matches
1# OpenAI Proxy
23This OpenAI API proxy injects Val Town's API keys. For usage documentation, check out https://www.val.town/v/std/openai
45Migrated from folder: openai/openaiproxy
4const cheerio = await import("npm:cheerio");
5const html = await fetchText(
6"https://en.wikipedia.org/wiki/OpenAI",
7);
8const $ = cheerio.load(html);
weatherGPTmain.tsx3 matches
1import { email } from "https://esm.town/v/std/email?v=11";
2import { OpenAI } from "npm:openai";
34let location = "brooklyn ny";
8).then(r => r.json());
910const openai = new OpenAI();
11let chatCompletion = await openai.chat.completions.create({
12messages: [{
13role: "user",
weatherGPTREADME.md1 match
1If you fork this, you'll need to set `OPENAI_API_KEY` in your [Val Town Secrets](https://www.val.town/settings/secrets).
23
instructorExamplemain.tsx3 matches
1import Instructor from "https://esm.sh/@instructor-ai/instructor";
2import OpenAI from "https://esm.sh/openai";
3import { z } from "https://esm.sh/zod";
45const openAISecrets = {
6apiKey: getApiKey(),
7organization: getOrganisationKey(),
8};
910const oai = new OpenAI(openAISecrets);
1112const client = Instructor({
weatherGPTmain.tsx3 matches
1import { email } from "https://esm.town/v/std/email?v=11";
2import { fetch } from "https://esm.town/v/std/fetch";
3import { OpenAI } from "npm:openai";
45let location = "shenzhen";
9).then(r => r.json());
1011const openai = new OpenAI();
12let chatCompletion = await openai.chat.completions.create({
13messages: [{
14role: "user",
weatherGPTREADME.md1 match
1If you fork this, you'll need to set `OPENAI_API_KEY` in your [Val Town Secrets](https://www.val.town/settings/secrets).
23
gpt4Examplemain.tsx4 matches
1import { OpenAI } from "npm:openai";
2Deno.env.get("OPENAI_API_KEY");
34const openai = new OpenAI();
5let chatCompletion = await openai.chat.completions.create({
6messages: [{
7role: "user",
gpt4ExampleREADME.md1 match
3This uses the brand new `gpt-4-1106-preview`.
45To use this, set `OPENAI_API_KEY` in your [Val Town Secrets](https://www.val.town/settings/secrets).