Lesson 2: Using the Codex API
To use Codex, create an API key in your OpenAI account. Then send requests to the v1/completions
endpoint using the code-davinci-002
model or a suitable version.
Example with curl
:
curl https://api.openai.com/v1/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "code-davinci-002",
"prompt": "Write a factorial function in Python",
"max_tokens": 100
}'
The response will contain the generated code. Adjust max_tokens
, temperature
and other parameters to tune the result.