OpenAI provides a variety of API endpoints for interacting with their models, including those for text generation, embeddings, fine-tuning, and more. Here are some key endpoints you can use:
-
Completions: For generating text based on a prompt.
- Endpoint:
POST https://api.openai.com/v1/engines/{engine_id}/completions
- Example:
{ "model": "text-davinci-003", "prompt": "Once upon a time,", "max_tokens": 100, "temperature": 0.7 }
- Endpoint:
-
Chat Completions: For generating conversational text, useful for chatbots.
- Endpoint:
POST https://api.openai.com/v1/chat/completions
- Example:
{ "model": "gpt-4", "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Tell me a joke."} ] }
- Endpoint:
-
Edits: For editing text based on instructions.
- Endpoint:
POST https://api.openai.com/v1/edits
- Example:
{ "model": "text-davinci-edit-001", "input": "What day of the wek is it?", "instruction": "Fix the spelling mistakes." }
- Endpoint:
-
Embeddings: For generating vector representations of text.
- Endpoint:
POST https://api.openai.com/v1/embeddings
- Example:
{ "model": "text-embedding-ada-002", "input": "OpenAI is creating a new model." }
- Endpoint:
-
Moderation: For detecting unsafe content.
- Endpoint:
POST https://api.openai.com/v1/moderations
- Example:
{ "input": "I want to hurt someone." }
- Endpoint:
-
Fine-tuning: For fine-tuning models on your own data.
- Endpoint:
POST https://api.openai.com/v1/fine-tunes
- Example:
{ "training_file": "file-abc123", "model": "davinci" }
- Endpoint:
-
Files: For managing files used in fine-tuning.
- Upload a file:
POST https://api.openai.com/v1/files
- List files:
GET https://api.openai.com/v1/files
- Delete a file:
DELETE https://api.openai.com/v1/files/{file_id}
- Upload a file:
-
Models: For listing and retrieving available models.
- List models:
GET https://api.openai.com/v1/models
- Retrieve a model:
GET https://api.openai.com/v1/models/{model_id}
- List models:
All requests to these endpoints require an API key, which should be included in the request header:
Authorization: Bearer YOUR_API_KEY