Making Your First API Call: Send a Prompt to GPT-4 ✉️

Advanced

With your API key ready, the next step is making your first request. Using tools like cURL, Postman, or programming languages such as Python, you can send prompts to GPT-4 to generate responses. Here's a simple Python example using the requests library:

import requests
api_key = 'your-api-key'
headers = {
    'Authorization': f'Bearer {api_key}',
    'Content-Type': 'application/json'
}
data = {
    'model': 'gpt-4',
    'prompt': 'Explain blockchain technology in simple terms.',
    'max_tokens': 200,
    'temperature': 0.7
}
response = requests.post('https://api.openai.com/v1/completions', headers=headers, json=data)
print(response.json()['choices'][0]['text'].strip())

This script sends a prompt and prints the generated response. Parameters like max_tokens and temperature control output length and creativity. Think of the API as a language engine: you feed it prompts, and it responds with generated text based on learned patterns.