Language Guide · PHP
Manage AI Prompts in PHP
No SDK required. One HTTP call.
Fetch versioned, variable-interpolated AI prompts from PHP using built-in cURL or Guzzle. Works with Laravel, Symfony, WordPress, and any PHP application.
Code Example
One function. Any AI provider.
Fetch a versioned, interpolated prompt from PromptForge with a single HTTP call. The returned content string passes directly to your AI SDK — no transformation, no adapter, no extra library.
- 1Fetch a versioned prompt by ID with your variable values.
- 2Receive the fully rendered content string in the response.
- 3Pass it directly to your AI provider SDK as the system prompt.
<?php
function fetchPrompt(string $apiKey, string $promptId, array $vars = []): string
{
$query = http_build_query(array_merge(['_version' => 'latest'], $vars));
$url = "https://www.promptforge-app.com/api/v1/prompts/{$promptId}?{$query}";
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => ["Authorization: Bearer {$apiKey}"],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);
return $data['content'];
}
$content = fetchPrompt(
$_ENV['PROMPTFORGE_API_KEY'],
'YOUR_PROMPT_ID',
['role' => 'developer', 'task' => 'review code'],
);
// Pass $content to any AI SDKWhy PHP teams choose PromptForge
Designed for developers who want control without complexity.
Works in any PHP environment
Pure cURL — available in every PHP 5.4+ installation. No Composer packages required unless you prefer Guzzle.
Drop into any framework
Call it from a Laravel service class, a Symfony command, or a WordPress shortcode. One function, zero coupling to any framework abstraction.
Cache-friendly responses
The response is a plain string. Store it in Redis, Memcached, or Laravel cache for the duration of your version pin — avoid the round-trip on every page load.
Integrate in 4 steps
From zero to fetching your first versioned prompt in under 10 minutes. No framework setup, no SDK installation — just HTTP.
- 1
Create a prompt with variables
Open the dashboard, click New Prompt, and write your system prompt using {{variable}} placeholders for any dynamic values.
- 2
Copy your prompt ID
Your prompt ID appears in the URL bar when editing: /dashboard/prompts/YOUR_PROMPT_ID. The API Usage panel also shows it with pre-filled examples.
- 3
Generate an API key
Go to the API settings page and click Generate Key. Store it in your .env file and read it with $_ENV or getenv().
- 4
Fetch with cURL
A curl_init() call with CURLOPT_HTTPHEADER for the Bearer token. json_decode() the response and use $data['content'] with your AI provider client.
Teams building AI features in PHP
PHP agencies building AI-powered features for clients use PromptForge to keep prompts editable without touching production code. Laravel teams cache prompt responses per version number — paying the API cost once and serving thousands of AI requests from cache.
Start Free TrialStart for free, upgrade anytime
No credit card required to get started. Paid plans include a 14-day free trial.
- 1 Production Prompt
- 1,000 API Requests/mo
- Stable/Latest Channel Routing
- No Credit Card Required
No charge until your trial ends
- 10k API requests/month
- 5 prompt
- Unlimited versions
- Dynamic variables
- Version pinning
- API key management
No charge until your trial ends
- 100k API requests/month
- 25 prompt
- Unlimited versions
- Dynamic variables
- Version pinning
- API key management
No charge until your trial ends
- 500k API requests/month
- 100 prompt
- Unlimited versions
- Dynamic variables
- Version pinning
- API key management
Questions? Contact us