You run a small business, and every day you get the same questions: "How long for delivery?", "Can I return this?". Or you need to generate product descriptions for 200 items. The solution isn't hiring more people—it's the ChatGPT API.
We are Meteora Web, a digital agency from Sciacca, Sicily. We've been integrating OpenAI's APIs into real projects for years, from e-commerce chatbots to automated invoice data extraction. This guide is practical: it shows how to connect the ChatGPT API to your web app, with working code, transparent costs, and no buzzwords.
How does the ChatGPT API work for a web app?
The ChatGPT API is a simple HTTP endpoint. You send a POST request with a list of messages (system, user, assistant) and receive a JSON response. No UI, no SDK magic—just JSON in, JSON out.
Minimal example with cURL
curl https://api.openai.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-4o-mini",
"messages": [
{"role": "system", "content": "You are a helpful assistant for an Italian SME. Answer concisely in Italian."},
{"role": "user", "content": "What is the return policy for shoes?"}
],
"max_tokens": 300,
"temperature": 0.5
}'
The response contains the model's reply in choices[0].message.content. That's it. Never expose your API key on the client side—always keep it server-side.
Sponsored Protocol
How much does it cost to integrate the ChatGPT API?
Cost depends on token usage. With gpt-4o-mini, input costs ~$0.15/1M tokens, output ~$0.60/1M. A typical support conversation (300 tokens) costs $0.00018. For 1000 conversations per month, that's $0.18.
With gpt-4o, it's about 15x more expensive. For most small businesses, gpt-4o-mini is more than enough. Always set a monthly spending limit (e.g., $20) in your OpenAI dashboard to avoid surprises.
Sponsored Protocol
How to integrate the ChatGPT API in a PHP/Laravel web app?
We use Laravel daily. Here's a clean service class using Guzzle:
use Illuminate\Support\Facades\Http;
class ChatGPTService
{
protected string $apiKey;
protected string $model;
public function __construct()
{
$this->apiKey = config('services.openai.api_key');
$this->model = 'gpt-4o-mini';
}
public function ask(string $systemPrompt, string $userMessage): string
{
$response = Http::withHeaders([
'Authorization' => 'Bearer ' . $this->apiKey,
'Content-Type' => 'application/json',
])->post('https://api.openai.com/v1/chat/completions', [
'model' => $this->model,
'messages' => [
['role' => 'system', 'content' => $systemPrompt],
['role' => 'user', 'content' => $userMessage],
],
'max_tokens' => 500,
'temperature' => 0.7,
]);
if ($response->failed()) {
throw new \Exception('OpenAI API error: ' . $response->body());
}
return $response->json('choices.0.message.content');
}
}
What can you automate with a few API endpoints?
- Auto-generate meta descriptions and SEO content for your CMS.
- Build a WhatsApp bot that answers customer queries (integrate with Twilio or WhatsApp Business API).
- Extract structured data from scanned invoices (send OCR text, ask ChatGPT to return JSON with supplier, total, VAT).
- Moderate user reviews by asking the API: "Is this review offensive or spam? Reply only YES or NO."
How to handle security and rate limiting?
- Never expose the API key in frontend JavaScript. Proxy all requests through your server.
- Rate-limit endpoints per user/IP (using Laravel's throttle middleware).
- Sanitize user input to prevent prompt injection.
- Set a hard spending cap on your OpenAI account.
// Laravel route with throttle: 10 requests per minute
Route::middleware(['throttle:10,1'])->post('/support', [SupportController::class, 'ask']);
How to monitor costs and quality?
Log every API call: timestamp, model, token counts, cost. Use this data to create a monthly ROI report. For quality, manually review a sample of responses and adjust the system prompt.
Sponsored Protocol
What to do now
- Get an API key from platform.openai.com. Set a $20 spending limit.
- Test the cURL example above. Tweak the system prompt.
- Implement the service in your stack (PHP, Node.js, Python). Start with a small use case.
- Connect it to a real workflow: a contact form, a product description generator, or a chat widget.
- Measure results: hours saved vs API cost.
Need help integrating the ChatGPT API? Contact us or check our main guide on ChatGPT for professionals.