You can generate responses using ADK with the Vercel AI SDK's generateText or streamText functions. ADK orchestrates the agent loop natively on Android while the provider bridges tool execution and streaming back to JavaScript. Import the default provider, call adk() to construct a language model, and pass it to the AI SDK — the default export targets on-device Gemini Nano.
ReadableStream; see PolyfillsprepareNano() or model.prepare() before first on-device use (see Getting Started - On-device Gemini Nano)Cloud models use ADK's LlmAgent with Google's Gemini API. This is useful when Gemini Nano is unavailable, you need a more capable model, or you want to develop on an emulator without AICore. Create a provider with modelType: 'gemini' and an API key:
Cloud models do not require a separate download or prepare step.
Do not embed API keys in production client apps. Prefer a backend proxy or secure runtime configuration.
Stream responses for real-time output:
During streaming, the provider emits standard AI SDK stream parts: text-start, text-delta, text-end, and finish with usage metadata.
ADK returns token usage in response events (promptTokenCount, candidatesTokenCount, totalTokenCount). The provider maps this into AI SDK usage on both generateText results and streaming finish events:
Enable ADK agents to call JavaScript tools during generation. Works on both on-device Nano and cloud Gemini.
Tools are orchestrated by ADK natively, which means:
createAdkProvider via availableTools so ADK can invoke their execute handlersproviderExecuted: truemaxSteps does not control ADK's internal iterationADK needs tool executors registered both in the AI SDK and on the provider. Use createAdkProvider with availableTools, then pass tools to the AI SDK and call adk() as usual. Example:
During streaming, the provider emits tool-input-start, tool-input-delta, tool-input-end, and tool-call stream parts when ADK surfaces function calls from the model.
Pass tools through the AI SDK tools option as usual; the provider bridges execution to JavaScript while ADK orchestrates the agent loop natively.
Register tools when creating the provider so ADK can execute them from JavaScript:
To register executors at provider creation time:
Pass file parts in user messages using the standard AI SDK prompt format:
Supported file data formats:
data:image/jpeg;base64,... data URLsUint8Array - Binary image dataNote: File URLs (
file://or HTTP) are not supported yet. Pass base64 orUint8Arraydata directly.
Generate JSON responses using AI SDK JSON mode:
Note: JSON schema constraints (
responseFormat.schema) are not supported yet. Use JSON mode without a schema, or parse and validate the response in your app.
Streaming structured JSON is not supported by ADK yet.
Configure model behavior with generation options:
| Option | Type | Description |
|---|---|---|
temperature | number | Controls randomness |
maxTokens | number | Maximum tokens to generate (maxOutputTokens in AI SDK) |
topP | number | Nucleus sampling threshold |
topK | number | Top-K sampling parameter |
Example:
The following features are not yet supported:
| Feature | Status |
|---|---|
responseFormat.schema | Not supported - use JSON mode without schema |
| Streaming JSON | Not supported |
toolChoice: { type: 'required' } | Ignored with a warning - defaults to auto |
| File URLs in multimodal prompts | Not supported - use base64 or Uint8Array |
| iOS / web | Android only |