Providers
Let a tik use the viewer's own OpenRouter account for AI and Google Drive, Docs and Sheets for storage, with their consent and never their credential.
A tik can work with services the viewer already has: OpenRouter for AI models on their own key, and Google for files, Docs and Sheets in their own Drive. The viewer connects the account once in the Codetik app, allows each tik themselves, and the tik never sees the key or the Google credential: the app attaches it to each call.
| Provider | What the tik gets | On window.tik |
|---|---|---|
| OpenRouter | Text and image models, paid from the viewer's account | tik.openrouter |
| Drive files, Docs and Sheets in a folder of the tik's own | tik.google |
A provider is declared in the tik's settings in the Codetik app, not in tik.yaml, and a tik made with the CLI has no way to declare one yet. Until it does, this page applies to tiks made in the app.
A namespace is on window.tik only when the tik declares it, so if (tik.openrouter) is the feature test. codetik dev does not support providers yet: calls there reject with unsupported.
Asking the viewer
Every provider has the same gate. require() walks the viewer through connecting an account and allowing this tik, stays pending while they do, and resolves true once the provider is ready or false if they decline. The optional message, up to 100 characters, says why in the prompt.
if (tik.openrouter && (await tik.openrouter.require('to write your story'))) { // OpenRouter calls work now}A tik that needs both asks once:
if ( tik.providers && (await tik.providers.require( ['openrouter', 'google'], 'to save your stories', ))) { // both are connected and allowed}- Ask on the viewer's first action that needs it, not at page load in a loop.
- A decline is normal. Keep the tik useful without the provider, with a visible way to connect later that calls
require()again. - The viewer chooses how long a tik stays allowed (this session, 30 days or always) and can disconnect it any time from Settings, Providers in the app.
OpenRouter
AI models on the viewer's own OpenRouter account, through two libraries the app already has: ai and @openrouter/ai-sdk-provider. List both in package.json peerDependencies. There is nothing to configure: no key, no base URL.
import { streamText } from 'ai';import { openrouter } from '@openrouter/ai-sdk-provider'; async function ask(prompt: string): Promise<void> { if ( !tik.openrouter || !(await tik.openrouter.require('to answer your questions')) ) return; const result = streamText({ model: openrouter('openai/gpt-4o-mini'), prompt, }); for await (const delta of result.textStream) render(delta);}Images go through the image models:
import { experimental_generateImage } from 'ai'; const { image } = await experimental_generateImage({ model: openrouter.imageModel('google/gemini-2.5-flash-image'), prompt,});- Stream. Text appearing as it arrives feels fast; a spinner for ten seconds feels broken.
streamTextis not awaited; the aggregates on its result are (await result.text). - The viewer pays. Default to a small, cheap model and reach for a big one only when the task needs it. Model ids are OpenRouter ids,
vendor/model. - One chat at a time per tik. A second concurrent call is refused and bursts are rate limited, so disable the send button while a stream runs.
- Stoppable. Stop reading the stream when the viewer presses stop or leaves; leaving the tik mid-stream aborts it.
- Not supported: tool calling,
generateObjectand embeddings.completion()andtextEmbeddingModel()throw. createOpenRouter()exists for code written for the upstream library; itsapiKey,baseURLandheadersare ignored.
Drive, Docs and Sheets in the viewer's own Google account. Everything lives in the tik's own folder, Codetik/<tik title>, made on the first write. Files elsewhere in their Drive, or made by other tiks, are out of reach.
- Per viewer. Each viewer gets their own copies in their own Drive. It is storage that outlives the tik, not shared state: shared state is the tik's backend.
- By name.
openandwriteFileget or create a file by its name, so a tik finds its files again in a new session without storing an id. - The viewer's data. They can open, edit, rename or delete anything the tik keeps, so read defensively: a sheet may gain columns, a doc may be edited by hand.
if ( tik.google && (await tik.google.require('to keep your scores in your Drive'))) { const sheet = await tik.google.sheets.open({ title: 'Scores', headers: ['when', 'score'], }); await tik.google.sheets.append(sheet.id, [[new Date().toISOString(), 42]]); const { values } = await tik.google.sheets.read(sheet.id);}drive
| Method | What it does |
|---|---|
folder() | The tik's folder, with a link to open it in Drive |
list({ kind? }) | Every file the tik made; kind is doc, sheet or file |
writeFile(name, content, { mimeType?, encoding? }) | Create or overwrite by name: saves, exports, images as base64 |
readFile(id) | A file as text, up to 2 MB |
rename(id, name) | Rename any of the tik's files |
trash(id) | Move to the viewer's trash, recoverable for 30 days |
publish(id), unpublish(id) | Put a doc or sheet on the web, after the viewer confirms; take it off |
docs
Docs are read and written as markdown: headings, emphasis, links, lists and tables survive both ways.
| Method | What it does |
|---|---|
open({ title }) | Get or create a doc by title |
write(id, markdown) | Replace the whole doc |
append(id, markdown) | Add to the end; better for a doc the viewer also edits |
read(id) | The doc as markdown |
insertImage(id, imageFileId) | Add an image the tik saved with drive.writeFile |
sheets
Sheets work on the first tab, with ranges in A1 notation ('A2:C10'). append is for logs, one row per event; write is for state the tik keeps updating.
| Method | What it does |
|---|---|
open({ title, headers? }) | Get or create a sheet; headers becomes row 1 on creation |
append(id, rows) | Add rows after the last one; up to 100 rows of 26 cells |
write(id, range, rows) | Overwrite a range |
read(id, { range? }) | Read a range, A1:Z1000 by default |
clear(id, range) | Empty a range, keeping its formatting |
insertRows(id, { at, count? }) | Insert blank rows, shifting the rest down |
deleteRows(id, { at, count? }) | Delete rows, shifting the rest up |
format(id, range, style) | Bold, italic, strikethrough, text colour and background |
borders(id, range, { color?, thick? }) | Lines around and between the cells |
tagRow(id, { at, id }), findRow(id, { id }) | A row id that survives rows moving around it |
The full signatures, with every limit, are in src/tik.d.ts.
Calls and errors
Every call is a promise: await all of them. A call made while the tik is hidden waits until it is shown, so loading data on mount is safe even on a preloaded slide. Calls are rate limited per tik.
| Code | Meaning |
|---|---|
not_declared | The tik does not declare this provider |
not_connected | No valid connection: call require() again |
denied | Not allowed, or not this tik's file |
aborted | The tik was left mid-call, ending a stream |
rate_limited | Too many calls: back off, never retry in a loop |
provider_error | Anything else from OpenRouter or Google; .message says what |
unsupported | Not available here, such as any provider call in codetik dev |