API Documentation

Build applications using the powerful GPT4BD API. Our API is structurally identical to the official OpenAI API, making migration effortless.

Introduction

The GPT4BD API uses REST, accepts JSON payloads, and returns JSON responses. It uses standard HTTP response codes to indicate success or errors.

Base URL: https://gpt4bd.com/api/v1

Authentication

Authenticate your API requests by providing your API key in the Authorization HTTP header.

Authorization: Bearer YOUR_API_KEY
Keep your keys safe. Do not share your API keys in publicly accessible areas such as GitHub, client-side code, etc.

Models & Pricing

We abstract the complex OpenAI models into three simple tiers.

Model Interface ID Underlying Tech Cost (Tokens / 1k API Tokens) Best For
Model Air gpt-4o-mini 1 token Simple tasks, translation, high volume processing
Model Pro gpt-4o 5 tokens Complex reasoning, coding, logical tasks
Model Pro Max gpt-4-turbo 15 tokens Most capable model, deep analysis, long context

Create Chat Completion

POST /chat/completions

Creates a model response for the given chat conversation.

Request Body Example
{
  "model": "Model Pro",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant."
    },
    {
      "role": "user",
      "content": "Hello!"
    }
  ],
  "temperature": 0.7,
  "stream": true
}
Response Example
{
  "id": "chatcmpl-DDms4o3CadQWWiZDObf9CnfggRglI",
  "object": "chat.completion",
  "created": 1772178496,
  "model": "Model Pro",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! How can I assist you today?",
        "refusal": null,
        "annotations": []
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 19,
    "completion_tokens": 9,
    "total_tokens": 28,
    "prompt_tokens_details": {
      "cached_tokens": 0,
      "audio_tokens": 0
    },
    "completion_tokens_details": {
      "reasoning_tokens": 0,
      "audio_tokens": 0,
      "accepted_prediction_tokens": 0,
      "rejected_prediction_tokens": 0
    }
  },
  "service_tier": "default",
  "system_fingerprint": "fp_c7d0c94d9d"
}

Create Image Generation

POST /images/generations

Creates an image given a prompt. Powered by the incredibly advanced DALLĀ·E 3 engine. Note: Image generation bills a fixed cost of 500 tokens per image generated, rather than parsing tokens.

Request Body Example
{
  "model": "Model Image",
  "prompt": "A cute baby sea otter playing with a colorful beach ball",
  "n": 1,
  "size": "1024x1024"
}
Response Example
{
  "created": 1589478378,
  "data": [
    { 
      "revised_prompt": "Create a visual representation of an adorable, playful baby sea otter. It's splashing in the clear, ocean water, where its fur is slightly wet and shimmering under the sun. The sea otter is actively engaged in a game, playfully nudging and splashing a vibrant beach ball which consists of colors such as red, yellow, blue, and white. The fun-filled interaction of the otter with the ball reflects a scene filled with joy, playfulness, and innocence. Overall, the image emanates warmth and gentle humor, evoking a sense of awe-inspiring cuteness overloaded.",
      "url": "https://..."
    }
  ]
}

Custom Customer Service Bot

POST /bot

An easy-to-use endpoint designed specifically for chatbots. You provide the business knowledge (instructions, policies, company context) and the user's message. The API automatically builds the system and user prompts, calls the model, and returns a clean, simplified reply.

Request Body Example
{
  "knowledge": "You are a customer service representative for Bengal Electronics. Our return policy allows returns within 30 days for defective items. We only ship our products within Bangladesh.",
  "message": "Do you ship to India?",
  "history": [
    {"role": "user", "content": "Hi there!"},
    {"role": "assistant", "content": "Hello! I am a customer service rep for Bengal Electronics. How can I help you today?"}
  ],
  "stream": false
}
Response Example
{
  "success": true,
  "reply": "I'm sorry, but we only ship our products within Bangladesh."
}

Errors

Standard HTTP response codes indicate whether a request succeeded or failed.

  • 200
    OK - Everything worked as expected.
  • 400
    Bad Request - The request was unacceptable, often due to missing a required parameter.
  • 401
    Unauthorized - No valid API key provided.
  • 402
    Payment Required - You have exhausted your token balance.
  • 429
    Too Many Requests - You have hit your rate limit.