Quick start
Make one Node.js call to recognize “Look up order 000123. Do not cancel the order.” Find the goal and the prohibition without configuring business fields first.
1. Install
Use Node.js ≥20 and ESM. Run in your application directory:
npm install @devcodex/intent-runtime
npm installs required dependencies automatically. JavaScript and TypeScript projects use the same API. Set "type": "module" in package.json for .js, or save standalone JavaScript as .mjs. See Installation.
This example recognizes goals and constraints without a business Schema. Add structured parameters later using the order field example.
This path uses your model API credentials. To reuse the current Codex model without an additional key, follow Connect Codex.
The example uses the OpenAI Responses API. Set INTENT_API_KEY and INTENT_MODEL to your credentials and an available model name. These are variables read by the application example; the library does not automatically read fixed environment variable names. For xAI or your gateway, see Model APIs.
PowerShell:
$env:INTENT_API_KEY = "your API key"
$env:INTENT_MODEL = "your model name"
Bash:
export INTENT_API_KEY="your API key"
export INTENT_MODEL="your model name"
3. Save and run
Choose your project's language. Save JavaScript as basic.js or TypeScript as basic.ts. Package imports resolve from the file's location.
import {Intent, IntentError} from '@devcodex/intent-runtime';
import {createApiExecutor} from '@devcodex/intent-runtime/adapters/api';
const apiKey = process.env.INTENT_API_KEY;
const model = process.env.INTENT_MODEL;
if (!apiKey || !model) throw new Error('Set INTENT_API_KEY and INTENT_MODEL in your environment.');
const intent = new Intent({
language: 'en',
executor: createApiExecutor({provider: 'openai', apiKey, model}),
});
try {
const result = await intent.parse({input: 'Look up order 000123. Do not cancel the order.'});
console.log(JSON.stringify(result, null, 2));
// Read goals and constraints from effective; no order query is executed.
console.log('Goals:', result.effective.intents.map(node => node.goal));
console.log('Issues:', result.issues.map(issue => issue.message));
} catch (error) {
if (!(error instanceof IntentError)) throw error;
console.error(JSON.stringify(error.toJSON()));
process.exitCode = 1;
} finally {
await intent.dispose();
}
import {Intent, IntentError, type IntentParseRequest} from '@devcodex/intent-runtime';
import {createApiExecutor} from '@devcodex/intent-runtime/adapters/api';
const apiKey = process.env.INTENT_API_KEY;
const model = process.env.INTENT_MODEL;
if (!apiKey || !model) throw new Error('Set INTENT_API_KEY and INTENT_MODEL.');
const intent = new Intent({
language: 'en',
executor: createApiExecutor({provider: 'openai', apiKey, model}),
});
const request: IntentParseRequest = {input: 'Look up order 000123. Do not cancel the order.'};
try {
const result = await intent.parse(request);
console.log(JSON.stringify(result, null, 2));
console.log('Goals:', result.effective.intents.map(node => node.goal));
console.log('Issues:', result.issues.map(issue => issue.message));
} catch (error) {
if (!(error instanceof IntentError)) throw error;
console.error(JSON.stringify(error.toJSON()));
process.exitCode = 1;
} finally {
await intent.dispose();
}
Use your existing TypeScript build. For an ESM project without TypeScript tooling:
npm install -D typescript @types/node
npx tsc basic.ts --outDir out --target ES2022 --module NodeNext --moduleResolution NodeNext --strict --skipLibCheck
node out/basic.js
These are TypeScript development tools; JavaScript users do not need them. Set the model name and API key before running.
4. Read the result
The result should preserve the lookup goal and the prohibition on cancellation. The order ID appears in the natural-language goal. Extracting it into inputs requires a Schema and selecting orderId. Wording and generated IDs can vary.
Download the complete no-Schema example or read the Native response with an order field.
- effective.intents is the goal tree; read global and per-goal constraints.
- issues describes ambiguity, missing information, and conflicts. Ask for information rather than choosing a candidate yourself.
- fields defaults to []; omitting it still recognizes intent without new business field extraction.
- complete does not mean all fields are valid, permission is granted, or business work is done. This program does not query or cancel orders.
Continue with Read the result, or run the field and multi-turn examples. See Model APIs for other providers and Errors when a call fails.