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:
Library | Language | Official | Documentation |
---|---|---|---|
OpenAI Python | Python | Yes | https://github.com/openai/openai-python |
OpenAI Node.js | JavaScript/TS | Yes | https://github.com/openai/openai-node |
OpenAI.NET | C#/.NET | Community | https://github.com/OkGoDoIt/OpenAI-API-dotnet |
Azure OpenAI | Azure Service | Yes | https://learn.microsoft.com/azure/cognitive-services/openai/ |
Community SDKs | Ruby, PHP, Go… | Community | https://platform.openai.com/docs/community |
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
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
Further Reading
- OpenAI Python SDK GitHub
- OpenAI Node.js SDK GitHub
- Azure OpenAI Service overview
- OpenAI Community Resources
Watch Video
Watch video content