Skip to content

Development guide

How do I use HawkFlow.ai in my code?

To make sending data to HawkFlow.ai easy for you, we have provided packages in multiple languages. See below for how to install the packages.

pip install hawkflow
// coming soon - in the meantime you can get started by using our REST API
go get github.com/hawkflow/hawkflow-go
// coming soon - in the meantime you can get started by using our REST API
// coming soon - in the meantime you can get started by using our REST API
# coming soon - in the meantime you can get started by using our REST API
composer require hawkflow/hawkflow-php @dev

If you do not see your language here, you can send data to our API using HTTP POST requests. See the REST API docs for examples.

Authentication

HawkFlow.ai uses an API key to authenticate to our API. You receive an API after making an account. There are two ways that you can use the API key to authenticate.

Authentication using an environment variable

Set the api key value in an environment variable named "HAWKFLOW_API_KEY". You can do this using the command:

export HAWKFLOW_API_KEY=your-api-key-here

Authentication using code

If you do not have access to the machine to be able to set an environment variable, you can send the api key through in your code when you create the HawkFlowAPI object. See the code example below on how to do this.

from hawkflowclient.hawkflow_api import *

hf = HawkflowAPI(api_key="YOUR_API_KEY")
// coming soon - in the meantime you can get started by using our REST API
package main

import "github.com/hawkflow/hawkflow-go"

func main() {    
    hf := hawkflow.New("YOUR_API_KEY")
}
// coming soon - in the meantime you can get started by using our REST API
// coming soon - in the meantime you can get started by using our REST API
# coming soon - in the meantime you can get started by using our REST API
<?php

use HawkFlow\HawkFlow\HawkFlow;

$hf = new HawkFlow("YOUR_API_KEY");

Timed API - Monitor code performance

What is the Timed API endpoint used for?

The Timed API endpoint is used to time any part of your code.
See below on how to use it. See the [concepts](../concepts/index.md) page for all the benefits and features
that you receive by using the Timed API endpoint.

There is a start endpoint to use when a process is starting, and another endpoint to use when the process is ending. 
Both endpoints take the same paramters.

** Timed API parameters **

Parameter Type size format Required Description
process string max length 250 string, ',",% will be stripped required The Process name
meta string max length 500 string, ',",% will be stripped optional The meta details about your process
uid uuid max length 50 allowed a-z, 0-9, -_ optional Unique process identifier. If you would like to send multiple processes that run at the same time using the same values for process and meta, then you can use this parameter to identify their uniqueness
from hawkflowclient.hawkflow_api import *

hf = HawkflowAPI(api_key="YOUR_API_KEY")

# using explicit start and end API calls, time any part of your code
def example_function_to_time():
    hf.start("process_name", "your meta data")
    # your code
    hf.end("process_name", "your meta data")
from hawkflowclient.hawkflow_decorators import *

# send your api_key here, if you would like to send meta data, 
# use the optional 'hawkflow_meta' parameter shown below
@HawkflowTimed(api_key="YOUR_API_KEY")
def example_function_to_time(hawkflow_meta=""):
    # your method or function code
// coming soon - in the meantime you can get started by using our REST API
package main

import "github.com/hawkflow/hawkflow-go"

func main() {
    hf := hawkflow.New("YOUR_API_KEY")

    _ = hf.Start("hawkflow_examples", "", "")

    // your code

    _ = hf.End("hawkflow_examples", "", "")
}
// coming soon - in the meantime you can get started by using our REST API
// coming soon - in the meantime you can get started by using our REST API
# coming soon - in the meantime you can get started by using our REST API
<?php

use HawkFlow\HawkFlow\HawkFlow;

$hf = new HawkFlow("YOUR_API_KEY");

$hf->start("your_process_name", "your meta data");

// your code

$hf->end("your_process_name", "your meta data");

Metrics API - Monitor numerical values

What is the Metrics API endpoint used for?

The Metrics API endpoint is used to send HawkFlow any numerical value.
See below on how to use it. See the [concepts](../concepts/index.md#metrics) page for all the benefits and features
that you receive by using the Metrics API endpoint.
Parameter Type size format Required Description
process string max length 250 string, ',",% will be stripped required The Process name
meta string max length 500 string, ',",% will be stripped optional The meta details about your process
items dictionary, see curl example below for more details max length 50 items dict key: string, ',",% are not allowed. Value: any numerical required You can send multiple metrics at once in a dictionary.
from hawkflowclient.hawkflow_api import *

hf = HawkflowAPI(api_key="YOUR_API_KEY")

items = {
    "model_accuracy": 0.85,
    "number_of_rows_inserted": 15664,
    "users": 133
} 

hf.metrics("process_name", "your meta data", items) 
// coming soon - in the meantime you can get started by using our REST API
package main

import "github.com/hawkflow/hawkflow-go"

func main() {
    hf := hawkflow.New("YOUR_API_KEY")

    items := map[string]float64{
        "model_accuracy": 0.85,
        "number_of_rows_inserted": 15664,
        "users": 133,
    }

    _ = hf.Metrics("hawkflow_examples", "your meta data", items)
}
// coming soon - in the meantime you can get started by using our REST API
// coming soon - in the meantime you can get started by using our REST API
# coming soon - in the meantime you can get started by using our REST API
<?php

use HawkFlow\HawkFlow\HawkFlow;

$hf = new HawkFlow("YOUR_API_KEY");

$items = [
    "model_accuracy" => 0.85,
    "number_of_rows_inserted" => 15664,
    "users" => 133,
];

$hf->metrics($items, "your_process_name", "your meta data");

Exception API - Monitor exceptions

What is the Exception API endpoint used for?

The Exception API endpoint is used to send HawkFlow exceptions that occur in your code.
See below on how to use it. See the [concepts](../concepts/index.md#exceptions) page for all the benefits and features
that you receive by using the Exception API endpoint.
Parameter Type size format Required Description
process string max length 250 string, ',",% will be stripped required The Process name
meta string max length 500 string, ',",% will be stripped optional The meta details about your process
exception string max length 15000 any string required The text of the exception
import traceback

from hawkflowclient.hawkflow_api import *

hf = HawkflowAPI("YOUR_API_KEY")

try:
    # your code that may throw an exception
except Exception as err:
    # catch and send exceptions through to hawkflow 
    hf.exception("hawkflow_examples", "your meta data", traceback.format_exc())
// coming soon - in the meantime you can get started by using our REST API
package main

import "github.com/hawkflow/hawkflow-go"

func main() {
    hf := hawkflow.New("YOUR_API_KEY")

    err := userFunction()
    if err != nil {        
        // catch and send error through to hawkflow
        _ = hf.Exception("hawkflow_examples", "your_meta_data", err.Error())
    }
}

func userFunction() error {
    // your code that may return an error
}
// coming soon - in the meantime you can get started by using our REST API
// coming soon - in the meantime you can get started by using our REST API

<?php

use HawkFlow\HawkFlow\HawkFlow;

$hf = new HawkFlow("YOUR_API_KEY");

try {
    // your code that may throw an exception
} catch (\Exception $e) {
    // catch and send exceptions through to hawkflow 
    $hf->exception($e->getMessage(), "hawkflow_examples", "your meta data");
}

API Response Codes

Code Status Meaning
201 created Successful use of the API
500 error Please check the response for the error details
401 unauthorized Failed to authenticate using your api key
422 incorrect data Incorrect JSON data sent to the endpoint. Please check the response for the error details