AI Extraction
The AI Extraction settings enable automated prescription reading using vision-capable AI models through OpenRouter. When enabled, the AI can automatically extract values from prescription images that customers have uploaded, reducing manual data entry time and errors for your staff.
Overview
Section titled “Overview”AI extraction uses vision-capable language models to analyse prescription images uploaded by customers and automatically populate the prescription fields. It reads uploads in the lens wizard and on the upload link page, and staff can run it when reviewing and verifying prescription orders.
The system sends the uploaded prescription image along with configurable prompts to the AI model, which responds with structured JSON data containing the extracted prescription values.
Enable AI Extraction
Section titled “Enable AI Extraction”Navigate to SpecCart > Settings > AI extraction and check Enable AI extraction.
When disabled, all AI-related fields are hidden and no API calls are made.
API Configuration
Section titled “API Configuration”Once enabled, configure your OpenRouter API credentials:
1. Get an OpenRouter API Key
Section titled “1. Get an OpenRouter API Key”- Visit openrouter.ai/keys
- Sign up or log in to your OpenRouter account
- Create a new API key
- Copy the key (starts with
sk-or-v1-)
2. Enter API Credentials
Section titled “2. Enter API Credentials”- API endpoint: Pre-filled with
https://openrouter.ai/api/v1/chat/completions. Leave this as default unless using a compatible proxy. - API key: Paste your OpenRouter API key here. The field is password-masked for security.
3. Select a Model
Section titled “3. Select a Model”- Click Refresh models to load available vision-capable models from OpenRouter
- Select a model from the dropdown
Only models that support vision (image analysis) are shown. The list is filtered server-side to ensure compatibility.
Models you can use for prescription extraction include:
- anthropic/claude-sonnet-5.5: the default, used when no model has been chosen
- openai/gpt-4o: Strong vision capabilities
- google/gemini-pro-vision: Cost-effective option
4. Test Connection
Section titled “4. Test Connection”Click Test connection to verify your API credentials and selected model work correctly. A successful test confirms:
- API key is valid
- Endpoint is reachable
- Selected model is available
The test sends a simple request to the API without processing any real prescription data.
Extraction Prompts
Section titled “Extraction Prompts”The AI uses two prompts to extract prescription data:
System Prompt
Section titled “System Prompt”Sets the AI’s role and behaviour. This establishes context for all extraction requests.
Default: Instructs the AI to act as an expert at reading eyeglass prescriptions and to return structured JSON data.
User Prompt
Section titled “User Prompt”Provides specific instructions for each extraction request. Includes:
- What data to extract (sphere, cylinder, axis, the near ADD and the intermediate ADD, PD)
- Expected JSON output format
- Handling of missing or unclear values
Default: Detailed instructions specifying the JSON structure and field requirements.
Customising Prompts
Section titled “Customising Prompts”Advanced users can customise prompts to:
- Add support for specific prescription formats
- Include additional fields
- Adjust the AI’s behaviour for specific use cases
Reset to defaults button restores the original prompts if you need to undo changes.
Saving Settings
Section titled “Saving Settings”After configuring AI extraction settings, click Save changes in the header bar to persist your changes. All settings across every tab are saved together with this single button.
Using AI Extraction
Section titled “Using AI Extraction”Once configured, staff members can use AI extraction when processing orders:
- Navigate to SpecCart > Prescriptions and select an order
- Expand the lens item with an uploaded prescription
- Click Extract with AI (or Re-extract with AI if previously extracted)
- Review the extracted values, warnings, and confidence score in the modal
- Edit any values if needed, then click Accept & Apply
- The AI extraction details (confidence, model, warnings) display below the prescription table
AI extraction is also available from the order meta box in WooCommerce > Orders.
See Prescription Verification for the complete workflow.
Customer-side Upload
Section titled “Customer-side Upload”When AI extraction is enabled, the Upload a prescription option on the prescription step tells customers “We read the values and you check them.” The flow works as follows:
- Customer uploads a prescription photo or PDF via drag-and-drop or the file picker.
- The wizard shows “Reading your prescription…” while the file is sent to the configured model.
- The values read are shown on the step under Read from your upload, with the PD and, when prism is enabled, any prism read from the upload.
- If something is wrong, the customer chooses Edit, which moves to the manual form with the read values filled in.
- If no PD was read, the customer sees “We couldn’t find a PD on your upload. Please add it to continue.” and adds it on the step. Under Required with a default no notice shows: the PD list rests on “63 (average)” with its line (see Prescription settings). When PD requirement is set to Optional (see Prescription settings), the notice reads “We couldn’t find a PD on your upload. Add it if you know it.” and the customer can continue without it. If the customer replaces a file whose PD was read with a new file that has no PD, the PD read from the first file is kept and labelled From your earlier upload on the step and on the review. It changes to Entered by you if the customer picks another PD, or back to Read from your upload if a later file has a PD. The order still records the PD as read from an upload.
- If the customer edits any extracted value, the resulting order records
extraction_edited: truein the prescription metadata.
A prescription that says “Plano” or “PL” as a value is read as 0.00. A PD read from the file that falls outside 40 to 80 is dropped, so the customer is asked for it as if the file had none. If nothing can be read from the file (every eye and prism value empty), the customer sees “We couldn’t read your prescription. Upload a clearer photo or enter it yourself.” with Choose another file and Enter it yourself, and cannot continue with that file. A read that fails on the way is tried once more before this message shows.
When AI extraction is disabled, an upload is stored without being read and the customer is asked only for their PD: “Your prescription is uploaded. Please add your PD to continue.”, or, when PD requirement is Optional, “Your prescription is uploaded. Add your PD if you know it.”
Two ADD values (near and intermediate)
Section titled “Two ADD values (near and intermediate)”Some prescriptions list two additions, typically a near ADD (for reading) and an intermediate ADD (for computer or mid-distance work). From 1.8.0, SpecCart stores both: the read fills Near ADD and Intermediate ADD for each eye, and the wizard shows each one where the customer’s lens usage shows that field.
The default user prompt asks for the intermediate ADD as its own field, and also asks the model to emit a structured marker when it sees both values:
MULTIPLE_ADD:near=2.25,intermediate=1.50SpecCart uses the marker to fill any ADD the model left empty and removes it from the warnings, so neither staff nor the customer see it.
Prism read from an upload
Section titled “Prism read from an upload”When prism is enabled on the Prescription tab and the upload shows a prism, the wizard shows it under Read from your upload with the prism price. If the prism cannot be read or placed as horizontal or vertical, the customer sees “We couldn’t read the prism on your upload. Choose Edit and enter it to continue.” While prism is disabled, a prism on an upload is not carried into the order.
Cost Considerations
Section titled “Cost Considerations”OpenRouter charges per API call based on:
- Selected model
- Size of the image
- Length of the response
Typical prescription extraction costs $0.001 to $0.01 per image depending on the model. Monitor your usage in the OpenRouter dashboard.
Important Notes
Section titled “Important Notes”Verification Required
Section titled “Verification Required”AI extraction is an assistive tool, not a replacement for professional verification. Prescription values should always be reviewed by qualified staff before fulfilling an order. Incorrect prescriptions can cause eye strain, headaches, or vision problems.
Data Privacy
Section titled “Data Privacy”Prescription images are sent to OpenRouter’s API for processing. Review OpenRouter’s privacy policy to ensure compliance with your local regulations (HIPAA, GDPR, etc.).
Images are:
- Transmitted over HTTPS
- Processed by the selected model provider (Anthropic, OpenAI, Google, etc.)
- Not stored permanently by SpecCart after extraction
Read Quality
Section titled “Read Quality”How well a prescription is read depends on:
- Image quality (clear, well-lit, in-focus photos work best)
- Prescription format (standard formats work better than handwritten)
- Model selection (newer models generally perform better)
Encourage customers to upload high-quality images for best results.
Troubleshooting
Section titled “Troubleshooting””Failed to fetch models”
Section titled “”Failed to fetch models””- Verify your API key is correct
- Check your internet connection
- Ensure OpenRouter service is online
”Connection failed” on Test Connection
Section titled “”Connection failed” on Test Connection”- Double-check API key
- Verify API endpoint URL is correct
- Confirm selected model is available in your OpenRouter account
Extraction returns incorrect values
Section titled “Extraction returns incorrect values”- Review the uploaded image quality
- Check prompt configuration
- Try a different model
- Verify the prescription format is standard
PDF uploads are never read
Section titled “PDF uploads are never read”Reading a PDF needs the Imagick PHP extension on your server. Without it, PDF uploads cannot be read and customers see the “We couldn’t read your prescription” message; photos (JPG or PNG) are still read.
API calls not working in production
Section titled “API calls not working in production”- Ensure API key is saved in production environment
- Verify WordPress can make outbound HTTPS requests
- Check server firewall allows connections to openrouter.ai
Next Steps
Section titled “Next Steps”- Prescription Verification: Learn the full prescription verification workflow
- Email Notifications: Configure prescription-related emails
- General Settings: Configure other SpecCart options