OpenAI API
The API for ChatGPT, GPT-4 and DALL-E. The world's most-used AI API.
About this API
OpenAI's API is the world's most used for building AI products. It covers GPT models for chat/text, DALL-E for images, Whisper for transcription, TTS for speech, and embeddings for semantic search. Priced per token, competitive at the high end. Hebrew quality is excellent from GPT-4 up.
Who it's for
How to use it
- 1Register at platform.openai.com and load $5–10 in credit.
- 2Create an API key (sk-…).
- 3Install the SDK: `npm install openai`.
- 4Call chat.completions.create with a messages array.
Installation & setup
`npm install openai` (Node) or `pip install openai` (Python). Never embed a key client-side — route calls through a Next.js API route with the key in env vars.
Code examples
import OpenAI from "openai";
const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const response = await client.chat.completions.create({
model: "gpt-4o-mini",
messages: [
{ role: "system", content: "אתה עוזר בעברית." },
{ role: "user", content: "מה מזג האוויר בתל אביב?" },
],
});
console.log(response.choices[0].message.content);Sample response
{
"id": "chatcmpl-abc123",
"model": "gpt-4o-mini",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "אני עוזר AI ואין לי גישה למזג אוויר בזמן אמת…"
}
}
],
"usage": {
"prompt_tokens": 22,
"completion_tokens": 48,
"total_tokens": 70
}
}FAQ
Tips & pitfalls
Guides
Related APIs
Anthropic Claude API
Claude's API — models particularly strong in code, long-form content and textual analysis.
Google Gemini API
Google Gemini API — free tier is generous, multimodal (image + video + text).
Hugging Face Inference API
Access thousands of open-source models — from LLMs to image recognition — without self-hosting.