---
url: 'http://workflows-of-ai.com/blog/api-first'
title: 'API First'
author:
  name: 'Marcus Johansson'
  url: 'http://workflows-of-ai.com/about/marcus-johansson'
date: '2023-11-13T17:33:33+01:00'
updated: '2026-10-10T12:14:04+02:00'
type: article
summary: 'Use the AI Interpolator Post OB Processor and JSON:API to run Drupal AI chains from any app, answer at once and poll until the work is done.'
tags:
  - 'Marcus Johansson'
  - Workflows
  - 'Drupal AI'
image: 'http://workflows-of-ai.com/sites/default/files/previews/ad56483fb4ea183e.jpg'
published: true
og:
  site_name: 'Workflows of AI'
  'image:width': '1280'
  'image:height': '720'
  'image:alt': 'API First'
---
Drupal AI

# API First

Run your AI Interpolator chains from any application over JSON:API and poll for the result instead of waiting on the request.

  Marcus Johansson

November 13, 2023 · 1 min read

 ## About this video

This goes through all the steps that you need to know to set up any of your chains using an API-first approach, instead of using the GUI or using Drupal for it.

I use the AI Interpolator Post OB Processor together with JSON:API and JSON:API Extras to turn a one-sentence title into a full article with a header image. The API answers right away, and you poll the article until its status says it is finished.

*This video is from before the AI Interpolator module became AI Automators, part of the [AI module](https://www.drupal.org/project/ai). Module and menu names have changed since, and some steps look different today.*

## Watch the video

[Watch on YouTube: API First](https://www.youtube.com/watch?v=TaHZhNRpgb8)

### Video chapters

- 0:00 What the Post OB Processor does
- 3:13 Why run AI chains over an API
- 7:17 Drupal as a content framework
- 10:57 Installing JSON:API Extras
- 11:53 Building the article content type
- 15:07 Batch, cron and direct workers
- 18:21 Configuring JSON:API Extras
- 22:47 Opening permissions for the API
- 24:34 How the output buffer helps
- 27:05 Polling until the article is done

## Transcript

YouTube's automatic captions, lightly corrected. Click a line to jump to that moment in the video.

### Transcript

- 0:01 hey there Marcus here um today I'm going to talk about uh it's not actually a workflow so what I'm going to do is I'm going to um set up and use something called the
- 0:17 AI Interpolator post OB processor so that's the module you see here and what this does it basically opens up the AI Interpolator for API usages so Drupal comes with a lot of uh
- 0:32 well it comes with JSON:API but you can also basically extend it to use any uh API Service uh and for those that don't know I will just introduce this first you're
- 0:45 what you're seeing in front of you is a vanilla Drupal site I have added admin toolbar I have added the AI Interpolator modules and the these are the extra features that I add on top of Drupal
- 0:56 then that I have developed uh that are open source um what I am uh going to show you today it's then very different from what I show normally so normally I show just
- 1:12 how you connect you know different AI Services together in this uh use case I'm going to show you how you can set up from scratch uh API service instead where you can basically take single
- 1:25 input multiple inputs uh use AI services or other kind of processors on this uh to change this content into something else so in this case I'm going to make something that's
- 1:38 very stupid nothing that makes really sense I'm just going to create articles from one one sentence uh and an article and article image using OpenAI and Del in this
- 1:52 case uh the AI Interpolator has a lot of services we're up to 14 now I think that you can basically chain so there's a lot of use cases for it I've started creating videos for it but this uh
- 2:06 there's so much ways you can basically combine this that are not documented that I haven't done videos for but there will come more and more videos when I have time basically but I there's
- 2:19 probably hundreds of use cases where you can actually combine this into different services so it could be it's completely multimod you can take anything you can
- 2:28 input a text you can inut put a audio file with someone talking you can input a image that you want to describe do multiple steps there uh where you can do stuff that gets
- 2:40 outputed as text as images as audio full audio and I mean truly podcast you can generate so say that you want to uh I've seen these services available where you
- 2:53 can for instance input a URL uh and after some time you get a podcast output put the right where two people or three people are talking about the subject in this
- 3:06 article uh this is super simple to set up the whole back end you will just have to focus on the front end in this case uh so the reason to use API then is of course you might first of all not want
- 3:18 to use the Drupal front end you might want to run Drupal headless and then uh generate um the front end using react angular View something like that but it's also Drupal is very opiniated uh
- 3:34 not Everyone likes CMS or cmf systems uh so of course if you built a system in some other tool that you prefer even if it's you could be outside of PHP world even you know write
- 3:46 something node write something Java whatever yeah you can still use the Drupal and the AI Interpolator to combine all the different uh AI stuff uh via aui and the advantage of that is of
- 4:03 course that AI is not deterministic right if I set up a database set certain indexes and ask it to store something I know exactly what will happen that's deterministic I know the output I get if
- 4:16 I do a get request to it if I write a specific function I well I might add a bug into the function but usually I know what I input and what I am supposedly getting as output with AI it's not like
- 4:30 this you can guess what you're going to get as output but it might not be true and then you might want to chain a lot of stuff so if you take the podcast example what you need to do uh with AI
- 4:41 uh well if you don't have the AI Interpolator you need to use something like a scraping tool or let's take it one more another step you you want to search and uh research some news fat of
- 4:55 the day so say the the um yeah whatever it can be there's a volcano being uh exploding now in might that might explode in Iceland so say that you want to analyze 10 articles from
- 5:13 this uh you want to scrape these articles you want to create a summary of this article and then you want to create a summary of this summary and then use this summary to create a script for a
- 5:24 podcast and with this podcast you want to create a MP3 where multiple people are talking to each other with personalities and everything right if you're going to do this using LangChain
- 5:35 or something you need to code there is no other way around it you know you need to know how to code they're starting to get up chaining tools that you can pay for but this is completely open source
- 5:47 anything you see here you can do afterwards of course you have to pay for the services they're not going to generate stuff for you for free but as long as you pay for the services
- 5:56 actually chaining them and prototyping this because since I said what I said it's not deterministic something might go wrong in this chain and you don't want to spend a week or two weeks to
- 6:08 prototype something in JavaScript or python or something and then it turns out okay I can't actually get the end result I want instead you can basically set it up in couple yeah 20 minutes in
- 6:20 in the AI Interpolator it's gooey based anyone can do it the project manager can do it the the uh the CEO can do it if you want you just need to know how to prompt correctly right uh so it's very
- 6:34 good for that and because of this I think there might be people that want to try this out with this and then they find a product and then they say well this is fine we can keep it here we
- 6:44 don't want to spend the time on developing this but we don't like Drupal so we just keep that there and then we can make API call with inputs and get response with this output so
- 6:56 maybe if we take the podcast example you just just going to make API call that uh is just a search word and you're going to pull it until you see okay it's finished and here we have MP3 and that's
- 7:08 my result um and I just want to mention this uh because uh with Drupal 7 something Drupal 7 to Drupal e something happened where it lost its popularity among the
- 7:26 masses because basically it went away from being a hobby programming CMS similar to or I'm not going to say hobby that's uh that sounds like a very negative connotation I mean WordPress
- 7:39 currently you don't need to know that much about development and you can create a really great website and for articles for blog posts this kind of news sites best content management
- 7:52 system there is Drupal went another path path where they wanted to make everything Enterprise what is great with this is that the developers that work with it usually
- 8:04 knows what they're talking about which means that if you hire a Drupal developer create a project and that guy quits if you find another Drupal developer that person probably knows the
- 8:14 same stuff uh but what it's also great at is that it's a Content management framework that's why the goo is not as easy to use as WordPress it's not in general as easy
- 8:28 to use as WordPress there's not a plugin for everything there used to be in Drupal 7 and that's what changed in Drupal 8 then it became more professional more developer Centric
- 8:38 less site Builder Centric but what does exist that there is there there is a great framework for how every field looks like which means that for AI services this is already done so if we
- 8:53 need validation on a address field this is already done if uh OpenAI since it can generate Json what what isable uh what is available in the AI Interpolator is that you can basically
- 9:09 take a text search for locations like Eiffel Tower or something check these with Google Places check that it exists then get the address of it and map it on a Google Maps so we're talking about
- 9:23 really complex field that you can just set up within minutes using uh just a guy tool no development no programming needed uh so for this the inator is perfect that's why I I mean I I I
- 9:41 started looking at LangChain and that's great you can create something extremely sturdy so if you're going to create Big Data if you're going to create a software as a service where you know you
- 9:51 have a lot of customers so you have the money to set it up to work on a big development team LangChain in in uh no or LangChain in Python is great and there's so much more services but if you
- 10:04 just want to test something this is fabulous um so as I said this video is completely different from the other I probably talked more in this introduction than I
- 10:17 than the normal video is I will also mention I don't have anything prepared there might be some bugs on the way uh usually the videos are so simple that you don't see any bugs because it's so
- 10:30 simple to set up the interpolations uh that there is no time for bugs in this case I need to set up apis and stuff so because of this there might be bugs but that's maybe good to
- 10:43 see that not everything works flawlessly by clicking around and I had a script where I made everything perfect the only thing I will show you that I have prepared is basically the API requests
- 10:55 so I have tried those out already so let's let's get started as I said this is Drupal with AI Interpolator modules I haven't enabled this post OB processor module because I'm going to
- 11:07 show you the difference when I do enable it um I'm also going to enable JSON:API extras because this can do uh a little bit cooler stuff with uh JSON:API but let's get started now so what I do have
- 11:26 installed already is Json module so this is you comes with Drupal core you just have to enable it basically what I'm going to do is I'm going to install this JSON:API extras as well so we have it up
- 11:40 and running this is basically how you install something Drupal add functionality so this uh gives me better control over JSON:API this is what this module does and then what I'm going to
- 11:53 do is I'm going to go to content types and I'm going to create our uh well droup of people knows it as content types you can think of it as a workflow basically so we're going to create an
- 12:05 article right uh it needs a title and we can actually use the title as the prompt for generating our description and for generating our image sorry there was a cut there I got
- 12:23 the call thing fit so we're going to generate our article right so we need text formatted long for that which is basically HTML field uh we're just going to call
- 12:38 that the article uh so when you write this prompters it's very important how you write this because it might be perceived differently by the AI depending on how
- 12:52 you write this so when you choose the amount of fields when you're going to write a prompt like create x amount of paragraphs it might read that that each paragraph should be be its own value
- 13:04 right so what you can do here is either you do unlimited field save each in a field or you make sure that the prompt is so uh exact that it will generate one field
- 13:18 only but I um will basically do it in multiple Fields now so we choose full HTML we want to add some HTML on the output uh we enable the AI Interpolator and this is what's going to do the magic
- 13:32 now then so we use OpenAI text long and we base it on the title and then we write our uh prompt based on the title No based on the context uh generate an article that is around 12
- 13:51 paragraphs long you may use HTML Fields tags text it is like headers p e m um P strong we have the context then under advanced settings um sorry about that so under advaned
- 14:42 settings um we're going to choose GPT-4 because we want it basically in this case to take a little bit longer to Showcase what the the post OB processor is doing so this is for long running API
- 14:58 requests if you have ai stuff that can answer within a second or so you don't need this basically and then you see interpolator workers and that's the normal workers
- 15:11 that comes with the uh AI Interpolator so in the showcases I always use batch because that's very visual it's using JavaScript uh to cut up all the jobs into a cube basically
- 15:26 make sure that nothing times out so if you have a CDN or Patcher nginx timing out it's not going to happen but anyone sending API request can't run JavaScript of course this
- 15:38 means that that's not available so what you can do instead you can run it on Chrome but then it's very important of course that the CR jobs runs often enough so if you run every minute then
- 15:49 it's probably okay but if you run every hour it's going to suck if someone asks a request that they want to create a article and then they have to wait 1 hour so what we can use from the
- 16:02 beginning is direct and that means basically it when you do the request it's running in the background right taking time uh which is not super for API but it kind of works depends on if you have
- 16:18 a long timeout or not on your uh CDN nginx AER so on then so I added the article with this now I'm just going to add a image then that we call the article image we're going to save this we just
- 16:40 need one image there's a lot of fields here you see that's basically what comes with Drupal and why Drupal is very good for Content as I name said before we're going to use the OpenAI do to generate
- 16:56 the image we're going to base it on type title I'm going to write generate an image based on the following now generate an a header image for an article based on the
- 17:15 following uh text we put the context of course this is going to be very bad results you need a better prompt to be honest and there is I can do some advertisement here well not that I earn
- 17:31 any money on it but there is the PromptPerfect uh module you can use so you use this service PromptPerfect in between there where you can take a simple prompt
- 17:42 that generates a good prompt for do so you see the example here using spaghetti bolog and you get this great prompt for do for instance that's just another part of the
- 17:55 chain right same thing here Direct 100 we do DALL-E 3 so it takes some time save that we don't have to change any settings I can show you first manually how to create this
- 18:08 then uh and this is now based on the title I write here so I'm going to write Obama like poems it's going to create the article on this now then and while we're doing
- 18:21 this then I'm going to show you the how to set up the JSON:API so this is the JSON:API is already set up actually it's set up here and you can see the different
- 18:32 things that gets exposed by default and then you can of course turn off stuff uh so there's going to be something called node which is what the article is and this is available here so
- 18:45 this doesn't have anything yet but it's going to soon have something but say that I want to make this a little bit nicer now what I can do then is uh the following take some time so that's what
- 19:04 I am using this JSON:API extras for that I enabled see here if we do admin we go to web services here Json \[Music\] API and so this do take some time but there we see it's finished let's see if we
- 19:44 have a picture also that this nothing to do with ob as I said this is a very very bad prompt to be honest but you can see here at least it has generated all the article paragraphs
- 19:58 and you see it generated it then one by one and you can read it here Obama and his connection to his poetry and so on since I didn't add any context of course it's making up everything anyway here we
- 20:12 have the JSON:API settings then we're going to accept create read and everything right because we need to create over the API it's under JSON:API but what we're going to do now is we go
- 20:23 to the article so here you can hide different end points that you don't want to show right so I'm going to put this under Articles as the resource type article I'm going to hide a lot of stuff so we
- 20:36 just want the uid because that's what we work with in JSON:API and as I said JSON:API is just one version but the advantage of JSON:API and why I wanted to show this is that I don't actually
- 20:51 have to develop anything to enable it uh and then you see here if you use the field UI for creating fields in Drupal it prepend everything with field which is not so nice so you should really not
- 21:10 use this if you need something scalable you should rather uh write this in code but of course for most use cases you don't actually need to scale that much so it's it's a nice Q is solution you
- 21:23 see there's a AI Interpolator status so this basically says the status of the Curve processing so I'm just going to call this status to have a little bit nicer name to it if I reload now it's going to
- 21:37 be gone because as I showed you we moved it to articles we're going to look for file as well because there is a image connected to it right we're just going to do the
- 21:49 same here to nien it up uh so it is uh now stored under files instead and it's called a file let's see here we need the URI basically that's what we need and if we save this now what we can
- 22:10 do is using JSON:API then for uh let's see here including stuff where did you go here article file so I'm going to include the article image now now and then you can see it has included
- 22:31 the image here also so if I go to this one I should there are ways you can make it absolute but yeah here you have the image \[Music\] then so now we have set up everything we
- 22:47 have the API there's one more thing I need to do now so there is uh uh authentication module for API in Dro B uh from oh miniOrange it's here even I have it in
- 23:04 history so it's called rest API authentication so there you can set up any authentication layer you want right so all jot tokens everything however in this case I don't
- 23:16 want to showcase this this take some time so what I'm going to do instead is something you should definitely not do that's that I go into permissions here and here you can control who can do
- 23:29 what so we have a role called content editor and they should maybe be able to create new content but what I do now is I I allow anyone to create content uh I can just show you before
- 23:40 because I have my JSON:API here where I'm going to then send to the same endpoint Biden likees poems right so if I send this now you're going to see it's forbidden
- 23:54 403 but if I save now because now I allow everyone then I can save and you see it starts uh responding basically and the problem now then is this nothing happens right takes
- 24:13 forever because it takes forever to create this and if I go to the JSON:API end point it hasn't actually generated anything it's still just Obama article here so there's no way for me to pull to
- 24:27 check someu status as well but it because it has actually not written anything to database yet and this is then where the post OB processor comes in and where it uh does its job because
- 24:40 the what the post OB processor does is the following first of all OB then it stands for output buffer so it makes sure that Drupal does whatever Drupal does right if this is JSON:API graphql or if
- 25:00 you're even using the GUI it make sure that it finishes everything like it does normally which means it has saved the article it just hasn't run any a AI jobs on it and then it makes sure that this
- 25:15 is getting processed afterwards so the PHP process continues uh running it just outputs the buffer and tells your web server and J X Apache that hey I have a answer for you here
- 25:31 right output this answer and then I continue processing here in the background uh and this is of course very good for the use cases where you want to run the API command get a uu ID back
- 25:47 well uu ID then when we're talking about JSON:API depending on what API uh standard you use and then pull on this until it's finished so so that's what we're going
- 25:58 to do now we're going to um enable this uh so we have enabled this and what we need to do now is go to our content types again and manage fields and then under the process
- 26:21 workers we have post output of so we just save this go back to our example here you can see by the way it has generate something we can just for the fun of it by the way reload and take the second
- 26:50 file included here see how Biden looks still doesn't look like like B him but at least it's a old man so it looks a little bit maybe like him so anyway what we're going to do now is
- 27:05 we're going to run Trump likes poems and we're going to send it and then you're going to see oh there's a response directly so this is what the post op buffered uses right so now what
- 27:19 we can do is this so I forgot the S there I think let's try there we go so you see it's still processing right because this is going to take some time so what we can do now is that we're
- 27:44 just pulling this until processing is done right um and this is what the post OB processor does then it makes sure that your API service basically works like a API service should
- 28:02 do I will say that I can also add on top this of this if someone does a feature request uh that it could send a web hook as well when it's finished so you don't have to sit and
- 28:21 poll but that is of course yeah something we can add later so now finally you see it's status is finished we have an output here um and that's basically it it has generated
- 28:42 something um can look at the image I guess by include article image we called it I guess yes so you see that that was included did as well uh yeah well he looks very pretty
- 29:04 there Donald Trump so that is basically it this is what this module does it opens up uh the AI Interpolator to be very flexible to work with other systems where you can set up the
- 29:19 workflows in the interpolator but not having to use Drupal if you don't want or if you use Drupal and want to offer this as API service you can do this as well so
- 29:34 that's it thank you for watching and I hope you like it and if you like it please use it it's free open source and any feature request you can think of any bug requests just add them
- 29:50 to the to the drost website thank you

  Filed under [Workflows](/blog?category=6) [Drupal AI](/blog?category=2)

Parts of this content were produced by AI.

This site has not assessed whether a label is required for this content.

  How was AI used?The video and most of the introduction are Marcus's own, first published on workflows-of-ai.com. AI wrote the subtitle, the summary and the video chapters from the transcript, and the last sentences of the introduction, and corrected misheard names in YouTube's automatic captions.

   Marcus Johansson

Tinkers with AI and Drupal

 [About Marcus](/about/marcus-johansson)[Drupal.org profile](https://www.drupal.org/u/marcus_johansson)[Drupal AI](https://www.drupal.org/project/ai)

## The post in three sentences

The AI Interpolator chains OpenAI text and DALL-E images into an article from a one-sentence title, all set up in the Drupal UI. JSON:API and JSON:API Extras expose the article, and the Post OB Processor sends the API response right away while the AI work continues in the background. The client then polls the status field until it says finished.