Using GPT-4 on OpenAI API

Implementation guide · GPT-4 · OpenAI

Serverless

OpenAI API exposes GPT-4 through model ID gpt-4. Use the setup steps, sourced pricing, capabilities, and official provider links below to validate this route before deployment.

Last refreshed 2026-05-10. Next refresh: weekly.

Quick Start

  1. 1
    Create an account at OpenAI API and generate an API key.
  2. 2
    Use the OpenAI API SDK or REST API to call gpt-4 — see the documentation for request format.
  3. 3
    You'll be billed $30.00/1M input, $60.00/1M output tokens. See full pricing.

Code Examples

Install
pip install openai
API key
OPENAI_API_KEY
Model ID
gpt-4

Use the model slug directly, e.g. "gpt-4o" or "gpt-4.1-mini".

import os
from openai import OpenAI

client = OpenAI()  # reads OPENAI_API_KEY from env
response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Hello"}]
)
print(response.choices[0].message.content)

Pricing on OpenAI API

TypePrice (per 1M)
Input tokens$30.00
Output tokens$60.00

Capabilities

VisionMultimodalJSON / Tool useStructured OutputsCode Execution

About GPT-4

OpenAI's original GPT-4 model with strong reasoning and general knowledge. Foundation model for many applications.

Model Specs

Released2023-03-14
Parameters1.76T (8x222B MoE)*
Context8k
ArchitectureMixture of Experts
Knowledge cutoff2021-09

Provider

OpenAI API

OpenAI

San Francisco, California, United States