Skip to content

Instantly share code, notes, and snippets.

@decagondev
Created May 21, 2024 01:19
Show Gist options
  • Save decagondev/f6a442c26f824f0567a8e383ecaa97fe to your computer and use it in GitHub Desktop.
Save decagondev/f6a442c26f824f0567a8e383ecaa97fe to your computer and use it in GitHub Desktop.
Open AI Api Endpoints

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:

  1. 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
      }
  2. 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."}
        ]
      }
  3. 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."
      }
  4. 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."
      }
  5. Moderation: For detecting unsafe content.

    • Endpoint: POST https://api.openai.com/v1/moderations
    • Example:
      {
        "input": "I want to hurt someone."
      }
  6. 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"
      }
  7. 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}
  8. 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}

Authentication

All requests to these endpoints require an API key, which should be included in the request header:

Authorization: Bearer YOUR_API_KEY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment