Instant API Observability

Instant API Observability

Matt Ward

By Matt Ward

Published 1/31/2024 - 2 min read

We’ve all shipped code that relies on APIs. I suspect most of us have slapped a bunch of duct tape around those API calls to monitor them and maybe even alert when something isn’t behaving as it should – or maybe you are more the YOLO type and have always thought “that’s not worth my time.”

What if monitoring your API calls was a one-liner?

Well we did just that. Simply set your SDK’s base URL to use our proxy and you will get full request + response logs as well as performance metrics for all of your API calls, instantly!

First log in to the CLI and create a magic domain:

apoxy domains create --magic --random

A “magic key” will be returned which you can use to create a new base URL for your SDKs. These keys look something like k3anuenu2ins11wu9uzjks8pkz and they will be displayed in your domains list as k3anuenu2ins11wu9uzjks8pkz.apoxy.io.

Now that you’ve got the magic key, simply update your SDK:

const openai = new OpenAI({
  apiKey: env.OPENAI_API_KEY,
  baseURL: "https://k3anuenu2ins11wu9uzjks8pkz.api.openai.com.apoxy.io/v1",
});

Many SDKs actually support setting the base URL via an environment variable, which might be even quicker to integrate because you do not even need to edit your code. On platforms such as Vercel or Fly.io, these configuration changes are quick an easy to make in the UI. You could even create different Apoxy Cloud projects to separate your development environment from your production data. In this example that uses the Open AI SDK, the environment variable method is supported:

export OPENAI_BASE_URL="https://k3anuenu2ins11wu9uzjks8pkz.api.openai.com.apoxy.io/v1"

So what is this doing?

Given that the base URL for the hottest API of 2023/24 is https://api.openai.com/v1 – you can simply take the hostname of api.openai.com and drop it into the template:

Rather than your calls going directly to OpenAI servers, they will be routed through Apoxy’s secure global proxy infrastructure.

Can I monitor webhooks too?

Webhooks are really reverse API calls, so yep! If you have configured the application sending the webhook to use https://awesome.app/v1/example/webhook then all you need to do is update that configuration to use https://k3anuenu2ins11wu9uzjks8pkz.awesome.app.apoxy.io/v1/example/webhook and voilà! Now you’ve got logs for all your integrations.

The best part?

You can quickly find API calls by headers or a JSON field in the request/response body!

Sign up to give it a try for free today.