AI in your application
MarkdownYour application can ask a model to read text, PDFs and images and to answer in text, or in JSON that follows a schema you give. Apigami calls the model in its own name, in the EU: you need no AI account, no key and no server. What you send is processed without being stored and is never used for training.
{ "op": "ai.generate", "params": { "instructions": "Extract the person's name and city. Use null for what the text does not say.", "input": [{ "text": "Jean Dupont, developer, lives in Lyon." }], "output_schema": { "type": "object", "properties": { "name": { "type": "string" }, "city": { "type": ["string", "null"] } }, "required": ["name", "city"] } }}{ "result": { "output": { "name": "Jean Dupont", "city": "Lyon" }, "finish_reason": "stop", "usage": { "input_tokens": 188, "output_tokens": 43 } }}ai.generate is answered by Apigami itself, never by a browser: it takes no domain and no user_ref.
A run that serves a person needs that person’s grant of your AI, asked like a site’s; a run that serves
nobody needs only the declaration.
The AI is in preview, open to a few teams. Any other team’s call answers 403 ai is not open to this group yet.
Before the first call
Section titled “Before the first call”-
Declare the permission in your manifest, beside your sites (Permissions: ai):
"x-apigami": { "permissions": ["ai"] }The version whose code calls must declare it: the one a run executes, the production version for your
apg_key and forAPIGAMI_KEY. For a sub-app, the version the calling application reaches must declare it too, since that is what the connect page of the applications using it shows. -
Deploy, and publish to call from your server with your API key. The connect page then lists, among what your application may do, « Use an AI: what you entrust to it is processed in the cloud, without storage or training », and « Continue » grants it.
-
The people connected before a version that declares
aiare asked on Apigami’s screen of new permissions at their next opening of one of your pages. Until they answer, a run for them answers403 consent requestedwith"permission": "ai", and after a refusal403 no grant. A cron, an open action or your API key, which serve nobody, are not concerned. A member of your team trying a version withapp_runorapp_page_previewhas its AI granted for that trial.
Who calls
Section titled “Who calls”| Caller | Credential |
|---|---|
| Your server | your API key, apg_… |
| The action of a cron, for several people | env.APIGAMI_KEY, the production version’s key |
| An action, a trigger, a schedule | X-Apigami-Run, what Apigami handed the action |
| An open action | env.APIGAMI_KEY: it gets no X-Apigami-Run |
The AI answers your application, not a person: a call with nobody behind it, such as an open action or a
schedule, calls it like any other. A page cannot: its token is the visitor’s, who could write the
instructions. Call an action of yours from the page with apigami.call, and call the AI from that action.
export const extractPerson = async (env, runToken: string, pdfBase64: string) => { const answer = await fetch(`${env.APIGAMI_API_URL}/call`, { method: 'POST', headers: { 'X-Apigami-Run': runToken, 'Content-Type': 'application/json' }, body: JSON.stringify({ op: 'ai.generate', params: { instructions: 'Extract the person this resume is about.', input: [{ file: { media_type: 'application/pdf', data_base64: pdfBase64 } }], output_schema: { type: 'object', properties: { name: { type: 'string' } }, required: ['name'] }, }, }), }) const body = await answer.json() // Never log the input or the output: your logs are kept, and the content is someone else's. if (!answer.ok) throw new Error(`ai refused: ${answer.status} ${body.error}`) return body.result.output}The parameters
Section titled “The parameters”| Param | ||
|---|---|---|
instructions |
required | What the model must do, 1 to 32 000 characters |
input |
required | 1 to 10 parts, read in order: { "text": "…" } or { "file": { "media_type": "…", "data_base64": "…" } } |
output_schema |
optional | A JSON Schema of the answer, 16 kB at most. Absent, the answer is text |
max_output_tokens |
optional | 1 to 16 384, 4 096 by default |
model |
optional | gemini-3.1-flash-lite by default, claude-haiku-5-5 or claude-sonnet-5-5 |
The model’s settings are Apigami’s: they may change, never the contract.
Models
Section titled “Models”Without model, gemini-3.1-flash-lite answers. claude-haiku-5-5 and claude-sonnet-5-5 are in trial: they may
answer 503 ai is not configured while they are not open. They take the same parameters, with three limits:
- an image is 5 MB at most, decoded, each one; a larger one is refused with its path;
output_schemauses fewer keywords (Structured output);- a request the model chooses not to answer is
422 the model declined to answer: refusal.
Documents
Section titled “Documents”- Text parts total 500 000 characters at most.
- A file is a PDF (
application/pdf), plain text (text/plain) or an image (image/png,image/jpeg,image/webp), in standard base64. Its first bytes must match its type. - 14 MB of files at most per call, decoded, all files together.
- A Word or OpenDocument file is refused with a 415: convert it to PDF or text first.
Structured output
Section titled “Structured output”With output_schema, output is the parsed JSON, which follows the schema. A schema written by zod’s
z.toJSONSchema or pydantic passes as it is. The keywords the model reads are type, properties,
required, items, prefixItems, additionalProperties, enum (strings or numbers), anyOf, oneOf,
title, description, format, minItems, maxItems, minimum, maximum, propertyOrdering,
$schema, $id, $anchor, $defs and $ref. Any other, such as pattern or minLength, is refused
with its path rather than silently ignored. A value that may be absent is written
"type": ["string", "null"].
With a Claude model, the keywords are type, properties, required, items, additionalProperties, enum,
anyOf, title, description, format, minItems (0 or 1 only), $schema, $id, $defs and $ref, a $ref
pointing into the schema such as #/$defs/job. Every object is closed: additionalProperties may only be false,
and Apigami writes it on each object that leaves it out.
description is read by the model: say there what a field holds, and what to answer when the document
does not say.
usage counts the tokens of the call. output_tokens includes the model’s reasoning. Without a schema,
finish_reason is max_output_tokens when the text was cut short; with a schema, a cut answer is a 422,
since half a JSON is of no use.
Refusals
Section titled “Refusals”| Status | error |
What to do |
|---|---|---|
400 |
ai answers the caller, not a person: remove user_ref and install_ref |
Send neither |
403 |
a page cannot call the ai: … |
Call it from an action, which the page calls with apigami.call |
403 |
not_a_subapp: … |
A sub-app’s run, after the application calling it stopped declaring it |
403 |
subapp_not_accepted |
A sub-app’s run, after the person removed that optional sub-app |
409 |
publish a version with app_publish before an api key calls the ai: … |
Publish once: your key runs production’s manifest |
403 |
ai not permitted for this app: … |
Declare "permissions": ["ai"] in the version that calls, and deploy |
403 |
ai is not open to this group yet |
The AI is in preview: write to contact@apigami.com |
403 |
consent requested, with "permission": "ai" |
The person never decided your AI: send them to one of your pages, where Apigami asks them. With consentPending, the approval window is on screen |
403 |
no grant, with "permission": "ai" |
The person refused your AI; send them to settings_url (Refusals) |
400 |
invalid ai params: params.input[1].file.data_base64: does not start like application/pdf |
Fix the field it names |
400 |
invalid ai params: params.model: must be one of … |
Name one of the models, or leave model out |
413 |
ai input too large: at most 14 MB of files per call |
Send fewer or smaller files |
415 |
unsupported media type …: send pdf, text or an image |
Convert the file to PDF or text |
400 |
invalid ai params: the model cannot read this input, … |
Check the files, and the schema |
503 |
ai is not configured |
Apigami’s side: write to Apigami |
503 |
the model is busy, try again in a minute |
Wait for Retry-After, then try again |
502 |
the model could not answer, try again later |
Try again later |
422 |
the model declined to answer: safety |
The content was refused by the model’s filters, refusal for a Claude model: do not retry as is |
422 |
ai output cut at max_output_tokens: … |
Raise max_output_tokens, or ask for less |
A refusal never repeats what you sent. Apigami never retries a call by itself: a call is billed once.
Transcribe audio: ai.transcribe
Section titled “Transcribe audio: ai.transcribe”ai.transcribe turns a recording into text, in the language it detects. It is called like ai.generate: the same
credentials, the same ai permission and the same person’s grant, no domain, no user_ref, never from a page. It is
in trial, open to Jarvi’s team only, on Jarvi’s own transcription key: any other team’s call answers 403 ai is not open to this group yet, even one open to ai.generate.
{ "op": "ai.transcribe", "params": { "file": { "mime_type": "audio/webm", "data": "GkXfo59ChoEBQveBAULygQRC84EIQoKE…" }, "languages": ["fr", "en"] }}{ "result": { "text": "Bonjour, je vous appelle au sujet de la candidature de Jean.", "language": "fr", "audio_duration_seconds": 6.4 }}| Param | ||
|---|---|---|
file.mime_type |
required | audio/webm, audio/ogg, audio/mp4, audio/mpeg, audio/wav or audio/x-m4a. A parameter such as ;codecs=opus, which MediaRecorder writes, is ignored |
file.data |
required | The audio in standard base64, 14 MB at most once decoded |
languages |
optional | The languages the audio may be in, as codes such as fr or en_us (EN-US is read as en_us), 1 to 20. By default fr, en, es, nl, it, de and pt. Narrowing it keeps a muffled recording from being read as another language |
languageis the code detected amonglanguages,nullwhen none was given back;audio_duration_secondsis the recording’s length as the transcription measured it, ornull.- A transcription takes a few seconds for a voice note and is given 120 s; the call answers within 130 s at most. Past the 120 s, the call is a 502: send shorter recordings, a few minutes each.
textis empty when the recording holds no speech.
Its refusals
Section titled “Its refusals”The refusals of ai.generate that do not depend on its parameters apply as they are: ai not permitted for this app,
ai is not open to this group yet, consent requested and no grant with "permission": "ai", ai is not configured, a user_ref or a page’s token. Its own:
| Status | error |
What to do |
|---|---|---|
400 |
invalid ai params: params.file.mime_type: required |
Fix the field it names |
400 |
invalid ai params: params.languages[0]: must be an ISO 639-1 code such as fr, … |
Send codes, not names |
400 |
invalid ai params: params.file: the audio cannot be transcribed, … |
The file holds no audio it can decode: check its content and mime_type |
400 |
invalid ai params: params.languages: a language the transcription does not know, … |
Send only languages it transcribes, or leave languages out |
413 |
ai input too large: at most 14 MB of audio per call |
Send a shorter or more compressed recording |
415 |
unsupported media type …: send webm, ogg, mp4, mpeg, wav or m4a audio |
Convert the recording |
502 |
the transcription took longer than 120 s, … |
Try again later, or send a shorter recording |
502 |
the model could not answer, try again later |
Try again later |
What is kept
Section titled “What is kept”- Apigami keeps one line per call: the application, its version, the model, the tokens (for a transcription, the audio’s duration), the duration and whether it answered. Never the instructions, the files, the audio nor the answer.
- The model’s provider, Google Cloud, processes the call in the EU and stores nothing of it, with one exception: a request its abuse filters flag may be kept up to 90 days, in the EU, for review. Nothing is used for training.
- The transcription’s provider, AssemblyAI, processes the audio in the EU (
api.eu.assemblyai.com). Apigami deletes the transcript, and the audio with it, at AssemblyAI once the transcription has ended, whether it gave a text or failed; one still running when the call times out is deleted when it ends. One exception: an audio uploaded whose transcription never started, because AssemblyAI refused or did not answer the request to start it, has no transcript to delete it with, and stays at AssemblyAI until it expires there. - Your application is responsible for what it does with the answers. Never write an input or an output of the AI to your logs: they are kept.