Skip to content

Getting Started with Integral

The Integral is where you create your API handlers. A single Integral can handle multiple traditional API requests as defined by your prompt

NOTE

You need to setup your environment before creating Integral

Creating Basic Integral

To create an Integral, simply pass in the required parameters to the CLI command and deploy. Let's go into detail

Run this command and follow the prompts

fish
reasonai api add

# Follow the wizard and provide the following responses
> Enter API name: # getStarSignAPI
> Write the main instruction for the model:
#   Write your prompt/instruction here. You can edit later
#   e.g Given a person's birth month and year, you return their star sign as a json object containing {sign:string}
> Select a generative model to use:
#   e.g claude-3.5-sonnet
> Response format: # JSON

When done, a new API will be created under ./reason/integrals/getStarSignAPI with JSON config similar to the following:

json
{
  "name": "getStarSignAPI",
  "instruction": "Given a person's birth month and year, you return their star sign as a json object containing {sign:string}",
  "model": "gpt-4o-mini",
  "responseFormat": "json_object"
}

Great! Now let's run this command to deploy the API so we can start using it:

bash
reasonai api push

That's it. Your Integral is deployed and live

Testing your API

bash
curl https://reasonai.dev/api/v1/request \
  -X POST \
  -H "Authorization: Bearer <your api key here>" \
  -d '{
    "apiId": "<copy from ./reason/.meta.json>",
    "messages": [
      {
        "role": "user",
        "content": "what is the starsign of a person born in April 1992"
      }
    ]
  }'

You should receive results similar to:

json
{
  "id": "<your-api-id>",
  "threadId": "thread_6zY61bNiZX08Yt15MVolgaue",
  "messages": {
    "id": "msg_54vENtcnHHojV8sBL7HkB7ol",
    "role": "assistant",
    "content": [
      {
        "type": "text",
        "text": "{\"sign\":\"Aries\"}"
      }
    ]
  }
}

TIP

To learn more on effective prompt generations, click here
To see the full API reference for creating an Integral, click here

Next Steps

You've learned how to create an Integral, next: