Overview
Async Integration let’s you log events and calls without placing Helicone in your app’s critical
path. This ensures that an issue with Helicone will not cause an outage to your app.
Install Helicone Async
npm install @helicone/async
Initialize Logger
import { HeliconeAsyncLogger } from "@helicone/async";
import OpenAI from "openai";
const logger = new HeliconeAsyncLogger({
apiKey: process.env.HELICONE_API_KEY,
// pass in the providers you want logged
providers: {
openAI: OpenAI,
//anthropic: Anthropic,
//cohere: Cohere
// ...
}
});
logger.init();
const openai = new OpenAI();
async function main() {
const completion = await openai.chat.completions.create({
messages: [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who won the world series in 2020?"},
{"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
{"role": "user", "content": "Where was it played?"}
],
model: "gpt-3.5-turbo",
});
console.log(completion.choices[0]);
}
main();
Properties
You can set properties on the logger to be used in Helicone using the withProperties
method. (These can be used for Sessions, User Metrics, and more.)
const sessionId = randomUUID();
logger.withProperties({
"Helicone-Session-Id": sessionId,
"Helicone-Session-Path": "/abstract",
"Helicone-Session-Name": "Course Plan",
}, () => {
const completion = await openai.chat.completions.create({
// ...
})
})
Install Helicone Async
npm install @helicone/async
Initialize Logger
import { HeliconeAsyncLogger } from "@helicone/async";
import OpenAI from "openai";
const logger = new HeliconeAsyncLogger({
apiKey: process.env.HELICONE_API_KEY,
// pass in the providers you want logged
providers: {
openAI: OpenAI,
//anthropic: Anthropic,
//cohere: Cohere
// ...
}
});
logger.init();
const openai = new OpenAI();
async function main() {
const completion = await openai.chat.completions.create({
messages: [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who won the world series in 2020?"},
{"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
{"role": "user", "content": "Where was it played?"}
],
model: "gpt-3.5-turbo",
});
console.log(completion.choices[0]);
}
main();
Properties
You can set properties on the logger to be used in Helicone using the withProperties
method. (These can be used for Sessions, User Metrics, and more.)
const sessionId = randomUUID();
logger.withProperties({
"Helicone-Session-Id": sessionId,
"Helicone-Session-Path": "/abstract",
"Helicone-Session-Name": "Course Plan",
}, () => {
const completion = await openai.chat.completions.create({
// ...
})
})
Install Helicone Async
pip install helicone-async
Initialize Logger
from helicone_async import HeliconeAsyncLogger
from openai import OpenAI
logger = HeliconeAsyncLogger(
api_key=HELICONE_API_KEY,
)
logger.init()
client = OpenAI(api_key=OPENAI_API_KEY)
# Make the OpenAI call
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who won the world series in 2020?"},
{"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
{"role": "user", "content": "Where was it played?"}
]
)
print(response.choices[0])
Properties
You can set properties on the logger to be used in Helicone using the set_properties
method. (These can be used for Sessions, User Metrics, and more.)
session_id = str(uuid.uuid4())
logger.set_properties({
"Helicone-Session-Id": session_id,
"Helicone-Session-Path": "/abstract",
"Helicone-Session-Name": "Course Plan",
})
response = client.chat.completions.create(
# ...
)
Disabling Logging
You can completely disable all logging to Helicone if needed when using the async integration mode. This is useful for development environments or when you want to temporarily stop sending data to Helicone without changing your code structure.
# Disable all logging in async mode
logger.disable_logging()
# Later, re-enable logging if needed
logger.enable_logging()
# Disable all logging in async mode
logger.disable_logging()
# Later, re-enable logging if needed
logger.enable_logging()
When logging is disabled, no traces will be sent to Helicone. This is different from disable_content_tracing()
which only omits request and response content but still sends other metrics. Note that this feature is only available when using Helicone’s async integration mode.
Supported Providers
Other Integrations