Skip to main content
K
VI

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.

Các bài viết liên quan

  1. Bài 3: Mẹo và giới hạn khi dùng Codex
  2. Lesson 3: Tips and limits when using Codex
  3. Bài 2: Sử dụng API Codex