TL;DR

import Itzam from "itzam";

const itzam = new Itzam(process.env.ITZAM_API_KEY);

// Send the text generated to the URL provided
export const sendMessageToWebhook = async (message: string) => {
  return await itzam.generateText({
    input: "What is the capital of France?",
    workflowSlug: "french-chatbot",
    type: "event",
    callback: {
      url: "https://yoursite.com/webhook",
      headers: {
        Authorization: "your_secret_key",
      },
    },
  });
};

Webhooks

Webhooks are a way to send the text/object generated by AIs to a URL you provide. To use a webhook, you need to install the Itzam SDK.
npm install itzam
# or
yarn add itzam
# or
pnpm add itzam
Then, you can initialize the Itzam client with your API key.
import Itzam from "itzam";

const itzam = new Itzam(process.env.ITZAM_API_KEY);

Sending text responses

For this example, let’s imagine you want to send AI responses to your website. This is how you can do it:
export const sendMessageToWebhook = async (question: string) => {
  const response = await itzam.generateText({
    input: question,
    workflowSlug: "french-expert",
    type: "event", // Use this type to indicate that you are using webhooks
    callback: {
      url: "https://yoursite.com/webhook", // The URL to send the response to
      // You can add headers to the request
      headers: {
        Authorization: "your_secret_key",
      },
      // You can also add a custom properties object to the response
      customProperties: {
        user_id: "user_123",
      },
    },
  });

  return response;
};
The webhook body will look like this:
{
  "object": {
    "response": "The least populated city in France is Rochefourchat."
  },
  "metadata": {
    "cost": "0.0000114",
    "model": {
      "name": "Gemini 2.0 Flash",
      "tag": "google:gemini-2.0-flash"
    },
    "durationInMs": 742,
    "inputTokens": 38,
    "outputTokens": 19,
    "runId": "01981e5d-d5ea-768c-98e1-462fb1d43d92"
  },
  "customProperties": {
    "user_id": "user_123"
  }
}

Sending object responses

You can also send object responses to your webhook. This is how you can do it:
const schema = z.array(
  z.object({
    name: z.string(),
    description: z.string(),
  })
);

export const sendMessageToWebhook = async (question: string) => {
  return await itzam.generateObject({
    input: question,
    workflowSlug: "marvel-movies",
    schema,
    type: "event",
    callback: {
      url: "https://yoursite.com/webhook",
      headers: {
        Authorization: "your_secret_key",
      },
      customProperties: {
        user_id: "user_123",
      },
    },
  });
};
The webhook body will look like this:
{
  "object": [
    {
      "name": "The Avengers",
      "description": "The Avengers is a 2012 American..."
    },
    {
      "name": "Thor",
      "description": "Thor is a 2011 superhero film..."
    }
  ],
  "metadata": {
    "cost": "0.0000114",
    "model": {
      "name": "Gemini 2.0 Flash",
      "tag": "google:gemini-2.0-flash"
    },
    "durationInMs": 742,
    "inputTokens": 38,
    "outputTokens": 19,
    "runId": "01981e5d-d5ea-768c-98e1-462fb1d43d92"
  },
  "customProperties": {
    "user_id": "user_123"
  }
}

Conclusion

That’s it! Now you can send AI responses to any URL you want.