API Documentation

Last updated: October 30, 2025

Introduction

Welcome to the Key2Prompt API documentation. This guide will help you integrate Key2Prompt's prompt generation capabilities into your applications and services. Our API is designed to be simple, RESTful, and easy to use.

The Key2Prompt API allows you to programmatically generate prompts based on keywords, enabling automated content generation workflows for your applications.

Authentication

All API requests require authentication using your personal API key. Your API key must be included in the request headers to authenticate your requests.

Getting Your API Key

  1. Log in to your Key2Prompt account or sign up if you don't have one
  2. Navigate to your Settings page
  3. Find the "API Key Management" section where your unique API key is displayed
  4. Click the copy button to copy your API key to the clipboard
  5. You can regenerate your API key at any time if needed (this will invalidate the old key)

Security Notice: Keep your API key secure and never share it publicly. Treat it like a password. If you believe your API key has been compromised, regenerate it immediately from your Settings page.

API Endpoint

The Key2Prompt API is accessible at the following base URL:

https://www.key2prompt.com

Generate Prompt

Generate a prompt based on a keyword or short phrase.

Endpoint:

POST /api/prompt/generate

Request Format

The API uses a unique approach where authentication and prompt data are passed through HTTP headers rather than the request body.

Required Headers:

  • APIKey - Your personal API key (string)
  • prompt - The keyword or phrase to generate a prompt from (string)
  • Content-Type - Set to application/json

Response Format

Successful requests return a JSON object containing the generated prompt.

Success Response (200 OK):

{
  "success": true,
  "prompt": "Generated prompt text based on your keyword",
  "keyword": "your-keyword",
  "timestamp": "2025-10-30T22:28:27.627Z"
}

Code Examples

Here are examples of how to use the Key2Prompt API in different programming languages:

cURL

bash
curl -X POST https://api.key2prompt.com/api/prompt/generate \
  -H "Content-Type: application/json" \
  -H "APIKey: your-api-key-here" \
  -H "prompt: your keyword or phrase" \
  -d '{}'

JavaScript/Node.js

javascript
// Using fetch (Browser/Node.js 18+)
const apiKey = 'your-api-key-here';
const keyword = 'your keyword or phrase';

const response = await fetch('https://api.key2prompt.com/api/prompt/generate', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'APIKey': apiKey,
    'prompt': keyword
  },
  body: JSON.stringify({})
});

const data = await response.json();
console.log('Generated prompt:', data.prompt);

// Using axios
const axios = require('axios');

const apiKey = 'your-api-key-here';
const keyword = 'your keyword or phrase';

try {
  const response = await axios.post(
    'https://api.key2prompt.com/api/prompt/generate',
    {},
    {
      headers: {
        'Content-Type': 'application/json',
        'APIKey': apiKey,
        'prompt': keyword
      }
    }
  );
  
  console.log('Generated prompt:', response.data.prompt);
} catch (error) {
  console.error('Error:', error.response?.data || error.message);
}

Python

python
import requests

api_key = 'your-api-key-here'
keyword = 'your keyword or phrase'

headers = {
    'Content-Type': 'application/json',
    'APIKey': api_key,
    'prompt': keyword
}

response = requests.post(
    'https://api.key2prompt.com/api/prompt/generate',
    headers=headers,
    json={}
)

if response.status_code == 200:
    data = response.json()
    print(f"Generated prompt: {data['prompt']}")
else:
    print(f"Error: {response.status_code} - {response.text}")

PHP

php
<?php

$apiKey = 'your-api-key-here';
$keyword = 'your keyword or phrase';

$ch = curl_init('https://api.key2prompt.com/api/prompt/generate');

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([]));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'APIKey: ' . $apiKey,
    'prompt: ' . $keyword
]);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($httpCode === 200) {
    $data = json_decode($response, true);
    echo "Generated prompt: " . $data['prompt'];
} else {
    echo "Error: " . $httpCode . " - " . $response;
}

?>

Rate Limits

API rate limits vary based on your subscription plan:

  • Free Plan:
    • 100 requests per day
    • 3,000 requests per month
  • Standard Plan ($4/month):
    • Higher daily and monthly limits
  • Premium Plan ($10/month):
    • 300 requests per day
    • 9,000 requests per month

When you exceed your rate limit, the API will return a 429 (Too Many Requests) status code. Consider implementing exponential backoff in your application to handle rate limiting gracefully.

Error Handling

The API uses standard HTTP status codes to indicate success or failure:

  • 200 OK: Request succeeded
  • 400 Bad Request: Invalid request parameters or missing headers
  • 401 Unauthorized: Invalid or missing API key
  • 403 Forbidden: API key doesn't have permission to access this resource
  • 429 Too Many Requests: Rate limit exceeded
  • 500 Internal Server Error: Server-side error occurred

Error Response Format:

{
  "success": false,
  "error": "Error message describing what went wrong",
  "statusCode": 400
}

Best Practices

  • Secure Your API Key: Never expose your API key in client-side code or public repositories. Use environment variables or secure configuration management.
  • Implement Error Handling: Always handle API errors gracefully and provide meaningful feedback to your users.
  • Use HTTPS: Always use HTTPS when making API requests to ensure data is encrypted in transit.
  • Cache Responses: If you're generating prompts for the same keywords repeatedly, consider caching the results to reduce API calls.
  • Monitor Usage: Keep track of your API usage in the Profile page to avoid hitting rate limits unexpectedly.
  • Implement Retry Logic: Use exponential backoff when retrying failed requests, especially for 429 and 5xx errors.

Support

If you have questions about the API or need assistance: