OpenAI API

The API for ChatGPT, GPT-4 and DALL-E. The world's most-used AI API.

AIPaidבתשלוםדורש מפתחAI
Official siteDocumentation

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

Any AI-embedded project
SaaS companies
Chatbots
Writing tools

How to use it

  1. 1
    Register at platform.openai.com and load $5–10 in credit.
  2. 2
    Create an API key (sk-…).
  3. 3
    Install the SDK: `npm install openai`.
  4. 4
    Call 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

gpt-4o-mini — fast and cheap (< $0.001 per average request).

Tips & pitfalls

Set temperature=0 for deterministic tasks (parsing, classification).
Use streaming for a live UX.
Add your own rate limiter — prevents a bug from burning credit.

Guides

Related APIs