惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
罗磊的独立博客
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI
云风的 BLOG
云风的 BLOG
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
A
About on SuperTechFans
WordPress大学
WordPress大学
B
Blog
Martin Fowler
Martin Fowler
Jina AI
Jina AI
I
InfoQ
P
Proofpoint News Feed
小众软件
小众软件
S
SegmentFault 最新的问题
V
V2EX
B
Blog RSS Feed
量子位
大猫的无限游戏
大猫的无限游戏
aimingoo的专栏
aimingoo的专栏
博客园 - 三生石上(FineUI控件)
MongoDB | Blog
MongoDB | Blog
美团技术团队

Deno

Deno 2.8 | Deno Claw Patrol: an open-source security firewall for agents | Deno Fresh 2.3: Zero JS by default, View Transitions, and Temporal support | Deno Deno 2.7: Temporal API, Windows ARM, and npm overrides | Deno Build a dinosaur runner game with Deno, pt. 6 | Deno Build a dinosaur runner game with Deno, pt. 5 | Deno Deno Deploy is Generally Available | Deno Introducing Deno Sandbox | Deno Build a dinosaur runner game with Deno, pt. 4 | Deno Build a dinosaur runner game with Deno, pt. 3 | Deno Build a dinosaur runner game with Deno, pt. 2 | Deno React / Next.js Denial-of-Service Vulnerability: Deno Deploy users protected | Deno Deno 2.6: dx is the new npx | Deno Build a dinosaur runner game with Deno, pt. 1 | Deno React Server Functions / Next.js Vulnerability: Deno Deploy users protected | Deno My highlights from the new Deno Deploy | Deno Deno's Other Open Source Projects | Deno How Deno protects against npm exploits | Deno Help Us Raise $200k to Free JavaScript from Oracle | Deno Deno 2.5: Permissions in the config file | Deno Fresh 2.0 Graduates to Beta, Adds Vite Support | Deno Deno 2.4: deno bundle is back | Deno JavaScript™ Trademark Update | Deno What's coming to JavaScript | Deno A brief history of JavaScript | Deno Reports of Deno's Demise Have Been Greatly Exaggerated | Deno An Update on Fresh | Deno How Plaid migrated 100 services to a new database platform 5x faster with Deno | Deno Deno 2.3: Improved deno compile, local npm packages, and more | Deno Add JSR packages with pnpm and Yarn | Deno
Announcing OpenAI on JSR | Deno
Andy Jiang · 2025-01-24 · via Deno

JSR is a modern open source JavaScript registry that simplifies publishing and importing JavaScript and TypeScript modules. JSR supports publishing TypeScript source code, auto-generating documentation and type definition files, provenance attestation for more security, and can be used with npm-like package managers. You can use JSR modules not just with Deno, but in other runtimes like Node and environments like the browser and the edge. JSR has seen continued growth since launch, with over 400 new packages published weekly.

We’re thrilled to announce that the OpenAI JavaScript SDK is now available on JSR.

OpenAI is a leading development platform for building AI products and experiences using a diverse set of models including GPT, DALL-E, and more. It can also be used across any JavaScript environment, such as browsers and various runtimes.

Using OpenAI’s SDK via JSR offers an unbeatable developer experience, with first class TypeScript support, auto-generated documentation right in your code editor, and more.

🚨️ Looking to publish your own libraries on JSR? 🚨️

Try Stainless - the comprehensive API platform that ingests OpenAPI specs to autogenerate SDKs including JSR-ready TypeScript modules. In fact, this OpenAI SDK was built using Stainless.

Installing OpenAI

You can get started with OpenAI using the deno add command:

deno add jsr:@openai/openai

Or using npm:

npx jsr add @openai/openai

The first command will generate and add @openai to a deno.json file, while the second will generate and add @openai to a package.json file. Looking at our deno.json:

// deno.json

{
  "imports": {
    "@openai/openai": "jsr:@openai/openai@4.80.0"
  }
}

Let’s use the OpenAI SDK to create a human-like response based on a text prompt. In our main.ts file, we can write:

import OpenAI from "@openai/openai";

const openai = new OpenAI();

const completion = await openai.chat.completions.create({
  model: "gpt-4o-mini",
  messages: [
    { role: "system", content: "You are a helpful assistant." },
    {
      role: "user",
      content: "Write a haiku about recursion in programming.",
    },
  ],
});

console.log(completion.choices[0].message);

Next, let’s create an OpenAI key here and set it as an environment variable. In Mac/Linux, that looks like this:

export OPENAI_API_KEY="your_api_key_here"

Finally, let’s run it:

$ deno -A main.ts
{
  role: "assistant",
  content: "Functions call themselves,  \n" +
    "Layers deep in logic's dance,  \n" +
    "Infinite embrace.  ",
  refusal: null
}

It works! (And if you’re hitting the 429 error code, you may need to upgrade.)

Check out OpenAI’s documentation to learn more about working with their various models and creating AI driven experiences.

What’s next?

With OpenAI’s JavaScript SDK now on JSR, it’s even easier to add AI experiences to your products or build AI products.

🚨️ Read more about JSR 🚨️