API Endpoints

You can create a free account or log in if you already have one and get your API key.

#   Overview

Our API can be used with following domains:

  • api.grand.app (recommended)
  • api.usegrand.com (deprecated)

Following endpoints are supported by Grand:

Please use only https protocol with all the requests.

#   Authentication

We need following headers to be always present in your API requests.

KeyTypeRequired?DefaultDescription
x-auth-keyStringYesEmptyYour API Key
x-auth-secretStringYesEmptyYour API Secret

Both of these can be found in your dashboard.

#   /generate

For free-form text generation using GPT models.

URL: api.grand.app/generate

Method: POST

Request Format: JSON body

Response: JSON

E.g. Request body:

{
    "text": "Grand API is simple, easy and",
    "model_id": "Ukg1ClHdlG03aG7cAu8J", // id of GPT-J
    "creativity": 30,
    "stop": ".",
    "max": 50,
    "only_response": true
  }
KeyTypeRequired?DefaultDescription
textStringYesYour examples and prompt
stopStringYesThe stop character. Grand will stop the text generation when the given character is found. Details below on this page.
creativityIntYesThe level of creativity that you need from the model. Between 1 to 100. Lower number results in more precision while higher in creativity
nIntNo1The number of outputs you want to generate. Between 1 and 3. 🚨 It produces different response schema, see example below
top_kIntNo50Between 5 and 100
top_pFloatNo0.75Between 0.0 and 1.0
length_penaltyFloatNo1.0Lower the value, more concise the output will be. Between 0.0 and 1.0
repetition_penaltyFloatNo0.0Called uniqueness in the Playground. Higher the value, lower the repetition of earlier text. Between 0.0 and 1.0
model_idStringNoUkg1ClHdlG03aG7cAu8JID of the GPT model you want to use. Take a look at the Models page for details. Default: GPT-J
maxIntNo50The maximum number of tokens to generate.
only_responseBooleanNofalseSetting it to "true" will only not include the request text in the response.

E.g. Success Response:

{
    "ok": true,
    "id": "47eb786b",
    "data": {
      "text": " fast.",
    }
  }

E.g. Success Response with n: 3:

{
  "ok": true,
  "outputs": [
    {
      "id": "6917294e",
      "data": {
        "text": " effective."
      }
    },
    {
      "id": "e462fb11",
      "data": {
        "text": " useful."
      }
    },
    {
      "id": "cdf63f80",
      "data": {
        "text": " fast."
      }
    }
  ]
}

E.g. Error Response:

{
    "ok": false,
    "reason": "x-auth-key or x-auth-secret missing"
  }

#   /playbook/use

This endpoint is for using stored Playbooks through API. It only requires an input text and returns the output text.

You can find the Playbook id in the settings section of a Playbook.

URL: api.grand.app/playbook/use

Method: POST

Request Format: JSON body

Response: JSON

E.g. Request body:

{
    "input": "Who is Elon Musk?",
    "playbook_id": "0qhpjSjsSTFoMh2Gm0yO" # id of the 'Answer the questions based on known facts' Playbook.
  }
KeyTypeRequired?DefaultDescription
inputStringYesInput text for the Playbook
playbook_idStringYesThe ID of Playbook that you want to use. It can be found on the Playbook page.
maxIntNoAs stored in PlaybookThe maximum number of tokens to generate.
nIntNo1The number of outputs you want to generate. Between 1 and 3. 🚨 It produces different response schema, see example below
creativityIntNoAs stored in PlaybookThe level of creativity you want. Between 1 to 100
top_kIntNo50Between 5 and 100
top_pFloatNo0.75Between 0.0 and 1.0
length_penaltyFloatNo1.0Lower the value, more concise the output will be. Between 0.0 and 1.0
model_idStringNoAs stored in PlaybookID of the GPT model you want to use. Take a look at the Models page for details. Default: GPT-J

E.g. Success Response:

{
    "ok": true,
    "id": "5d58663e",
    "data": {
      "text": "Elon Musk is an American entrepreneur, investor, engineer, and inventor."
    }
  }

E.g. Success Response with n: 2:

{
  "ok": true,
  "outputs": [
    {
      "id": "240b3daf",
      "data": {
        "text": "Elon Musk is an American entrepreneur, engineer, investor, and designer, best known for his work on the electric car company Tesla, SpaceX, and the tunneling venture The Boring Company."
      }
    },
    {
      "id": "ef92beac",
      "data": {
        "text": "Elon Musk is a South African-born American entrepreneur, investor, engineer, inventor, and the founder, CEO, and lead designer of SpaceX and Tesla Motors."
      }
    }
  ]
}

#   /socket/create

You can create a socket connection for realtime text generation. This endpoint returns a WebSocket URL you can connect to from a client. Have a look at our guide on using WebSockets for AI response.

URL: api.grand.app/socket/create

Method: POST

Request Format: JSON body

Response: JSON

E.g. Request body:

{
    "ttl": 3600
  }
KeyTypeRequired?DefaultDescription
ttlIntegerNo3600Connections's Time To Live in seconds. Between 60 and 3600 (1 hour) seconds. TTL starts after the first connection.

E.g. Success Response:

{
    "ok": true,
    "ttl": 3600,
    "id": "vf93jf001",
    "url": "wss://api.grand.app/connect/6W3TjJFKID8290mnTLo/vf93jf001"
  }

#   Stop Signs

Grand only supports following stop values at the moment:

  • <newline> to stop at a new line character. i.e: \n
  • . Fullstop
  • , Comma
  • ? Question mark
  • : Colon
  • ; Semi-Colon
  • !!!
  • ###
  • ///

#   Sample Python and CURL Code

Generate usage with Python

Below is a sample code in Python for using our /generate endpoint.

import json
  import requests

  headers = {
    'x-auth-key': '<Your-API-Key>',
    'x-auth-secret': '<Your-API-Secret>',
    
    'Accept': 'application/json',
  }

  text = """
  Grand API is simple, easy and
  """

  body = {
    "text": text.rstrip(), # remove trailing spaces, yields much better results.
    "model_id": "Ukg1ClHdlG03aG7cAu8J",
    "creativity": 50,
    "stop": ".",
    "max": 50,
  }

  response = requests.post('http://api.grand.app/generate', json=body, headers=headers)
  jsonResponse = response.json()

  if jsonResponse.get('ok') == False:
    print(f"Error from Grand: {jsonResponse.get('reason')}")
  else:
    print(jsonResponse.get('data').get('text'))

Generate usage with cURL

curl -XPOST 'http://api.grand.app/generate' \
  -H 'x-auth-key: <Your-API-Key>' \
  -H 'x-auth-secret: <Your-API-Secret>' \
  -H "Content-type: application/json" \
  -d '{
    "text": "Grand API is simple, easy and",
    "model_id": "Ukg1ClHdlG03aG7cAu8J",
    "creativity": 50,
    "stop": ".",
    "max": 50
  }'

Playbook API usage with Python

Sample code in Python for using our /playbook/use endpoint.

import json
  import requests

  headers = {
    'x-auth-key': '<Your-API-Key>',
    'x-auth-secret': '<Your-API-Secret>',
    
    'Accept': 'application/json',
  }

  body = {
    "input": "Who is Elon Musk?",
    "playbook_id": "0qhpjSjsSTFoMh2Gm0yO" # id of the 'Answer the questions based on known facts' Playbook: https://grand.app/playbook/0qhpjSjsSTFoMh2Gm0yO
  }

  response = requests.post('http://api.grand.app/playbook/use', json=body, headers=headers)
  jsonResponse = response.json()

  if jsonResponse.get('ok') == False:
    print(f"Error from Grand: {jsonResponse.get('reason')}")
  else:
    print(jsonResponse.get('data').get('text'))

Playbook use in cURL

curl -XPOST 'http://api.grand.app/playbook/use' \
  -H 'x-auth-key: <Your-API-Key>' \
  -H 'x-auth-secret: <Your-API-Secret>' \
  -H "Content-type: application/json" \
  -d '{
    "input": "Who is Elon Musk?",
    "playbook_id": "0qhpjSjsSTFoMh2Gm0yO"
  }'