Create and export an API key
Before you begin, create an API key in the dashboard, which you’ll use to securely access the API. Store the key in a safe location, like a.zshrc
file or another text file on your computer. Once you’ve generated an API key, export it as an environment variable in your terminal.
Export an environment variable on macOS or Linux
Install an official SDK
To use the OpenAI API in server-side JavaScript environments like Node.js, Deno, or Bun, you can use the official OpenAI SDK for TypeScript and JavaScript. Get started by installing the SDK using npm or your preferred package manager:With the OpenAI SDK installed, create a file called Execute the code with
Install the OpenAI SDK with npm
example.mjs
and copy the example code into it:Test a basic API request
node example.mjs
(or the equivalent command for Deno or Bun). In a few moments, you should see the output of your API request.Azure OpenAI libraries
Microsoft’s Azure team maintains libraries that are compatible with both the OpenAI API and Azure OpenAI services. Read the library documentation below to learn how you can use them with the OpenAI API.Azure OpenAI client library for .NET
Azure OpenAI client library for JavaScript
Azure OpenAI client library for Java
Azure OpenAI client library for Go
Community libraries
The libraries below are built and maintained by the broader developer community. You can also watch our OpenAPI specification repository on GitHub to get timely updates on when we make changes to our API. Please note that OpenAI does not verify the correctness or security of these projects. Use them at your own risk!C# / .NET
C++
Clojure
Crystal
Dart/Flutter
Delphi
Elixir
Go
Java
Julia
Kotlin
Node.js
- openai-api by Njerschow
- openai-api-node by erlapso
- gpt-x by ceifa
- gpt3 by poteat
- gpts by thencc
- @dalenguyen/openai by dalenguyen
- tectalic/openai by tectalic
PHP
Python
R
Ruby
Rust
- async-openai by 64bit
- fieri by lbkolev
Scala
Swift
- AIProxySwift by Lou Zell
- OpenAIKit by dylanshine
- OpenAI by MacPaw
Unity
Unreal Engine
Other OpenAI repositories
- tiktoken - counting tokens
- simple-evals - simple evaluation library
- mle-bench - library to evaluate machine learning engineer agents
- gym - reinforcement learning library
- swarm - educational orchestration repository