API Documentation

API Instructions

Getting Started

To use the Prompt Inspector API, follow these steps:

  1. Sign up for an account and create a project to obtain your API key.
  2. Use the endpoint and headers specified below for all requests.
  3. Send your prompt data in the correct format.
  4. Handle potential errors to ensure your application's stability.

Endpoint

Send a POST request to:

https://promptinspector.com/api/prompt

Headers

  • Content-Type: application/json
  • x-api-key: YOUR_API_KEY

Request Body

{
  "data": {
    "prompt": "User's input or question",
    "identifier": "user@example.com"
  }
}

Response

The API will respond with a JSON object containing:

  • A success message
  • The saved prompt data, including generated tags
{
  "message": "Prompt saved successfully",
  "prompt": {
    "id": "prompt_id",
    "projectId": "project_id",
    "prompt": "User's input or question",
    "identifier": "user@example.com",
    "tags": [
      {
        "id": "tag_id",
        "name": "tag_name"
      }
    ],
    "createdAt": "2023-04-20T12:34:56.789Z"
  }
}

Error Handling

The API may return error responses. Always handle these errors in your application to prevent crashes. Common error scenarios include:

  • 401 Unauthorized: Invalid API key
  • 403 Forbidden: Request limit reached
  • 500 Internal Server Error: Server-side issues

Implement proper error handling as shown in the examples below.

Examples

import axios from 'axios';

const apiKey = 'YOUR_API_KEY';
const apiUrl = 'https://promptinspector.com/api/prompt';

async function sendPrompt(message, userIdentifier) {
  try {
    const response = await axios.post(apiUrl, {
      data: {
        prompt: message,
        identifier: userIdentifier,
      }
    }, {
      headers: {
        'Content-Type': 'application/json',
        'x-api-key': apiKey,
      },
    });
    console.log(response.data);
    return response.data;
  } catch (error) {
    console.error('Error:', error.response ? error.response.data : error.message);
    // Handle the error appropriately
  }
}

Note: Replace YOUR_API_KEY with the API key obtained from your project settings.