Repository navigation
API AI
Caligrafy Quill 2.26.0. Generated from the source by
php qa/build-api-reference.php; the guides explain how to use these classes, this reference says exactly what each public method takes and returns. Back to the API reference.
OpenAI, open models through OpenAI-compatible providers, the OpenAI Assistants and Watson.
| Class | What it is |
|---|---|
Caligrafy\OpenAI |
The OpenAI class handles all exchanges with the OpenAI models (text and images) |
Caligrafy\Agent |
The Agent class talks to open models through OpenAI-compatible providers: Groq (default, through groq-php), Together AI, Fireworks AI, OpenRouter, a local Ollama or any custom endpoint. |
Caligrafy\Assistant |
The Assistant class runs conversations with OpenAI models through the Responses and Conversations APIs. |
Caligrafy\Watson |
The Watson class handles all exchanges with the Watson Assistant |
namespace Caligrafy;
class OpenAI extends \stdClassSource: framework/core/OpenAI.php:22
The OpenAI class handles all exchanges with the OpenAI models (text and images)
-
COMMANDS = array('CONVERSE', 'SUMMARIZE', 'ANALYZE', 'CORRECT', 'CLASSIFY', 'COMPLETE', 'PREDICT', 'RECOMMEND', 'CUSTOM'): Commands that delegate() accepts, by name (case insensitive) -
TYPES = array('TEXT', 'IMAGE'): Model types that the constructor accepts, by name (case insensitive)
-
public $type: string the OpenAI model type: text or image -
public $parameters: string the OpenAI model parameters -
public $context: array conversation context -
public $attachments: string the OpenAI file attachments necessary for fine-tuning models
public static function command($name)Resolves a command name (ex: 'summarize' from a form) to its prompt. Returns null for anything else, so that user input can never select another constant (such as APP_KEY or DB_PASSWORD)
Parameters
$name
Source: framework/core/OpenAI.php:38
public static function type($name)Resolves a model type name ('text' or 'image') to its configuration. Returns null for anything else
Parameters
$name
Source: framework/core/OpenAI.php:47
public function __construct($mode = TEXT)No doc comment.
Parameters
-
$mode, defaultTEXT
Source: framework/core/OpenAI.php:87
public function converse(
$parameters = array(),
$attachments = array(),
$method = 'POST',
$additionalHeaders = array()
)General method to command the AI to converse in text parameters:
- For type text: array of model, prompt/input, instructions, temperature, tokens, max_tokens, top_p, frequency_penalty
- For type image: array of prompt, n, size
attachments:
- For type image: array("image" => uri to image)
method: POST, GET, PUT, DELETE. default is POST additionalHeaders: array of request headers to complement default
Parameters
-
$parameters, defaultarray() -
$attachments, defaultarray() -
$method, default'POST' -
$additionalHeaders, defaultarray()
Source: framework/core/OpenAI.php:109
public function delegate(
$input = '',
$outcome = '',
$command = ANALYZE,
$context = array(),
$parameters = array()
)No doc comment.
Parameters
-
$input, default'' -
$outcome, default'' -
$command, defaultANALYZE -
$context, defaultarray() -
$parameters, defaultarray()
Source: framework/core/OpenAI.php:115
namespace Caligrafy;
class Agent extends \stdClassSource: framework/core/Agent.php:33
The Agent class talks to open models through OpenAI-compatible providers: Groq (default, through groq-php), Together AI, Fireworks AI, OpenRouter, a local Ollama or any custom endpoint.
Choose the provider in .env with AGENT_PROVIDER (groq|together|fireworks|openrouter|ollama|custom). Key: the provider key (GROQ_API_KEY, TOGETHER_API_KEY, FIREWORKS_API_KEY, OPENROUTER_API_KEY) or AGENT_API_KEY. AGENT_API_BASE overrides the endpoint (required for custom), AGENT_MODEL and AGENT_VISION_MODEL the default models. The GROQ_* settings and constants keep working as before.
Groq keeps groq-php: its audio endpoints (multipart uploads) and behavior stay unchanged. The other providers only need chat completions and the model list, sent with cURL (no extra dependency).
-
PROVIDERS = ...: Providers: label, default endpoint, key setting, default models (October 2026), audio support, where to get a key and where the models are listed. Ollama needs no key; custom needs AGENT_API_BASE and AGENT_MODEL. Serverless Llama (October 2026): OpenRouter and Ollama only. Groq retired its Llama chat models in August 2026, Together and Fireworks only serve Llama on dedicated/on-demand deployments: their defaults are gpt-oss-120b. Preview models: Groq qwen/qwen3.8-27b. TIMEOUT = 120
->__construct()Agent::settings()Agent::setting()->provider()->model()->visionModel()->configure()->delegate()->visualize()->transcribe()->translate()->models()Agent::modelIds()
public function __construct($apiKey = "", $provider = "", $baseUrl = "")apiKey: optional key, otherwise taken from .env provider: optional provider name, otherwise AGENT_PROVIDER (default groq) baseUrl: optional endpoint, otherwise AGENT_API_BASE or the provider default
Parameters
-
$apiKey, default"" -
$provider, default"" -
$baseUrl, default""
Source: framework/core/Agent.php:92
public static function settings($get = null, $provider = "", $baseUrl = "")Resolves the provider settings from .env (or from $get, a function that returns a setting by name: used by doctor)
Parameters
-
$get, defaultnull -
$provider, default"" -
$baseUrl, default""
Returns array: provider, label, base, baseOverride, key, keyName, model, vision
Source: framework/core/Agent.php:118
public static function setting($name)Reads a setting: $_ENV (filled from .env), then the constant of the same name, then getenv()
Parameters
$name
Source: framework/core/Agent.php:147
public function provider()Provider in use (groq, together, fireworks, openrouter, ollama or custom)
Source: framework/core/Agent.php:156
public function model()Default text model of the provider (AGENT_MODEL, GROQ_MODEL for Groq, or the built-in default)
Source: framework/core/Agent.php:164
public function visionModel()Default vision model of the provider (AGENT_VISION_MODEL, GROQ_VISION_MODEL for Groq, or the built-in default)
Source: framework/core/Agent.php:172
public function configure($parameters = array())Set configuration of Agent parameters include: temperature, max_tokens etc. They are added to every delegate() and visualize() request.
Parameters
-
$parameters, defaultarray()
Source: framework/core/Agent.php:181
public function delegate(
$model = "",
$messages = array(),
$response_format = array(),
$stream = false,
$tool_choice = "",
$tools = array()
)Create a text prompt for agent model: specify the model of the provider (default: model()) messages: array of role (system, user) and content response_format: array of types i.e ['type' => 'json_object'] stream: set to true if streaming response is expected. Check documentation for fetching results tool_choice: set to "auto" when tools are used tools: array of tool definition (OpenAI format)
Parameters
-
$model, default"" -
$messages, defaultarray() -
$response_format, defaultarray() -
$stream, defaultfalse -
$tool_choice, default"" -
$tools, defaultarray()
Source: framework/core/Agent.php:196
public function visualize($file = "", $prompt = "Describe this image", $model = "")Vision file: file path (or a public image URL that the provider downloads) prompt: what to do with image model: a vision model of the provider (default: visionModel())
Parameters
-
$file, default"" -
$prompt, default"Describe this image" -
$model, default""
Source: framework/core/Agent.php:246
public function transcribe(
$file = "",
$prompt = "",
$model = GROQ_TRANSCRIPTION_MODEL,
$language = "en",
$response_format = "json"
)Audio Transcribe (Groq only) file: file path model: specify model to use response_format: string. 'json' language: specify language of audio prompt: string of an optional transcription prompt
Parameters
-
$file, default"" -
$prompt, default"" -
$model, defaultGROQ_TRANSCRIPTION_MODEL -
$language, default"en" -
$response_format, default"json"
Source: framework/core/Agent.php:283
public function translate(
$file = "",
$prompt = "",
$model = GROQ_TRANSCRIPTION_MODEL,
$response_format = "json"
)Audio Translate (Groq only) file: file path model: specify model to use response_format: string. 'json' prompt: string of an optional transcription prompt
Parameters
-
$file, default"" -
$prompt, default"" -
$model, defaultGROQ_TRANSCRIPTION_MODEL -
$response_format, default"json"
Source: framework/core/Agent.php:304
public function models()Models of the provider (for Ollama: the models pulled on the server)
Returns array: ['api_success' => true, 'response' => sorted list of model ids] or ['api_success' => false, 'response' => error]
Source: framework/core/Agent.php:321
public static function modelIds($json)Model ids of a GET /models answer: {data: [...]} (OpenAI, Groq, OpenRouter, Ollama /v1/models), a bare list (Together), or {models: [{name}]} (Ollama /api/tags, Fireworks account models). Models marked inactive (Groq) are left out.
Parameters
$json
Returns array|null: sorted ids, null when the answer is not a model list
Source: framework/core/Agent.php:336
namespace Caligrafy;
class Assistant extends \stdClassSource: framework/core/Assistant.php:29
The Assistant class runs conversations with OpenAI models through the Responses and Conversations APIs.
OpenAI shut down the Assistants API on August 26, 2026. Version 2.0 of this class keeps the same chainable methods (start, createMessage, run, retrieveResponse, end) on top of the APIs that replace it:
- the assistant (model, instructions, tools) is configuration kept in this object and sent with every response
- a conversation (POST /v1/conversations) replaces the thread
- a response (POST /v1/responses) replaces the run
- files are searched through a vector store (file_search tool)
-
public $name: string the name of the assistant (used for the vector store name and metadata) -
public $description: string what the assistant does (local description) -
public $instructions: string the instructions (system prompt) sent with every response -
public $tools = array(["type" => "file_search"]): array the tools: ["type" => "file_search"] is completed with the vector store, ["type" => "code_interpreter"] gets an automatic container with the uploaded files -
public $file_ids =[]: array ids of the files uploaded for the assistant -
public $file_paths =[]: array local paths of the files to upload -
public $metadata: array metadata sent with every response (up to 16 string pairs) -
public $vector_store_id = '': string the vector store that holds the files searched by file_search -
public $assistant_id = '': string kept for backward compatibility: the Assistants API no longer exists, nothing is created on OpenAI -
public $thread_id = '': string the active conversation id (conv_...). Kept under its old name for backward compatibility -
public $run_id = '': string the last response id (resp_...) -
public $status = 'queued': string the status of the last response: completed, failed, in_progress, queued, incomplete, cancelled -
public $messages =[]: array the messages of the conversation: the user messages added and the assistant messages received. Every message is ['id', 'role', 'content' => 'type' => 'input_text'] -
public $response_text = '': string the text of the last assistant answer -
public $last_response =[]: array the last raw response returned by OpenAI (useful for errors and usage)
->__construct()->retrieve()->delete()->start()->end()->createMessage()->listMessages()->run()->retrieveResponse()->text()->uploadAssistantFiles()->deleteAssistantFile()
public function __construct($parameters = array())Configure an assistant parameters: name, description, instructions, model, tools, metadata, file_paths (uploaded to a new vector store), file_ids (already uploaded files), vector_store_id (existing vector store)
Parameters
-
$parameters, defaultarray()
Source: framework/core/Assistant.php:130
public function retrieve()Kept for backward compatibility: the assistant configuration lives in this object
Source: framework/core/Assistant.php:154
public function delete()Deletes the vector store created for the assistant (the uploaded files stay in the OpenAI file storage)
Source: framework/core/Assistant.php:162
public function start()Start the contextual conversation (POST /v1/conversations)
Source: framework/core/Assistant.php:177
public function end()Delete the contextual conversation
Source: framework/core/Assistant.php:189
public function createMessage($content, $file_ids =[], $metadata = null, $role = "user")Add a message to send with the next run() $file_ids: files given to the code interpreter for this message
Parameters
$content-
$file_ids, default[] -
$metadata, defaultnull -
$role, default"user"
Source: framework/core/Assistant.php:203
public function listMessages()Lists the items of the conversation (GET /v1/conversations/{id}/items), oldest first
Source: framework/core/Assistant.php:217
public function run(
$additional_instructions = '',
$instructions = null,
$tools =[],
$model = '',
$metadata = null
)Send the pending messages and get the answer (POST /v1/responses) The overrides apply to this response only
Parameters
-
$additional_instructions, default'' -
$instructions, defaultnull -
$tools, default[] -
$model, default'' -
$metadata, defaultnull
Source: framework/core/Assistant.php:226
public function retrieveResponse($timeout = 120, $interval = 2)Waits for the last response when it is still queued or in progress (background responses), polling GET /v1/responses/{id} every $interval seconds for at most $timeout seconds
Parameters
-
$timeout, default120 -
$interval, default2
Source: framework/core/Assistant.php:256
public function text()Returns the text of the last assistant answer
Source: framework/core/Assistant.php:272
public function uploadAssistantFiles($specified_paths =[])Uploads files (POST /v1/files) and adds them to the assistant's vector store for file_search
Parameters
-
$specified_paths, default[]
Returns array: the ids of the uploaded files
Source: framework/core/Assistant.php:281
public function deleteAssistantFile($file_id)Removes a file from the vector store and deletes it from the OpenAI file storage
Parameters
$file_id
Source: framework/core/Assistant.php:303
namespace Caligrafy;
class Watson extends \stdClassSource: framework/core/Watson.php:20
The Watson class handles all exchanges with the Watson Assistant
->__construct()->communicate()->getSessionId()->getContext()->getSkillVariables()->getContextVariable()->getConversation()->getLastExchange()->getResponse()->getExchangeAt()->closeSession()
public function __construct($watson_assistant_id, $environment_id = null).env settings:
- WATSON_API_KEY: the service API key
- WATSON_URL: the service instance URL, https://api.<region>.assistant.watson.cloud.ibm.com/instances/<instance_id>
- WATSON_ENVIRONMENT_ID (optional): the environment of the assistant (Environment settings > API details). Without it, the legacy /v2/assistants/<id>/sessions path is used
- WATSON_API_VERSION (optional): the API version date, 2024-08-25 by default
Parameters
$watson_assistant_id-
$environment_id, defaultnull
Source: framework/core/Watson.php:90
public function communicate($messageText, $skillVariables = null)Send Input to Watson
Parameters
-
$messageTextstring: to send to Watson -
$skillVariablesarray, defaultnull
Source: framework/core/Watson.php:124
public function getSessionId()Get Session ID
Returns the: current active session ID
Source: framework/core/Watson.php:157
public function getContext()Get Context
Returns the: current Context
Source: framework/core/Watson.php:170
public function getSkillVariables()Get Skill Variables
Returns the: skill variables
Source: framework/core/Watson.php:182
public function getContextVariable($variable)Get Context Variable
Parameters
$variable
Returns the: Context variable
Source: framework/core/Watson.php:196
public function getConversation()Get Context
Returns the: current Conversation
Source: framework/core/Watson.php:210
public function getLastExchange()Get Context
Returns the: last exchange
Source: framework/core/Watson.php:223
public function getResponse()Get Last Response
Returns the: last response
Source: framework/core/Watson.php:236
public function getExchangeAt($turnCount)Get conversation exchange at turn count
Parameters
-
$turnCountint: defines the turn count of the conversation
Returns array: the conversation exchange at turn count
Source: framework/core/Watson.php:251
public function closeSession()Close the Watson Session
Returns boolean: true if session closed successfully
Source: framework/core/Watson.php:265
Caligrafy: Describe it. Approve it. Ship it. Your idea turned into a complete app: every feature built once, for web pages, Vue apps, a REST API and AI agents, and online.
Why Caligrafy: the benefits, the measurements, and what it is not yet
-
Quickstart with Claude: describe it, approve it, ship it
or the Quickstart: the same three steps by hand, in 5 minutes
- How Caligrafy works: the ideas in 5 minutes
- Your first capability: build a feature, page included
-
Capabilities in depth
-
#[Capability]: every option - Scheduled jobs: capabilities on a timer
- Notifications: web push and email
- Background jobs: capabilities run later
- Migrations: database changes, in order
- The cache
-
Testing your app
- Dependency injection
- Validation rules
-
Web pages
- Views and page components
- Design styles: another look, one setting
- Declarative routes: every request, in one line
-
Route::page·Route::form·Route::auth·Route::webhook·Route::download·Route::redirect·Route::action·Route::snap· capability routes - How to export a list as CSV
- Controllers: moving one to a declared route · how to, step by step
- Forms and helpers
-
Vue apps
-
Mobile and tablet
-
REST API
-
AI agents
-
Snap Cards and the assistant
- Payments: Stripe and crypto
- Face detection and face login
- OpenAI: chat and images · Assistants
- Open models: Llama, Mistral...
- Chatbots with Watson
- Machine learning in the browser
- Metadata and social cards · search and analytics
-
Putting it online: the production image, the database at every start
-
API reference: every class and method
-
Routing ·
Route·AuthRoutes· pages ·Controller· capabilities -
Data ·
Model·Query· sign-in · jobs ·Notify· payments · AI -
Interfaces · Snap ·
Snap\Cards·Snap\Conversation· testing · tooling · helper functions
-
Routing ·
-
Caligrafer: every command
- Project · build · data · agents · jobs and tests · maintenance · deploy
- Installation, configuration and Caligrafer
- Routing · Request · Controllers · Views
- Vue: flow of information · routes · validations
- Security and upgrading
- Release notes: 2.26 · 2.25 · 2.24 · 2.23 · 2.22 · 2.21 · 2.20 · 2.19 · 2.18 · 2.17 · 2.16 · 2.15 · 2.14 · 2.13 · 2.12 · 2.11 · 2.10 · 2.9 · 2.8 · 2.7 · 2.6 · 2.5 · 2.4 · 2.3 · 2.1 · October 2026 · changelog
- Testing Caligrafy (contributors)