Genkit
Use Teralor Flash in server-side Genkit flows: text, streaming, tools, and schema parsing with the OpenAI-compatible plugin.
Connect Flash through Genkit's existing OpenAI-compatible plugin. Keep your API key on the server; no Firebase project, Google inference service, or custom provider package is required.
Install and authorize
Use Node 24.x. Complete Start here first: supply
TERALOR_API_KEY through your server environment and confirm authenticated model
discovery against the same environment. Never expose the key through frontend
code, NEXT_PUBLIC_* variables, browser storage, prompts, or Git.
Pin the two packages together. This recipe was exercised with 1.44.0:
npm install --save-exact --ignore-scripts genkit@1.44.0 @genkit-ai/compat-oai@1.44.0Commit your package lock. These are dependencies of your server application, not the Flash portal or a browser bundle.
Text generation
Save this as genkit-flash.mjs. The base URL below follows this documentation
site's environment; use the matching environment's key.
import assert from 'node:assert/strict';
import { genkit, modelRef, z } from 'genkit';
import { openAICompatible } from '@genkit-ai/compat-oai';
assert(process.env.TERALOR_API_KEY, 'Set TERALOR_API_KEY on the server');
const ai = genkit({
plugins: [openAICompatible({
name: 'teralor',
baseURL: 'https://api.teralor.com/v1',
apiKey: process.env.TERALOR_API_KEY,
maxRetries: 0,
timeout: 45_000,
})],
});
const options = {
model: modelRef({ name: 'teralor/Flash' }),
config: { max_tokens: 256, reasoning_effort: 'none' },
maxTurns: 2,
};
const result = await ai.generate({
...options,
abortSignal: AbortSignal.timeout(45_000),
prompt: 'Reply with exactly GENKIT_OK and nothing else.',
});
assert.equal(result.text.trim(), 'GENKIT_OK');
console.log(result.text);node genkit-flash.mjsThe model reference combines the plugin name teralor with the API model ID
Flash. Each model call reserves at most 256 output tokens; a tool loop can use
more than one call. SDK retries are disabled, model turns are bounded, and each
generation has a fresh 45-second client deadline.
Use config.max_tokens, not maxOutputTokens, with this pinned plugin. Its
1.44.0 generic serializer drops maxOutputTokens. It also drops
temperature: 0, so this recipe deliberately omits temperature. Recheck both
behaviors before upgrading; don't assume an unsent control reached the API.
Streaming
The following snippets reuse the imports, ai, and options above. Consume the
stream and observe its completion together so errors from either are handled:
const { stream, response } = ai.generateStream({
...options,
abortSignal: AbortSignal.timeout(45_000),
prompt: 'Reply with exactly STREAM_OK and nothing else.'
})
const [completed, text] = await Promise.all([
response,
(async () => {
let text = ''
for await (const chunk of stream) text += chunk.text
return text
})()
])
assert.equal(text.trim(), 'STREAM_OK')
assert.equal(completed.text.trim(), 'STREAM_OK')
console.log(text)A client abort stops client consumption; it does not prove backend execution, accounting, or queue reservations have finished. Don't blindly retry an uncertain request. See Troubleshooting.
One read-only tool
Genkit handles the model → tool → model loop. This tool only returns a fixed marker; it does not access files, accounts, or external services:
let calls = 0
const lookupMarker = ai.defineTool(
{
name: 'lookupMarker',
description: 'Read a fixed compatibility marker; no external side effects.',
inputSchema: z.object({}),
outputSchema: z.string()
},
async () => {
assert.equal(++calls, 1, 'The smoke tool must run only once')
return 'TOOL_OK'
}
)
const toolResult = await ai.generate({
...options,
abortSignal: AbortSignal.timeout(45_000),
tools: [lookupMarker],
prompt: 'Call lookupMarker exactly once, then reply with only its returned marker.'
})
assert.equal(calls, 1)
assert.equal(toolResult.text.trim(), 'TOOL_OK')
console.log(toolResult.text)Authorize real tools against the authenticated application user and validate inputs in the server-side handler. A model's tool choice or a valid Teralor key is not permission to act for an arbitrary user.
The API's shared admission layer handles omitted assistant content on
valid tool-call histories. No custom fetch adapter or message-rewriting shim is
needed. Malformed calls, arguments, IDs, unmatched results, and invalid message
sequences remain rejected. Verify a tool-only replay against the endpoint you
use; a text-bearing assistant tool call alone doesn't cover that case.
Structured output
const structured = await ai.generate({
...options,
abortSignal: AbortSignal.timeout(45_000),
output: { schema: z.object({ ok: z.boolean() }) },
prompt: 'Return ok true.'
})
assert.deepEqual(structured.output, { ok: true })This is Genkit prompt instruction plus client-side schema parsing, not native
server-enforced constrained decoding. Do not set response_format or claim
strict JSON-schema enforcement: the current API rejects native
response_format: json_schema with HTTP 400. Treat schema failures as failures,
not as validated data or tool authorization.
More information
- Connect tools — harness and application routes.
- API reference — supported fields and error responses.
- Genkit OpenAI-compatible plugin
- Genkit tool calling