Introduction to OpenAI

Pre Requisites

OpenAI Libraries

OpenAI offers a range of official and community-maintained client libraries for interacting with the OpenAI API. Whether you’re building chatbots, generating images, or computing embeddings, there’s a library for your environment. Below is a quick overview of the most popular options:

LibraryLanguageOfficialDocumentation
OpenAI PythonPythonYeshttps://github.com/openai/openai-python
OpenAI Node.jsJavaScript/TSYeshttps://github.com/openai/openai-node
OpenAI.NETC#/.NETCommunityhttps://github.com/OkGoDoIt/OpenAI-API-dotnet
Azure OpenAIAzure ServiceYeshttps://learn.microsoft.com/azure/cognitive-services/openai/
Community SDKsRuby, PHP, Go…Communityhttps://platform.openai.com/docs/community

The image lists various OpenAI libraries, including Python, .NET, Node.js, Azure OpenAI, and community libraries. It also includes a link to the OpenAI documentation.

For the full list of clients and SDKs, see the Libraries section on the OpenAI docs.


Python

The official Python SDK is the most widely used OpenAI client. It supports:

  • Chat and text completions
  • Image generation
  • Embeddings
  • Utility functions and helpers

Python’s readability and extensive ecosystem make it ideal for developers, data scientists, and researchers. It integrates smoothly into existing projects and benefits from comprehensive docs and community support.

Note

Be sure to set your API key in the environment before running examples:

export OPENAI_API_KEY="your_api_key_here"
import os
import openai

openai.api_key = os.getenv("OPENAI_API_KEY")

response = openai.ChatCompletion.create(
    model="gpt-3.5-turbo",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user",   "content": "Hello, how are you?"}
    ]
)

print(response.choices[0].message.content)

Node.js

The official Node.js client offers a promise-based API that works seamlessly with modern JavaScript and TypeScript frameworks:

  • Async/await support
  • ESM modules
  • Works with Express, React, Vue, and more
import OpenAI from "openai";

const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });

const response = await openai.chat.completions.create({
  model: "gpt-3.5-turbo",
  messages: [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user",   content: "What's the weather like today?" }
  ]
});

console.log(response.choices[0].message.content);

.NET

While OpenAI doesn’t provide an official .NET SDK, community libraries like OpenAI.NET and OpenAI API Client fill the gap. They enable cross-platform .NET applications with:

  • Asynchronous processing
  • Microsoft stack integration
  • Enterprise-grade features

The image is an infographic about .NET Libraries, highlighting features like community-supported libraries, cross-platform applications, enterprise integration, and asynchronous processing, along with use cases in AI, financial services, and Microsoft Teams.

using System;
using System.Threading.Tasks;
using OpenAI.Chat;

namespace OpenAILesson
{
    class Program
    {
        static async Task Main()
        {
            var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY");
            var client = new ChatClient(new ChatClientOptions
            {
                ApiKey = apiKey,
                Model  = "gpt-3.5-turbo"
            });

            var result = await client.CompleteChatAsync("Say 'this is a test.'");
            Console.WriteLine(result.Choices[0].Message.Content);
        }
    }
}

Azure OpenAI

Azure OpenAI Service brings OpenAI’s capabilities to the Azure ecosystem, offering:

  • Enterprise security & compliance
  • Managed, scalable API hosting
  • Integration with Azure Cognitive Services, ML, and DevOps
  • Access to pre-trained and fine-tuned models

Explore the Azure OpenAI Service documentation.

Community Libraries

Numerous open-source SDKs and tools extend OpenAI support to languages and frameworks beyond the official clients. Community libraries provide:

  • Open collaboration and contributions
  • Language-specific enhancements
  • Cross-platform development
  • Creative integrations

The image is a slide titled "Community Libraries" highlighting four aspects: diverse ecosystem, open-source contribution, platform flexibility and language extensions, and open collaboration.


Further Reading

Watch Video

Watch video content

Previous
Understanding OpenAI Models