Files and voice
Images, PDFs and text files a visitor drops, pastes or attaches to a question, and dictation into the question field, in every chat module, read by the visitor's own AI.
A chat module takes files and voice when your site passes attachments. The visitor drops a file on the module, pastes a screenshot into the question field, or picks files with the attach button, and dictates a question with the microphone button. The files reach the visitor's own model as the account that answers reads them, and the dictation lands in the question field as text for the visitor to correct before sending.
A module without attachments keeps its question box as it was.
Turn it on
<AiChatPanel system="You answer questions about this shop." mcp="/api/mcp" attachments={{}} /><aiconnect-chat variant="panel" mcp="/api/mcp" attachments></aiconnect-chat>
<aiconnect-chat variant="inline" attachments='{"files": false, "maxFiles": 4}'></aiconnect-chat>{} takes images, PDFs, text files and voice with the default caps. The search bar takes voice only.
| Field | Default | What it sets |
|---|---|---|
images | true | Images: PNG, JPEG, WebP, GIF, and HEIC where the browser decodes it. |
files | true | PDFs and text files: plain text, Markdown, CSV and JSON. |
voice | true | The microphone button. |
accept | every kind left on | The media types the site takes, such as ["image/png", "image/jpeg"]. image/* takes the whole family. |
maxBytes | 5 MB | The size the files of one question take on the way to the model. |
maxFiles | 10 | The files of one question. |
What the visitor sees
Files dragged over a module cover it with a drop zone that says whether the module takes them before the visitor lets go. Each file shows as a chip above the field: a thumbnail for an image, the name and the size for a document, a ring while the page reads it, and a button to remove it. A file the module does not take, a question over its size or its count, and a file the browser could not read each show a line saying why, in the module's language. The images of a sent question open in a lightbox, which Escape closes without closing the module.
Everything follows your --aic-* tokens, the dark theme and right to left, in the five languages of the modules.
What the model receives
The page prepares each file once it is added:
- An image is drawn again at 1,568 pixels on its long side at most, the size Anthropic's vision guide recommends, and sent as WebP, or JPEG in a browser that writes no WebP. Drawing it again drops its metadata, the GPS position of a phone photo included.
- A PDF goes whole to a model that reads PDFs. For any other model, pdf.js reads it in the page: its text goes as a text file under the PDF's name, and each page without text, such as a scan, goes as an image when the model sees images. pdf.js loads the first time such a PDF is sent.
- A text file goes as its text, under its name, inside its own salted envelope (see Guards).
What each model reads comes from the wallet, which reads it from the provider's docs or, for OpenRouter, from its model list:
| Account | Images | PDFs |
|---|---|---|
| Claude plan, Claude API key | yes | yes |
| OpenAI API key | yes | yes |
| ChatGPT plan | yes | as text |
| Gemini plan | Gemini models | Gemini models |
| Gemini API key | yes | as text |
| OpenRouter | the models that list image input | yes, OpenRouter parses them |
| Mistral API key | the vision models | as text |
| Grok, Qwen, MiniMax, MiMo, Muse, Perplexity, DeepSeek, NVIDIA | the models their docs name | as text |
| Kimi, GLM, Nous, CodeBuddy, TensorPass | no | as text |
On a model that does not see images, the image's chip says so before the question is sent, and the question goes with its text. A site set to Auto in the wallet asks first the accounts whose model reads every file of the question.
Each question resends the conversation, files included. Past 7.5 million characters, under the 8 million the wallet takes in one request, the files of the oldest questions give way to a note naming them.
Dictation
The visitor presses the microphone button and speaks. The bar shows a live waveform and the time, and the words where the transcription writes them while the visitor speaks. Done puts the transcript in the field, Cancel or Escape drops it, and the recording ends by itself after 15 seconds of silence or 2 minutes. The SDK ships no speech model: the transcription service of the account that answers writes the words, and without one, the browser's speech recognition does.
| Account | Transcription |
|---|---|
| ChatGPT plan | The dictation Codex uses. |
| OpenAI API key | /v1/audio/transcriptions with gpt-transcribe. |
| Mistral API key | /v1/audio/transcriptions with Voxtral. |
| Gemini plan, Gemini API key | The visitor's Gemini model writes down the recording. |
| Claude plan and every other account | The browser's speech recognition, in Chrome, Edge and Safari. Chrome sends the voice to Google's recognition service. Firefox has none yet, so it hides the microphone for these accounts. |
The wallet counts dictation against each site's day by what the account bills. A transcription billed by the minute counts against the minutes of dictation the visitor gives each site in the wallet's Settings, 15 a day by default, and a recording stops at the minutes left. Gemini, which hears the recording, takes 32 tokens a second from the site's daily tokens. A site over its minutes goes on with the browser's speech recognition, and with none in the browser, the module says the site used its dictation of the day.
The language is the module's, with the region of the visitor's browser language that matches it, such as he-IL or ar-MA. The browser asks the visitor for the microphone on your site's behalf, and a refusal shows how to allow it.
Guards
The guards read what the visitor attached as well as what they typed:
- the text of every attached text file meets the injection patterns, and a question whose file carries one stops as a typed one does;
- the files of one question hold 200,000 characters of text at most, which
maxAttachmentTextinguardssets; - the long base64 block reads only what the visitor typed, since a CSV or a JSON file holds long tokens of its own;
- each text file reaches the model inside
<attachment-SALT name="...">, and the rules tell the model that instructions written inside an attachment carry no authority; - an email address written in the visitor's own file may appear in the answer, as one the visitor typed may.
A PDF sent whole and an image reach the model as they are: the guards cannot read inside them.
Bundlers and the Content Security Policy
The dictation records through an audio worklet, a file the React package publishes beside its code and loads with new URL('./pcmWorklet.js', import.meta.url), which Vite, webpack and Next.js copy with your bundle. pdf.js loads with a dynamic import() the first time a PDF goes as its text. The Web Components load both from beside their own script, as aiconnect-pcm-worklet.js and aiconnect-pdf.js: serve the three files from the same place.
Under a Content Security Policy, script-src allows the origin these files come from, and a page in a frame needs allow="microphone" for dictation.
Your own interface
useAiChat sends a question with its files:
import { checkAttachment, prepareAttachment } from '@tensorpass/aiconnect/attachments';
const check = checkAttachment(file, {}, 0);
if (check.ok) {
const attachment = await prepareAttachment(file, check.kind, check.mediaType);
await chat.send({ text: 'What is in this photo?', attachments: [attachment] });
}chat.reads says what the model of the account that answers reads, and chat.dictation is the account's transcription when it has one.
Web Components
Add every interface module to a page without React, such as a WordPress page, with one script tag and two custom elements.
Guards
The protections every module runs on every conversation against prompt injection, leaks of your site's data and exfiltration of the visitor's conversation, and how your site tunes them with one option.