Playground Sign in Start free
APIs

ChatGPT API

Automated browser interaction with ChatGPT to get AI-generated responses

Overview

The ChatGPT API endpoint automates interactions with ChatGPT's web interface, allowing you to submit prompts and receive AI-generated responses programmatically. This uses browser automation with human behavior simulation to interact naturally with ChatGPT.

WARNING — Browser Automation

This endpoint uses automated browser interactions with ChatGPT's web interface, not direct API calls. Response times are typically 10-30 seconds depending on prompt complexity.

Quick Start

Basic Request

curl -X GET "https://api.ujeebu.com/chatgpt?prompt=What%20is%20the%20capital%20of%20France%3F" \
  -H "ApiKey: YOUR_API_KEY"
const response = await fetch(
  'https://api.ujeebu.com/chatgpt?prompt=What+is+the+capital+of+France?',
  {
    headers: {
      'ApiKey': 'YOUR_API_KEY'
    }
  }
);

const data = await response.json();
console.log(data.conversation.messages);
import requests

response = requests.get(
    'https://api.ujeebu.com/chatgpt',
    params={'prompt': 'What is the capital of France?'},
    headers={'ApiKey': 'YOUR_API_KEY'}
)

data = response.json()
print(data['conversation']['messages'])
package main

import (
	"fmt"
	"io"
	"log"
	"net/http"
	"net/url"
)

func main() {
	baseURL := "https://api.ujeebu.com/chatgpt"
	params := url.Values{}
	params.Set("prompt", "What is the capital of France?")

	req, err := http.NewRequest("GET", baseURL+"?"+params.Encode(), nil)
	if err != nil {
		log.Fatal(err)
	}
	req.Header.Set("ApiKey", "YOUR_API_KEY")

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()

	body, _ := io.ReadAll(resp.Body)
	fmt.Println(string(body))
}

Response

{
  "conversation": {
    "messages": [
      {
        "id": "msg-abc123",
        "role": "user",
        "content": "What is the capital of France?",
        "position": 0
      },
      {
        "id": "msg-def456",
        "role": "assistant",
        "content": "The capital of France is Paris. It's one of the most visited cities in the world...",
        "model": "gpt-4",
        "position": 1
      }
    ],
    "total_messages": 2,
    "user_messages": 1,
    "assistant_messages": 1
  },
  "metadata": {
    "prompt": "What is the capital of France?",
    "total_messages": 2,
    "user_messages": 1,
    "assistant_messages": 1
  },
  "recipe": "ChatGPT"
}

Request Parameters

Required Parameters

Parameter Type Required Default Description
prompt string Yes - The question or prompt to send to ChatGPT. URL-encode special characters.

Optional Parameters

Parameter Type Required Default Description
wait_for_load boolean No true Wait for page to fully load before interaction.
timeout number No 60000 Maximum time to wait for response in milliseconds (60 seconds).
enable_web_search boolean No false Enable ChatGPT's web search capability for up-to-date information.
return_html boolean No false Include the full page HTML in the response.

Response Format

Conversation Object

The response contains a conversation object with all messages exchanged:

{
  "conversation": {
    "messages": [
      {
        "id": "msg-abc123",
        "role": "user",
        "content": "Your prompt",
        "position": 0
      },
      {
        "id": "msg-def456",
        "role": "assistant",
        "content": "ChatGPT's response",
        "model": "gpt-4",
        "position": 1
      }
    ],
    "total_messages": 2,
    "user_messages": 1,
    "assistant_messages": 1
  }
}

Message Fields

Field Type Description
id string Unique message identifier
role string user or assistant
content string Message text content
model string Model used (assistant messages only, omitted if empty)
position int Zero-based position in the conversation

Metadata

Additional information about the interaction:

{
  "metadata": {
    "prompt": "Original prompt text",
    "total_messages": 2,
    "user_messages": 1,
    "assistant_messages": 1
  }
}

Use Cases

1. Content Generation

Generate articles, blog posts, or marketing copy:

GET /chatgpt?prompt=Write%20a%20short%20blog%20post%20about%20web%20scraping

2. Question Answering

Get detailed answers to complex questions:

GET /chatgpt?prompt=Explain%20how%20machine%20learning%20works%20in%20simple%20terms

3. Code Generation

Request code snippets or explanations:

GET /chatgpt?prompt=Write%20a%20Python%20function%20to%20scrape%20a%20website

4. Data Analysis

Ask for analysis or insights:

GET /chatgpt?prompt=What%20are%20the%20key%20trends%20in%20AI%20for%202024%3F

5. Creative Writing

Generate creative content:

GET /chatgpt?prompt=Write%20a%20short%20story%20about%20a%20robot%20learning%20to%20cook

Examples

Example 1: Simple Question

curl -X GET "https://api.ujeebu.com/chatgpt?prompt=What%20is%20artificial%20intelligence%3F" \
  -H "ApiKey: YOUR_API_KEY"
const response = await fetch('https://api.ujeebu.com/chatgpt?' + new URLSearchParams({
  prompt: 'What is artificial intelligence?'
}), {
  headers: {
    'ApiKey': 'YOUR_API_KEY'
  }
});

const data = await response.json();
const answer = data.conversation.messages.find(
  msg => msg.role === 'assistant'
).content;

console.log(answer);
import requests

response = requests.get(
    'https://api.ujeebu.com/chatgpt',
    params={'prompt': 'What is artificial intelligence?'},
    headers={'ApiKey': 'YOUR_API_KEY'}
)

data = response.json()
assistant_message = next(
    msg for msg in data['conversation']['messages']
    if msg['role'] == 'assistant'
)

print(assistant_message['content'])
package main

import (
	"encoding/json"
	"fmt"
	"io"
	"log"
	"net/http"
	"net/url"
)

func main() {
	baseURL := "https://api.ujeebu.com/chatgpt"
	params := url.Values{}
	params.Set("prompt", "What is artificial intelligence?")

	req, err := http.NewRequest("GET", baseURL+"?"+params.Encode(), nil)
	if err != nil {
		log.Fatal(err)
	}
	req.Header.Set("ApiKey", "YOUR_API_KEY")

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()

	body, _ := io.ReadAll(resp.Body)

	var result map[string]interface{}
	json.Unmarshal(body, &result)
	fmt.Println(result)
}

Example 2: Content Generation with Timeout

curl -X GET "https://api.ujeebu.com/chatgpt?prompt=Write%20a%20product%20description%20for%20wireless%20headphones&timeout=90000" \
  -H "ApiKey: YOUR_API_KEY"
const response = await fetch('https://api.ujeebu.com/chatgpt?' + new URLSearchParams({
  prompt: 'Write a product description for wireless headphones',
  timeout: '90000'
}), {
  headers: {
    'ApiKey': 'YOUR_API_KEY'
  }
});

const data = await response.json();
console.log(data.conversation.messages.at(-1).content);
import requests

response = requests.get(
    'https://api.ujeebu.com/chatgpt',
    params={
        'prompt': 'Write a product description for wireless headphones',
        'timeout': 90000  # 90 seconds
    },
    headers={'ApiKey': 'YOUR_API_KEY'}
)

data = response.json()
print(data['conversation']['messages'][-1]['content'])
package main

import (
	"fmt"
	"io"
	"log"
	"net/http"
	"net/url"
)

func main() {
	baseURL := "https://api.ujeebu.com/chatgpt"
	params := url.Values{}
	params.Set("prompt", "Write a product description for wireless headphones")
	params.Set("timeout", "90000")

	req, err := http.NewRequest("GET", baseURL+"?"+params.Encode(), nil)
	if err != nil {
		log.Fatal(err)
	}
	req.Header.Set("ApiKey", "YOUR_API_KEY")

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()

	body, _ := io.ReadAll(resp.Body)
	fmt.Println(string(body))
}

Best Practices

Prompt Engineering

Be Specific:

  • ❌ "Tell me about dogs"
  • ✅ "List 5 interesting facts about Golden Retrievers"

Provide Context:

  • ❌ "Write code"
  • ✅ "Write a Python function that validates email addresses using regex"

Set Format Expectations:

  • ✅ "Explain in bullet points"
  • ✅ "Write in a professional tone"
  • ✅ "Keep response under 200 words"

Timeout Management

  • Simple questions: Default 60 seconds is sufficient
  • Complex analysis: Increase to 90-120 seconds
  • Long-form content: May need up to 180 seconds
// Adjust timeout based on task complexity
const timeout = promptLength > 500 ? 120000 : 60000;

Error Handling

Always implement retry logic for transient errors:

async function askChatGPT(prompt, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      const response = await fetch(
        `https://api.ujeebu.com/chatgpt?prompt=${encodeURIComponent(prompt)}`,
        { headers: { 'ApiKey': 'YOUR_API_KEY' } }
      );

      if (response.ok) {
        return await response.json();
      }
    } catch (error) {
      if (i === maxRetries - 1) throw error;
      await new Promise(resolve => setTimeout(resolve, 2000 * (i + 1)));
    }
  }
}

Error Handling

Common Errors

Input Not Found:

{
  "error": "Could not find ChatGPT input - retrying..."
}

Solution: Automatic retry. If persists, check if ChatGPT interface has changed.

Response Timeout:

{
  "error": "Timeout waiting for ChatGPT response - retrying..."
}

Solution: Increase timeout parameter or simplify prompt.

No Response Detected:

{
  "error": "No response detected from ChatGPT - retrying..."
}

Solution: Automatic retry. May indicate temporary ChatGPT unavailability.

Missing Prompt:

{
  "error": "Please provide 'prompt' parameter"
}

Solution: Ensure prompt parameter is included in request.

Retry Strategy

The endpoint automatically retries on transient errors:

Error Type Auto Retry Recommended Action
Input not found Yes Wait for retry
Submit button not found Yes Wait for retry
Response timeout Yes Consider increasing timeout
No response detected Yes Wait for retry
Authentication error No Check proxy settings

Credits & Billing

Credit Costs

Operation Credits
ChatGPT prompt submission 0 credits (no credit cost configured)
Additional retries 0 credits (included)

INFO — Credit Cost

The ChatGPT endpoint currently has no credit cost configured in the backend. This may change in the future.

Billing Notes

  • Credits are not currently charged for ChatGPT requests
  • Automatic retries don't consume additional credits
  • Response length doesn't affect credit cost

Cost Optimization

Batch Similar Queries:

// Instead of multiple simple requests
const prompts = [
  "What is AI?",
  "What is ML?",
  "What is NLP?"
];

// Combine into one request
const combinedPrompt = "Briefly explain: 1) AI, 2) ML, 3) NLP";

Cache Common Responses:

const cache = new Map();

async function getChatGPTResponse(prompt) {
  if (cache.has(prompt)) {
    return cache.get(prompt);
  }

  const response = await fetchChatGPT(prompt);
  cache.set(prompt, response);
  return response;
}

Technical Details

Authentication

Authentication is managed automatically using browser profiles with valid ChatGPT sessions. No additional API keys or ChatGPT Plus subscription required from your end.

Human Behavior Simulation

The endpoint includes:

  • Natural mouse movements
  • Random delays between actions
  • Human-like typing patterns
  • Page scrolling and interaction

This ensures reliable operation and reduces detection risk.

Response Times

Typical response times:

  • Page load: 3-5 seconds
  • Prompt submission: 1-2 seconds
  • Response generation: 5-20 seconds
  • Total: 10-30 seconds

Longer prompts or complex requests may take up to 60 seconds.

Next Steps

Ready to build?

Spin up an API key in 60 seconds

Free tier: 5,000 credits, no card, full access to every endpoint on this page.