Sessions
The Expo layer owns a cross-platform session abstraction. A session keeps conversational state — natively where the provider supports it, emulated where it doesn't.
export type CreateSessionOptions = {
instructions?: string;
provider?: ExpoAIProvider;
fallback?: 'none' | 'cloud' | 'any';
temperature?: number;
maxOutputTokens?: number;
metadata?: Record<string, string>;
sensitive?: boolean;
reasoningLevel?: 'light' | 'moderate' | 'deep';
};
export type ExpoAISession = {
id: string;
provider: ExpoAIProvider;
generate(options: SessionGenerateOptions): Promise<GenerateResult>;
stream(options: SessionGenerateOptions): AsyncIterable<GenerateChunk>;
generateObject<T>(options: SessionGenerateObjectOptions): Promise<T>;
generateObjectWithMeta<T>(
options: SessionGenerateObjectOptions,
): Promise<{ object: T; result: GenerateResult }>;
prewarm(options?: { promptPrefix?: string }): Promise<boolean>;
reset(): Promise<void>;
dispose(): Promise<void>;
};
sensitiveapplies the same routing gate as a one-shot request when the session picks its provider: a sensitive session binds to a third-party cloud only withfallback: 'cloud'or an explicitprovider: 'cloud'.- The session is bound to one provider. If a later
privacy policy disallows it, the session's next
call throws
UNAVAILABLE. generateObjectWithMetareturns the object plus itsGenerateResult(usage,structured). Schema and repair prompts never pollute the transcript.prewarmis best-effort and resolvesfalsewhen the provider can't prewarm.reasoningLevelis a hint used by Apple Private Cloud Compute and ignored elsewhere.
const session = await ExpoAI.createSession({
instructions: 'You are a concise note-taking assistant.',
});
await session.generate({ prompt: 'Capture the action items from this meeting.' });
await session.dispose();
Native mapping
| Concept | iOS | Android | Cloud |
|---|---|---|---|
| Session | Native Foundation Models session | Native or emulated session | Conversation / thread |
| Instructions | Native instructions | Prompt prefix | System message |
| Streaming | Native if available | Native or emulated | Provider stream |
| Structured output | Native if available | JSON prompt + validation | JSON mode / tools |
| Tools | Native if available | Emulated | Provider tools |