openai-platform
Introduction
OpenAI provides a robust API platform that allows developers to integrate advanced AI models into their applications. This includes capabilities for text generation, embeddings, image generation, and more.
Core Capabilities
1. Chat Completions
The Chat Completions API is the primary way to interact with models like GPT-4o and GPT-4o-mini. It uses a message-based interface.
Endpoint: https://api.openai.com/v1/chat/completions
Basic Usage (Node.js):
const response = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "Hello!" }
],
});
2. Embeddings
Embeddings are numerical representations of text that can be used for search, clustering, and recommendations.
Models: text-embedding-3-small, text-embedding-3-large
Basic Usage:
const embedding = await openai.embeddings.create({
model: "text-embedding-3-small",
input: "The food was delicious and the service was excellent.",
encoding_format: "float",
});
3. Assistants API
The Assistants API allows you to build AI assistants within your own applications. An Assistant has instructions and can leverage models, tools, and knowledge to respond to user queries.
4. Image Generation (DALL·E)
Generate or edit images based on natural language prompts.
Model: dall-e-3
Models Comparison
| Model | Description | Use Case |
|---|---|---|
| GPT-4o | High-intelligence flagship model | Complex tasks, reasoning |
| GPT-4o-mini | Fast, affordable small model | Simple tasks, high-volume |
| o1-preview | Reasoning model for complex problems | Science, math, coding |
Pricing & Rate Limits
OpenAI uses a pay-as-you-go model based on tokens. Tokens can be thought of as pieces of words.
- Input Tokens: Tokens sent to the model.
- Output Tokens: Tokens generated by the model.
You can monitor your usage and set limits in the OpenAI Dashboard.
Integration Example: Continue.dev
To use OpenAI with Continue.dev, add the following to your config.json:
{
"models": [
{
"title": "GPT-4o",
"provider": "openai",
"model": "gpt-4o",
"apiKey": "YOUR_API_KEY"
}
],
"tabAutocompleteModel": {
"title": "GPT-4o-mini",
"provider": "openai",
"model": "gpt-4o-mini",
"apiKey": "YOUR_API_KEY"
}
}