Send Images to Multimodal Models with 59API
Vision Input: What Your Application Actually Sends
Multimodal models can reason over text and images in one request. Typical production uses include extracting totals from receipts, reviewing product photos, reading dashboard screenshots, checking UI regressions, and turning documents into structured data. The important implementation detail is that an image is sent as a content item alongside your written prompt, not pasted into a plain text message.
59API provides a practical route for this work when you need affordable, pay-as-you-go access to official-quality GPT and Claude-family models through one relay. Its API base URL is https://api.59api.com, and its OpenAI-compatible interface means an existing OpenAI SDK integration can usually be adapted by changing the base URL and API key. Select a model that explicitly supports vision before relying on image analysis in production.
Example: Analyze an Image from a Public URL
First, install the official JavaScript SDK: npm install openai. Then create a client configured for 59API. Keep the API key in an environment variable rather than committing it to source control.
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.FIFTYNINE_API_KEY,
baseURL: "https://api.59api.com/v1",
});
The following request sends a product image by URL. Replace the model name with a vision-capable GPT model available in your 59API account. The prompt asks for a constrained JSON shape, which makes downstream handling more reliable than asking for free-form prose.
const response = await client.chat.completions.create({
model: "gpt-4o",
messages: [{
role: "user",
content: [
{ type: "text", text: "Inspect this product photo. Return JSON with category, dominant_colors, visible_text, and damage_notes. Use null where evidence is missing." },
{ type: "image_url", image_url: { url: "https://example.com/product.jpg" } }
]
}]
});
console.log(response.choices[0].message.content);
A public HTTPS URL is convenient for testing, but avoid exposing private customer images this way. For user uploads, send image bytes as a base64 data URL or store the file in a short-lived, access-controlled object URL. Also validate the model output before inserting it into a database, since a model response is generated content rather than a guaranteed schema-valid record.
Example: Send a Local Image as Base64
For a local file, read it into memory and prefix the encoded content with its MIME type. JPEG, PNG, and WebP are common choices; use the actual file type rather than labeling every upload as JPEG.
import fs from "node:fs";
const base64 = fs.readFileSync("./receipt.png").toString("base64");
const imageDataUrl = `data:image/png;base64,${base64}`;
const receipt = await client.chat.completions.create({
model: "gpt-4o",
messages: [{
role: "user",
content: [
{ type: "text", text: "Read this receipt. Return merchant, date, currency, total, and line_items as JSON. Do not invent unreadable values." },
{ type: "image_url", image_url: { url: imageDataUrl } }
]
}]
});
Make Vision Requests Accurate and Economical
- Crop before sending: Send the receipt, chart, or UI region that matters. Smaller, focused images reduce ambiguity and can reduce input cost.
- State the task precisely: Ask the model to identify, compare, transcribe, or classify. Include required fields, acceptable values, and what to do when text is unreadable.
- Use image detail deliberately: High-detail analysis is useful for small labels and dense screenshots, while lower detail may be enough for broad scene classification.
- Test difficult inputs: Include glare, rotation, low contrast, partial crops, handwriting, and multiple languages in your evaluation set.
- Protect privacy: Remove unnecessary sensitive regions and retain images only as long as your product requirements permit.
59API is especially useful when vision features need experimentation across model families without committing to a large prepaid balance. You can keep a single compatible integration for GPT models and supported Claude models, compare outputs for your real image set, and manage costs with pay-as-you-go pricing. Create a 59API account when you are ready to test a vision workflow, and use its referral rebate program to reduce ongoing API spend where applicable.
Pronto para começar?
Conecte Claude e GPT em minutos pelos menores preços, sem cortes. Cadastre-se e obtenha sua chave API.
Cadastro grátis