APIMaster.ai

ChatGPT API Guide 2026 — Access GPT-5 & GPT-4o | APIMaster.ai

Complete ChatGPT API guide: how to get access, call GPT-5 and GPT-4o with Python, set up streaming, and use the API outside the US via APIMaster.ai at discounted rates.

ChatGPT API Guide 2026

The ChatGPT API (officially the OpenAI API) lets you call GPT-5, GPT-4o, o3, and other models from your applications. This guide covers setup, Python usage, and how to access the ChatGPT API outside the US without restrictions.

What Is the ChatGPT API?

The ChatGPT API is the OpenAI Chat Completions API—the same technology behind ChatGPT, exposed as a developer endpoint. You send a list of messages and receive a generated response. It's available through OpenAI directly or via providers like APIMaster.ai.

Getting ChatGPT API Access

Direct from OpenAI:

  • US/EU billing address and credit card required
  • Blocked in China, Russia, and some other regions

Via APIMaster.ai (no restrictions):

  1. Register with just an email
  2. Top up balance (Alipay, USDT, credit card, WeChat)
  3. Get API key from console
  4. Use https://apimaster.ai/v1 as your base URL

ChatGPT API Python Quickstart

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_APIMASTER_KEY",
    base_url="https://apimaster.ai/v1",
)

response = client.chat.completions.create(
    model="gpt-5",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Explain how the ChatGPT API works."},
    ],
)

print(response.choices[0].message.content)

ChatGPT API Models Comparison

Model Context Input Output Best For
gpt-5 128K High High Complex tasks, reasoning
gpt-4o 128K Medium Medium Multimodal, vision
gpt-4o-mini 128K Low Low Fast, budget-friendly
o3 200K High High Math, science, coding
o4-mini 128K Medium Medium Fast reasoning

See APIMaster marketplace for current prices.

Streaming ChatGPT API Responses

Streaming delivers tokens as they're generated—essential for chat UIs:

stream = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Write a Python function to check if a number is prime."}],
    stream=True,
)

for chunk in stream:
    if chunk.choices[0].delta.content is not None:
        print(chunk.choices[0].delta.content, end="", flush=True)
print()

Vision: Send Images to ChatGPT API

GPT-4o and GPT-5 accept image inputs:

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "image_url",
                    "image_url": {"url": "https://example.com/diagram.png"},
                },
                {"type": "text", "text": "Describe what you see in this diagram."},
            ],
        }
    ],
)
print(response.choices[0].message.content)

Function Calling (Tool Use)

tools = [
    {
        "type": "function",
        "function": {
            "name": "search_docs",
            "description": "Search the documentation",
            "parameters": {
                "type": "object",
                "properties": {
                    "query": {"type": "string"},
                },
                "required": ["query"],
            },
        },
    }
]

response = client.chat.completions.create(
    model="gpt-5",
    messages=[{"role": "user", "content": "Find docs about authentication."}],
    tools=tools,
    tool_choice="auto",
)

# Check if model wants to call a function
if response.choices[0].finish_reason == "tool_calls":
    tool_call = response.choices[0].message.tool_calls[0]
    print(f"Function: {tool_call.function.name}")
    print(f"Args: {tool_call.function.arguments}")

Building a Simple ChatGPT-like App

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_APIMASTER_KEY",
    base_url="https://apimaster.ai/v1",
)

history = [{"role": "system", "content": "You are a helpful coding assistant."}]

def chat(user_input):
    history.append({"role": "user", "content": user_input})
    response = client.chat.completions.create(
        model="gpt-4o",
        messages=history,
    )
    reply = response.choices[0].message.content
    history.append({"role": "assistant", "content": reply})
    return reply

# Interactive loop
while True:
    user = input("You: ")
    if user.lower() in ("quit", "exit"):
        break
    print(f"Assistant: {chat(user)}")

ChatGPT API Pricing

OpenAI charges per million tokens. APIMaster offers the same models at significant discounts. Visit the marketplace for current prices, or see the OpenAI API Pricing guide.

Using ChatGPT API in China and Restricted Regions

The official OpenAI API is blocked in China. APIMaster provides:

  • Relay through non-blocked infrastructure
  • Chinese payment methods (Alipay, WeChat, USDT)
  • No VPN required
  • Low-latency endpoints for Asia

Get ChatGPT API access →