Erste Schritte

Schnellstart

Vier Schritte: Paket installieren, Schlüssel besorgen, Inhalte erzeugen und dann einen Agenten auf Ihrem Rechner arbeiten lassen. Das dauert etwa zehn Minuten und benötigt einige Credits.

node ≥ 18BrowserCloudflare Workers
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

1 · Installieren

npm install iagenify
# yarn add iagenify
python -m pip install iagenify

2 · Schlüssel angeben

Beim ersten Aufruf wird der Schlüssel gegen eine Sitzung ausgetauscht und danach nicht mehr gesendet. Bewahren Sie ihn auf dem Server auf.

import { IaGenify } from "iagenify";

const api = new IaGenify({
  apiKey: process.env.IAGENIFY_API_KEY,         // ia_...
  baseUrl: "https://api.iagenify.com",          // or set IAGENIFY_API_URL instead
});

console.log(api.env, api.framework);            // "node" "node"
console.log(await api.getUser());               // { id, email, credits, pack }
import os
from iagenify import IaGenify

api = IaGenify(
    api_key=os.environ["IAGENIFY_API_KEY"],
    base_url="https://api.iagenify.com",
)
print(api.env, api.framework)  # "python" "python"
print(api.get_user())
api.close()

3 · Inhalte erzeugen

const assistant = await api.models.create({
  model: "gemini-3.5-flash",
  settings: { role: "Technical writer", instructions: "Answer in one paragraph." },
  memory: true,
});

const result = await assistant.generate({
  inputs: [{ type: "text", content: "What is an execution trail?" }],
});

console.log(result.outputs[0].content);
console.log(result.usage);        // { credits: 4, inputTokens: 38, outputTokens: 96 }

await assistant.destroy();
assistant = api.models.create(
    model="gemini-3.5-flash",
    settings={"role": "Technical writer", "instructions": "Answer in one paragraph."},
    memory=True,
)

result = assistant.generate(inputs=[
    {"type": "text", "content": "What is an execution trail?"},
])
print(result["outputs"][0]["content"])
print(result["usage"])
assistant.destroy()
In Skripten angelegte Sitzungen anschließend löschen

Mit memory: true wird die Unterhaltung gespeichert. Ein Testskript, das seine Sitzungen zurücklässt, füllt das Konto mit Unterhaltungen, die niemand öffnet.

Strukturierte Ausgabe statt Fließtext

Übergeben Sie ein JSON Schema, damit die Antwort dessen Struktur entspricht. outputs[0].content ist dann ein JSON-String, den Sie parsen.

const extractor = await api.models.create({
  model: "gemini-3.5-flash",
  memory: false,
  schema: {
    type: "object",
    properties: {
      company: { type: "string" },
      amount:  { type: "number" },
      dueDate: { type: "string" },
    },
    required: ["company", "amount"],
  },
});

const { outputs } = await extractor.generate({
  inputs: [{ type: "text", content: invoiceText }],
});
const invoice = JSON.parse(outputs[0].content);
import json

extractor = api.models.create(
    model="gemini-3.5-flash",
    memory=False,
    schema={
        "type": "object",
        "properties": {
            "company": {"type": "string"},
            "amount": {"type": "number"},
            "dueDate": {"type": "string"},
        },
        "required": ["company", "amount"],
    },
)
response = extractor.generate(inputs=[{"type": "text", "content": invoice_text}])
invoice = json.loads(response["outputs"][0]["content"])

Dateien, Bilder oder Aufnahmen lesen

Eingaben sind typisiert. Sieben Typen werden unterstützt: text, image, file, video, audio, speech und passages.

import { readFileSync } from "node:fs";

await assistant.generate({
  inputs: [
    { type: "text",  content: "What does this contract commit us to?" },
    { type: "image", url: "https://example.com/page-1.png" },
    { type: "audio", content: readFileSync("./meeting.m4a").toString("base64"), mime: "audio/mp4" },
  ],
});
import base64
from pathlib import Path

result = assistant.generate(inputs=[
    {"type": "text", "content": "What does this contract commit us to?"},
    {"type": "image", "url": "https://example.com/page-1.png"},
    {"type": "audio", "content": base64.b64encode(Path("meeting.m4a").read_bytes()).decode(), "mime": "audio/mp4"},
])

4 · Den Agenten arbeiten lassen

Eine Modellsitzung beantwortet Fragen. Ein Agent erledigt Aufgaben: Er liest, sucht, bearbeitet, führt Befehle aus und fragt vor jedem unumkehrbaren Schritt nach.

const pc = await api.storage.get();          // this computer, as a storage

const agent = api.agents.create({
  runtime: "local",
  machine: pc,
  model: "gemini-3.5-flash",
  mode: "ask",                               // ask · auto · plan · full
  budget: 200,                               // credits; the run stops rather than overrun
  onPermission: async ({ tool, args, category }) => {
    console.log("asking for", tool, category);
    return "once";                           // "once" | "always" | "deny"
  },
});

const run = await agent.run({
  message: "Summarise every .md file in Notes/ into Notes/summary.md.",
  onEvent: (e) => {
    if (e.type === "text")      process.stdout.write(e.delta ?? "");
    if (e.type === "tool_start") console.log("\n→", e.tool, e.summary ?? "");
    if (e.type === "done")       console.log("\n", agent.usage);
  },
});

console.log(run.text);
console.log(agent.usage);        // { credits, turns, toolCalls }
console.log(agent.context);      // { tokens, limit, window, cachedTokens, parts }
machine = api.storage.get()
agent = api.agents.create(
    runtime="local",
    machine=machine,
    model="gemini-3.5-flash",
    mode="ask",
    budget=200,
    on_permission=lambda request: "once",
)

def on_event(event):
    if event["type"] == "text":
        print(event.get("text", ""), end="", flush=True)
    elif event["type"] == "tool_start":
        print("\n", event.get("tool"), event.get("summary", ""))

run = agent.run(
    message="Summarize every .md file in Notes/ into Notes/summary.md.",
    on_event=on_event,
)
print(run["text"])
print(run["usage"])

Das Schlussfolgern verfolgen

Zwölf Ereignistypen werden an onEvent übergeben. Die folgenden fünf bilden üblicherweise die Grundlage einer Oberfläche.

EreignisInhalt
textdelta — die fortlaufend übertragene Antwort
tool_startid, tool, args, summary, category
tool_endid, tool, ok, summary, credits, durationMs
permissiondie Anfrage, die Ihre onPermission-Funktion beantwortet
doneder Lauf ist beendet; agent.usage steht endgültig fest

Nächste Schritte