ll-24-25
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # openai-library Libraries ========= Set up your development environment to use the OpenAI API with an SDK in your preferred language. This page covers setting up your local development environment to use the [OpenAI API](/docs/api-reference). You can use one of our officially supported SDKs, a community library, or your own preferred HTTP client. Create and export an API key ---------------------------- Before you begin, [create an API key in the dashboard](/api-keys), which you'll use to securely [access the API](/docs/api-reference/authentication). Store the key in a safe location, like a [`.zshrc` file](https://www.freecodecamp.org/news/how-do-zsh-configuration-files-work/) or another text file on your computer. Once you've generated an API key, export it as an [environment variable](https://en.wikipedia.org/wiki/Environment_variable) in your terminal. macOS / Linux Export an environment variable on macOS or Linux systems ```bash export OPENAI_API_KEY="your_api_key_here" ``` Windows Export an environment variable in PowerShell ```bash setx OPENAI_API_KEY "your_api_key_here" ``` OpenAI SDKs are configured to automatically read your API key from the system environment. Install an official SDK ----------------------- JavaScript 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](https://github.com/openai/openai-node). Get started by installing the SDK using [npm](https://www.npmjs.com/) or your preferred package manager: Install the OpenAI SDK with npm ```bash npm install openai ``` With the OpenAI SDK installed, create a file called `example.mjs` and copy the example code into it: Test a basic API request ```javascript import OpenAI from "openai"; const client = new OpenAI(); const response = await client.responses.create({ model: "gpt-4.1", input: "Write a one-sentence bedtime story about a unicorn." }); console.log(response.output_text); ``` Execute the code with `node example.mjs` (or the equivalent command for Deno or Bun). In a few moments, you should see the output of your API request. [ Learn more on GitHub Discover more SDK capabilities and options on the library's GitHub README. ](https://github.com/openai/openai-node) Python To use the OpenAI API in Python, you can use the official [OpenAI SDK for Python](https://github.com/openai/openai-python). Get started by installing the SDK using [pip](https://pypi.org/project/pip/): Install the OpenAI SDK with pip ```bash pip install openai ``` With the OpenAI SDK installed, create a file called `example.py` and copy the example code into it: Test a basic API request ```python from openai import OpenAI client = OpenAI() response = client.responses.create( model="gpt-4.1", input="Write a one-sentence bedtime story about a unicorn." ) print(response.output_text) ``` Execute the code with `python example.py`. In a few moments, you should see the output of your API request. [ Learn more on GitHub Discover more SDK capabilities and options on the library's GitHub README. ](https://github.com/openai/openai-python) .NET In collaboration with Microsoft, OpenAI provides an officially supported API client for C#. You can install it with the .NET CLI from [NuGet](https://www.nuget.org/). ```text dotnet add package OpenAI ``` A simple API request to [Chat Completions](/docs/api-reference/chat) would look like this: ```csharp using OpenAI.Chat; ChatClient client = new( model: "gpt-4.1", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY") ); ChatCompletion completion = client.CompleteChat("Say 'this is a test.'"); Console.WriteLine($"[ASSISTANT]: {completion.Content[0].Text}"); ``` To learn more about using the OpenAI API in .NET, check out the GitHub repo linked below! [ Learn more on GitHub Discover more SDK capabilities and options on the library's GitHub README. ](https://github.com/openai/openai-dotnet) Java OpenAI provides an API helper for the Java programming language, currently in beta. You can include the Maven depency using the following configuration: ```xml <dependency> <groupId>com.openai</groupId> <artifactId>openai-java</artifactId> <version>0.31.0</version> </dependency> ``` A simple API request to [Chat Completions](/docs/api-reference/chat) would look like this: ```java import com.openai.client.OpenAIClient; import com.openai.client.okhttp.OpenAIOkHttpClient; import com.openai.models.ChatCompletion; import com.openai.models.ChatCompletionCreateParams; import com.openai.models.ChatModel; // Configures using the `OPENAI_API_KEY`, `OPENAI_ORG_ID` and `OPENAI_PROJECT_ID` // environment variables OpenAIClient client = OpenAIOkHttpClient.fromEnv(); ChatCompletionCreateParams params = ChatCompletionCreateParams.builder() .addUserMessage("Say this is a test") .model(ChatModel.O3_MINI) .build(); ChatCompletion chatCompletion = client.chat().completions().create(params); ``` To learn more about using the OpenAI API in Java, check out the GitHub repo linked below! [ Learn more on GitHub Discover more SDK capabilities and options on the library's GitHub README. ](https://github.com/openai/openai-java) Go OpenAI provides an API helper for the Go programming language, currently in beta. You can import the library using the code below: ```golang import ( "github.com/openai/openai-go" // imported as openai ) ``` A simple API request to [Chat Completions](/docs/api-reference/chat) would look like this: ```golang package main import ( "context" "fmt" "github.com/openai/openai-go" "github.com/openai/openai-go/option" ) func main() { client := openai.NewClient( option.WithAPIKey("My API Key"), // defaults to os.LookupEnv("OPENAI_API_KEY") ) chatCompletion, err := client.Chat.Completions.New( context.TODO(), openai.ChatCompletionNewParams{ Messages: openai.F( []openai.ChatCompletionMessageParamUnion{ openai.UserMessage("Say this is a test"), } ), Model: openai.F(openai.ChatModelGPT4o), } ) if err != nil { panic(err.Error()) } println(chatCompletion.Choices[0].Message.Content) } ``` To learn more about using the OpenAI API in Go, check out the GitHub repo linked below! [ Learn more on GitHub Discover more SDK capabilities and options on the library's GitHub README. ](https://github.com/openai/openai-go) 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](https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/openai/Azure.AI.OpenAI) * [Azure OpenAI client library for JavaScript](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/openai/openai) * [Azure OpenAI client library for Java](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/openai/azure-ai-openai) * [Azure OpenAI client library for Go](https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/ai/azopenai) * * * Community libraries ------------------- The libraries below are built and maintained by the broader developer community. You can also [watch our OpenAPI specification](https://github.com/openai/openai-openapi) 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 * [Betalgo.OpenAI](https://github.com/betalgo/openai) by [Betalgo](https://github.com/betalgo) * [OpenAI-API-dotnet](https://github.com/OkGoDoIt/OpenAI-API-dotnet) by [OkGoDoIt](https://github.com/OkGoDoIt) * [OpenAI-DotNet](https://github.com/RageAgainstThePixel/OpenAI-DotNet) by [RageAgainstThePixel](https://github.com/RageAgainstThePixel) ### C++ * [liboai](https://github.com/D7EAD/liboai) by [D7EAD](https://github.com/D7EAD) ### Clojure * [openai-clojure](https://github.com/wkok/openai-clojure) by [wkok](https://github.com/wkok) ### Crystal * [openai-crystal](https://github.com/sferik/openai-crystal) by [sferik](https://github.com/sferik) ### Dart/Flutter * [openai](https://github.com/anasfik/openai) by [anasfik](https://github.com/anasfik) ### Delphi * [DelphiOpenAI](https://github.com/HemulGM/DelphiOpenAI) by [HemulGM](https://github.com/HemulGM) ### Elixir * [openai.ex](https://github.com/mgallo/openai.ex) by [mgallo](https://github.com/mgallo) ### Go * [go-gpt3](https://github.com/sashabaranov/go-gpt3) by [sashabaranov](https://github.com/sashabaranov) ### Java * [simple-openai](https://github.com/sashirestela/simple-openai) by [Sashir Estela](https://github.com/sashirestela) * [Spring AI](https://spring.io/projects/spring-ai) ### Julia * [OpenAI.jl](https://github.com/rory-linehan/OpenAI.jl) by [rory-linehan](https://github.com/rory-linehan) ### Kotlin * [openai-kotlin](https://github.com/Aallam/openai-kotlin) by [Mouaad Aallam](https://github.com/Aallam) ### Node.js * [openai-api](https://www.npmjs.com/package/openai-api) by [Njerschow](https://github.com/Njerschow) * [openai-api-node](https://www.npmjs.com/package/openai-api-node) by [erlapso](https://github.com/erlapso) * [gpt-x](https://www.npmjs.com/package/gpt-x) by [ceifa](https://github.com/ceifa) * [gpt3](https://www.npmjs.com/package/gpt3) by [poteat](https://github.com/poteat) * [gpts](https://www.npmjs.com/package/gpts) by [thencc](https://github.com/thencc) * [@dalenguyen/openai](https://www.npmjs.com/package/@dalenguyen/openai) by [dalenguyen](https://github.com/dalenguyen) * [tectalic/openai](https://github.com/tectalichq/public-openai-client-js) by [tectalic](https://tectalic.com/) ### PHP * [orhanerday/open-ai](https://packagist.org/packages/orhanerday/open-ai) by [orhanerday](https://github.com/orhanerday) * [tectalic/openai](https://github.com/tectalichq/public-openai-client-php) by [tectalic](https://tectalic.com/) * [openai-php client](https://github.com/openai-php/client) by [openai-php](https://github.com/openai-php) ### Python * [chronology](https://github.com/OthersideAI/chronology) by [OthersideAI](https://www.othersideai.com/) ### R * [rgpt3](https://github.com/ben-aaron188/rgpt3) by [ben-aaron188](https://github.com/ben-aaron188) ### Ruby * [openai](https://github.com/nileshtrivedi/openai/) by [nileshtrivedi](https://github.com/nileshtrivedi) * [ruby-openai](https://github.com/alexrudall/ruby-openai) by [alexrudall](https://github.com/alexrudall) ### Rust * [async-openai](https://github.com/64bit/async-openai) by [64bit](https://github.com/64bit) * [fieri](https://github.com/lbkolev/fieri) by [lbkolev](https://github.com/lbkolev) ### Scala * [openai-scala-client](https://github.com/cequence-io/openai-scala-client) by [cequence-io](https://github.com/cequence-io) ### Swift * [AIProxySwift](https://github.com/lzell/AIProxySwift) by [Lou Zell](https://github.com/lzell) * [OpenAIKit](https://github.com/dylanshine/openai-kit) by [dylanshine](https://github.com/dylanshine) * [OpenAI](https://github.com/MacPaw/OpenAI/) by [MacPaw](https://github.com/MacPaw) ### Unity * [OpenAi-Api-Unity](https://github.com/hexthedev/OpenAi-Api-Unity) by [hexthedev](https://github.com/hexthedev) * [com.openai.unity](https://github.com/RageAgainstThePixel/com.openai.unity) by [RageAgainstThePixel](https://github.com/RageAgainstThePixel) ### Unreal Engine * [OpenAI-Api-Unreal](https://github.com/KellanM/OpenAI-Api-Unreal) by [KellanM](https://github.com/KellanM) Other OpenAI repositories ------------------------- * [tiktoken](https://github.com/openai/tiktoken) - counting tokens * [simple-evals](https://github.com/openai/simple-evals) - simple evaluation library * [mle-bench](https://github.com/openai/mle-bench) - library to evaluate machine learning engineer agents * [gym](https://github.com/openai/gym) - reinforcement learning library * [swarm](https://github.com/openai/swarm) - educational orchestration repository

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully