πŸ₯ž
Glif Docs/Guide
  • Getting Started
    • πŸ‘‹What is Glif?
    • πŸ’‘What can I do with a glif?
      • πŸƒRun a glif
      • πŸ”ŒBuild a glif
      • πŸ”€Remix a glif
      • πŸ—£οΈComment on a glif
      • πŸ”³Embed a glif
    • βš’οΈHow do I build a glif?
      • πŸ“½οΈVideo tutorial: Building a simple image generator
      • 🟰Using variables
    • βš™οΈProfile Settings
    • πŸͺ™Credits and Payments
    • ❓FAQs
  • Blocks
    • πŸ™‹Inputs
      • ✍️Text Input Block
      • πŸ–ΌοΈImage Input Block
      • πŸ“‹Multipick Block
    • πŸͺ„Generators
      • πŸ“ƒText Block
      • πŸ–ΌοΈImage Block
      • ➑️Image to Text Block
        • Florence2Sam2Segmenter
    • 🧰Tools
      • πŸ”€Text Combiner Block
      • πŸ”¬JSON Extractor Block
    • πŸ’…Styling
      • 🎨HTML Block
      • πŸ–ΌοΈCanvas Block
    • πŸ§‘β€πŸ”¬Advanced/Experimental
      • πŸŽ™οΈAudio Input Block
      • ↔️Glif Block
      • 🌐Web Fetcher Block
      • πŸ”ŠAudio Spell
      • 🧱ComfyUI Block
      • πŸ“‘Audio to Text Block
      • πŸŽ₯Video Input Block
      • πŸ”§JSON Repair Block
  • Apps
    • 🎨Glif It! Browser Extension
  • Glif University
    • πŸŽ₯Video Tutorials
      • 🐲How To: D&D Character Sheet Generator
      • 🧠How To: Expanding Brain Meme Generator
      • πŸ¦‘How To: Occult Memelord Generator
      • πŸ₯ΈHow To: InstantID Portrait Restyle Glif
      • πŸ•ΊHow To: Style and Pose a Character with InstantID + Controlnet
      • 😱How To: Create a Simple Cartoon Portrait Animation Glif (LivePortrait + Custom Blocks)
      • πŸ‘—How to Create a Clothing Restyler App (IP Adapter, ControlNet + GPT Vision)
      • 🀑How to Create a 4+ Panel Storyboard/Comic (Flux Schnell)
      • πŸŽ‚How to Create a Recipe Generator with Accompanying Pictures
      • How to Use JasperAI Depth Controlnet on Flux Dev
      • πŸ¦Έβ€β™‚οΈHow to Make a Consistent Comic Panel Generator
    • πŸ§‘β€πŸ«Prompt Engineering 101
    • πŸ–ΌοΈControlNet
    • πŸ“šAI Glossary
  • API - for Developers
    • ⚑Running glifs via the API
    • πŸ€–Using AI Assistants to build with the Glif API
    • πŸ“™Reading & writing data via the API
    • πŸ—ΎGlif Graph JSON Schema
    • πŸ“«Embed player & custom webpages
    • πŸ“«Sample code
    • ❓What can I make with the Glif API?
      • Browser Extensions
      • Discord Bots
      • Games
      • Social Media Bots
      • Experimental Projects
  • Policies
    • πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦Community Guidelines
  • Programs
    • πŸ–ΌοΈLoradex Trainer Program
  • Community Resources
    • πŸ§‘β€πŸ€β€πŸ§‘Resources Created by Glif Community Members
  • Contact Us
    • πŸ“£Send us your feedback
    • πŸš”Information for law enforcement
Powered by GitBook
On this page
  • Running glifs using the Simple API
  • Parameters
  • Looking up the internal names of a glif's inputs
  • ⚠️ Strict mode and default glif input value substitution
  • ⚠️ CORS (cross-origin requests)
  1. API - for Developers

Running glifs via the API

PreviousAI GlossaryNextUsing AI Assistants to build with the Glif API

Last updated 1 month ago

The Glif API is unstable and in beta, but we’re excited to see what y'all build.

To get started, create your API tokens on

The API is currently subject to the same limits as user accounts, you can purchase more credits at . see details. This is all subject to change without notice.

If you're building with our API, please or since we'd love to chat and learn more about what you're building. For selected apps we can extend a higher rate limit during this free testing period.

We ask that you include β€œpowered by glif.app” and a link to within the UI of your integration. Please use a Glif logo badge in the zip file below.

Running glifs using the Simple API

The Simple API requires an API token to make requests

curl -X POST -H "Authorization: Bearer abzfasdf2349820349" -d '{"id": "clgh1vxtu0011mo081dplq3xs", "inputs": ["cute friendly oval shaped bot friend"]}' https://simple-api.glif.app
import requests

response = requests.post(
    "https://simple-api.glif.app",
    json={"id": "clgh1vxtu0011mo081dplq3xs", "inputs": ["cute friendly oval shaped bot friend"]},
    headers={"Authorization": "Bearer abzfasdf2349820349"},
)
print(response.content)
const apiToken = 'abzfasdf2349820349';
const data = {
  id: "clgh1vxtu0011mo081dplq3xs",
  inputs: ["cute friendly oval shaped bot friend"]
};
const response = await fetch('https://simple-api.glif.app',
  {
    method: 'POST',
    headers: {
        'Authorization': `Bearer ${apiToken}`,
        'Content-Type': 'application/json'
    },
    body: JSON.stringify(data)
});
const result = await response.json();
console.log(result);

Here’s the expected output of that command:

{
  "id": "clgh1vxtu0011mo081dplq3xs",
  "inputs": { "node_6": "cute friendly oval shaped bot friend" },
  "output":"<https://res.cloudinary.com/dzkwltgyd/image/upload/v1686242317/glif-run-outputs/fhbvbp9bwf0pkmm4woj2.png>",
  "outputFull": { "...": "" }
}

You're most likely interested in the output field, which is the final output of the glif.

outputFull is a JSON object with more info about the final output, including it's type.

If there’s an error it’ll be in an error field, but the response will have a "200 OK" status code. For legacy reasons the the Simple API always returns 200 OK. This might change in the future.

Parameters

id

You can put the glif id in the url:

https://simple-api.glif.app/clgh1vxtu0011mo081dplq3xs

Or put it in the body:

{
  "id": "clgh1vxtu0011mo081dplq3xs",
  "inputs": ["..."]
}

inputs

for now only string values are allowed

You can either use a positional array:

{
  "inputs": ["a happy horse", "living on a farm", "in France"]
}

Or name your parameters. The names have to correspond to your glif-block names. If you don't know the block names, check out Looking up the internal names of a glif's inputs.

{
  "inputs": {
    "param1": "a happy horse",
    "param2": "living on a farm",
    "param3": "in France"
  }
}

Looking up the internal names of a glif's inputs

To specify named parameters, you need to use the internal block name. This has no spaces and usually is something like "text1", "multipick2", but each glif creator can customize it.

Or you can look at the nodes field of a glif's data via our API:

username
ego
radmilk
text1
Full example Glif API response JSON
[
  {
    "id": "clkbasluf0000mi08h541a3j4",
    "name": "chat.welcome",
    "imageUrl": null,
    "description": "",
    "createdAt": "2023-07-20T15:19:11.511Z",
    "updatedAt": "2023-12-01T11:59:23.279Z",
    "output": "Welcome to our Discord Chat, @jamiedubs, where creativity's at!\nWith Tanaki as your guide, prepare for a delightful ride.\nWe'll connect ideas across the land, with art and magic at our command.\nSo join us now, let's collaborate, and create wonders that resonate.",
    "outputType": "TEXT",
    "forkedFromId": null,
    "featuredAt": null,
    "userId": "cli4waaz20002l5082wrs99bx",
    "completedSpellRunCount": 3,
    "user": {
      "id": "cli4waaz20002l5082wrs99bx",
      "name": "tanaki",
      "image": "https://cdn.discordapp.com/avatars/1111720492408262686/a355dbcf07ce472fc7bc382cf0807802.png",
      "username": "tanaki"
    },
    "spheres": [],
    "data": {
      "nodes": [
        {
          "name": "username",
          "type": "TextInputBlock",
          "params": {
            "label": "@username to greet",
            "value": "harrystyles"
          }
        },
        {
          "name": "ego",
          "type": "GlifBlock",
          "params": {
            "id": "clj359oq70000le08nog0a0sb",
            "inputValues": []
          }
        },
        {
          "name": "radmilk",
          "type": "GlifBlock",
          "params": {
            "id": "clpmk3e3x000xqrpfuxrjq6gl",
            "inputValues": []
          }
        },
        {
          "name": "text1",
          "type": "GPTBlock",
          "params": {
            "api": "chat",
            "model": "gpt-4",
            "prompt": "{ego}\nplease keep the above in mind.\n\nI need you to welcome a new user to a discord chat.\n\nAdd a joke in the style of some example jokes. Share the joke as if it were a fact and you are mitch hedberg. Make it weird and under 2 sentences. Don't mention it is a joke. Just tell the joke. Play with their name. Add linebreaks and markdown to format your message where needed.\n\nExample jokes:\n{radmilk}\n\n\nTheir username is:\n{username}\n\nNow write the welcome message in no more than 2 short sentences:\n\n",
            "maxTokens": 500,
            "temperature": 0.9
          }
        }
      ]
    },
    "_count": {
      "likes": 0,
    }
  }
]

Lastly, you can use the commandline to fetch field names dynamically using curl + jq:

curl -s https://glif.app/api/glifs?id=clmdnx8fa0000lf0fbovo8lv1 | jq -r '.[] .data .nodes[] .name'

here's the output:

input1
image1

meaning this glif requires two inputs, input1 and image1. We plan to improve this in the near future.

⚠️ Strict mode and default glif input value substitution

If you do not provide enough inputs, the default values in the glif values will be automatically substituted.

So if you specify arg1, that'll be used, but if it requires arg1 and arg2, it'll use your arg1 but use the defualt value for arg2.

If you'd prefer to have API calls with insufficient inputs to fail, append ?strict=1 to your URLs, e.g. https://simple-api.glif.app?strict=1

⚠️ CORS (cross-origin requests)

CORS is allowed by the Simple API, but not by our other API endpoints. You'll need to make your own serverside wrappers for these cases.

On the glif.app website you can look at the block names in the "View source" page of a glif, :

This glif has blocks with the names:

⚑
like this one
https://glif.app/api/glifs?id=clkbasluf0000mi08h541a3j4
https://glif.app/settings/api-tokens
https://glif.app/pricing
FAQ
join our Discord
get in touch
glif.app
Register for your free token here
145KB
glif_badges.zip
archive
little diagram on the "View Source" page which shows the names of each block