Development
ChatGPT API Complete Guide: Build AI Apps in Any Language
The ChatGPT API is the most powerful and accessible AI API available. This complete guide shows you how to integrate it into your projects.
2026-06-2820 min readLearnGeni AI Academy
ChatGPT API संपूर्ण गाइड: AI एप्लिकेशन बनाएं
OpenAI API (ChatGPT API) किसी भी एप्लिकेशन में AI इंटीग्रेट करने का प्रवेश द्वार है।
API Key कैसे पाएं
- platform.openai.com पर जाएं
- अकाउंट बनाएं या लॉगिन करें
- API Keys → Create new secret key पर क्लिक करें
- Key कॉपी करें — यह दोबारा नहीं दिखाई देगी
इंस्टॉलेशन
pip install openai python-dotenv
.env फ़ाइल:
OPENAI_API_KEY=sk-आपकी-key-यहां
पहला API कॉल
from openai import OpenAI
from dotenv import load_dotenv
load_dotenv()
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "आप हिंदी में एक सहायक हैं।"},
{"role": "user", "content": "आर्टिफिशियल इंटेलिजेंस क्या है?"}
]
)
print(response.choices[0].message.content)
मेमोरी के साथ चैटबॉट
from openai import OpenAI
client = OpenAI()
messages = [{"role": "system", "content": "आप ग्राहक सेवा सहायक हैं।"}]
def chat(user_input: str) -> str:
messages.append({"role": "user", "content": user_input})
response = client.chat.completions.create(model="gpt-4o-mini", messages=messages)
reply = response.choices[0].message.content
messages.append({"role": "assistant", "content": reply})
return reply
print(chat("नमस्ते, मेरे ऑर्डर में समस्या है"))
print(chat("ऑर्डर नंबर #12345 है"))
लागत अनुकूलन
| मॉडल | इनपुट लागत (1M टोकन) | आउटपुट लागत | उपयोग |
|---|---|---|---|
| gpt-4o-mini | $0.15 | $0.60 | दैनिक कार्य |
| gpt-4o | $2.50 | $10.00 | जटिल कार्य |
OpenAI API में महारत हासिल करना चाहते हैं? LearnGeni का संपूर्ण ChatGPT API गाइड में वास्तविक प्रोजेक्ट शामिल हैं। सभी गाइड देखें।
G
Earn Your International AI Certificate
This article is part of the LearnGeni AI Mastery Program — 30 comprehensive guides in 50+ languages. Complete all 30 and earn a certificate backed by WhatsGeni (Official Meta AI Partner), recognized in 50+ countries.
🌍
50+ Languages
Learn in your native language
🏆
Official Certificate
Backed by Meta AI Partner
💡
30 Guides
$5 each or $50 for the full bundle