Skip to content

hyperdxio/sample-vercel-ai-sdk-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Integrating HyperDX with Vercel AI SDK OpenTelemetry

Install HyperDX SDK

npm install @hyperdx/node-opentelemetry

Initialize HyperDX SDK and enable experimental_telemetry flag

const HyperDX = require("@hyperdx/node-opentelemetry");

HyperDX.init({
  apiKey: "<YOUR_API_KEY>",
  service: "ai-sdk",
});

const { openai } = require("@ai-sdk/openai");
const { generateObject } = require("ai");


const main = async () => {
  const result = await generateObject({
    model: openai("gpt-4o-mini", {
      structuredOutputs: true,
    }),
    schemaName: "recipe",
    schemaDescription: "A recipe for lasagna.",
    schema: z.object({
      name: z.string(),
      ingredients: z.array(
        z.object({
          name: z.string(),
          amount: z.string(),
        }),
      ),
      steps: z.array(z.string()),
    }),
    prompt: "Generate a lasagna recipe.",
    experimental_telemetry: {
      isEnabled: true,
      functionId: "my-awesome-function",
      metadata: {
        something: "custom",
        someOtherThing: "other-value",
      },
    },
  });
  // Make sure to flush the telemetry data to HyperDX
  await HyperDX.shutdown();
};

Run the code

You can execute the sample program by running the following command:

HYPERDX_API_KEY=<YOUR_API_KEY> npm start

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published