You can create a free account or log in if you already have one and get your API key.
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.
We need following headers
to be always present in your API requests.
Key | Type | Required? | Default | Description |
---|---|---|---|---|
x-auth-key | String | Yes | Empty | Your API Key |
x-auth-secret | String | Yes | Empty | Your API Secret |
Both of these can be found in your dashboard.
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
}
Key | Type | Required? | Default | Description |
---|---|---|---|---|
text | String | Yes |
| Your examples and prompt |
stop | String | Yes |
| The stop character. Grand will stop the text generation when the given character is found. Details below on this page. |
creativity | Int | Yes |
| The level of creativity that you need from the model. Between 1 to 100. Lower number results in more precision while higher in creativity |
n | Int | No | 1 | The number of outputs you want to generate. Between 1 and 3. 🚨 It produces different response schema, see example below |
top_k | Int | No | 50 | Between 5 and 100 |
top_p | Float | No | 0.75 | Between 0.0 and 1.0 |
length_penalty | Float | No | 1.0 | Lower the value, more concise the output will be. Between 0.0 and 1.0 |
repetition_penalty | Float | No | 0.0 | Called uniqueness in the Playground. Higher the value, lower the repetition of earlier text. Between 0.0 and 1.0 |
model_id | String | No | Ukg1ClHdlG03aG7cAu8J | ID of the GPT model you want to use. Take a look at the Models page for details. Default: GPT-J |
max | Int | No | 50 | The maximum number of tokens to generate. |
only_response | Boolean | No | false | Setting 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"
}
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.
}
Key | Type | Required? | Default | Description |
---|---|---|---|---|
input | String | Yes |
| Input text for the Playbook |
playbook_id | String | Yes |
| The ID of Playbook that you want to use. It can be found on the Playbook page. |
max | Int | No | As stored in Playbook | The maximum number of tokens to generate. |
n | Int | No | 1 | The number of outputs you want to generate. Between 1 and 3. 🚨 It produces different response schema, see example below |
creativity | Int | No | As stored in Playbook | The level of creativity you want. Between 1 to 100 |
top_k | Int | No | 50 | Between 5 and 100 |
top_p | Float | No | 0.75 | Between 0.0 and 1.0 |
length_penalty | Float | No | 1.0 | Lower the value, more concise the output will be. Between 0.0 and 1.0 |
model_id | String | No | As stored in Playbook | ID 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."
}
}
]
}
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
}
Key | Type | Required? | Default | Description |
---|---|---|---|---|
ttl | Integer | No | 3600 | Connections'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"
}
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!!!
###
///
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'))
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
}'
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'))
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"
}'