![illustration of Custom GPTs vs OpenAPI path parameters](/uploads/blog_posts/14.webp)
Custom GPTs vs OpenAPI path parameters
Seems that the AI can't do idiomatic API calls for a RESTful interface after all - or their HTTP client has some bug.
TLDR: Don't use path parameters, at all, they don't work properly. Either do POST with params in the body or else use query parameters and declare them as required.
I spent a whole evening banging my head against a brick wall yesterday. The initial problem looked simple:
- I have an api for cooking recipes/ingredients, bog-standard RESTful interface.
- I have a custom GPT that is specialized on giving inspiration about what to cook.
- Connect them!
Easier said than done. Let me explain.
The initial API spec:
I basically had the following actions defined in my openapi.json
spec:
POST /search
that takes a query string as the body and returns a list of IDs and recipe namesGET /recipes/{id}
that takes the ID as the path param (yes, correctly specified in detail) and returns the informations about a recipe
only these two are the relevant ones to showcase the problem.
What GPT does
- I added the
openapi.json
file as an action to my custom GPT, and the editor says its all correct. Cool! - Now I try using it by asking a question about some food
- It uses the
POST /search
action just fine - It asks me which of the recipes I'd like
- It uses the
GET /recipes/{id}
action - ERROR.
- It uses the
GET /recipes/{id}
action - ERROR
- It uses the
GET /recipes/{id}
action - ERROR
- ...
and so on.
In the debugging output on the GPT test playground I could inspect the request/response debug information, and it looked good. It literally says that it is calling /recipes
with the parameter id
of some correct value. My server answered with an error though.
I used curl
to directly test the same request against the same server, and it worked flawlessly.
The actual problem
Now this is kind of nasty to spot from their debugging hints in the online editor.
GPT actually made the request to /recipes
(the /{id}
part is stripped out!) and adds the parameter as a query parameter instead!
And after hours of trying various syntaxes and looking through the openai forums, it seems that path parameters just don't work in general.
The Solution(s)
That means for me: I have two options to get the same functionality somehow:
- POST request with a body (this works just fine)
- GET request with query parameters (this is what GPT does already)
It felt just wrong to use POST for getting some data by ID, it also can create trouble if you want to add some caching layers in front of your API. Therefore: query parameters it is! The new action shall be GET /get_recipe_details
with ?id=something
. Smells like very old PHP somehow, but I am fine with it, this API is not for humans/developers but solely for the machine to begin with.
Some small code refactorings later, and I got it running, and now it works flawlessly.
What saved my day quite a bit here: Thanks to Rust and actix-web, moving around these definitions and having the compiler telling you every mistake or missing/wrong configuration is extremely liberating. Also codegen from actix-web to openapi specification at runtime just works, no need to fiddle with these complex JSON/YAML files.
- Number of words: 540
- Reading time: 3 minutes
- Posted: 3 months ago
Linked Categories
Click around and find out ↓
![illustration of Technology](/uploads/blog_categories/3.thumbnail.webp)
Technology
Stay ahead of the tech curve! Discover cutting-edge tools, trends, and insights tailored for solopreneurs and indie hackers driving innovation.
![illustration of Indie Hacking](/uploads/blog_categories/6.thumbnail.webp)
Indie Hacking
Dive into the world of solo entrepreneurship. Get insights and strategies for building successful, self-reliant tech businesses.
![illustration of Backend Development](/uploads/grimoire_categories/6.thumbnail.webp)
Backend Development
Uncover the power behind the scenes of web services and applications, focusing on creating robust, scalable backend systems that support frontend experiences.
![illustration of Rust](/uploads/grimoire_technologies/11.thumbnail.webp)
Rust
A language empowering everyone to build reliable and efficient software. Futuristic swiss army knife and probably the most powerful mainstream technology today
Portfolio Links
See the stuff I made ↓
![illustration of fresh bites bot](/uploads/portfolio_assets/6.thumbnail.webp)
fresh bites bot
Custom GPT as an alternative frontend to my website https://fresh-bites.online to allow for interactive recipe search and tweaking.
![illustration of API](/uploads/portfolio_categories/4.thumbnail.webp)
API
Traditional backend services with an API. Gets data from somewhere, processes it to extract valuable information, returns it on demand.
Related Posts →
![illustration of GPT4o Just Landed And Will Be Free For All!](/uploads/blog_posts/13.thumbnail.webp)
GPT4o Just Landed And Will Be Free For All!
3 months agoThe latest OpenAI ChatGPT model just got reveiled and it will be free for everyone - but more importantly: the GPT Store will be, too!
![illustration of Rewrite it in Rust: Fun Weekend & Happy Wife](/uploads/blog_posts/12.thumbnail.webp)
Rewrite it in Rust: Fun Weekend & Happy Wife
3 months agoHow I rewrote a pet project in Rust, shipped it within 2 days start-to-finish, and gained social credit along the way.
![illustration of The joy of traditional SSR website development](/uploads/blog_posts/11.thumbnail.webp)
The joy of traditional SSR website development
4 months agoHow I got my sanity back after years of JavaScript madness. Building websites finally is fun again - plus hosting and maintenance is much better!
![illustration of The Solopreneur and AI assistants](/uploads/blog_posts/10.thumbnail.webp)
The Solopreneur and AI assistants
4 months agoMy thoughts about how solopreneurs and indie hackers can leverage AI tools to delegate work tasks without having employees or paying freelancers.
![illustration of Digital Assets](/uploads/blog_posts/9.thumbnail.webp)
Digital Assets
4 months agoLearn how to categorize, build, and leverage digital products like websites, chat assistants, ebooks, and apps to create a sustainable lifestyle business.
Latest Posts →
![illustration of GPT4o Just Landed And Will Be Free For All!](/uploads/blog_posts/13.thumbnail.webp)
GPT4o Just Landed And Will Be Free For All!
3 months agoThe latest OpenAI ChatGPT model just got reveiled and it will be free for everyone - but more importantly: the GPT Store will be, too!
![illustration of Rewrite it in Rust: Fun Weekend & Happy Wife](/uploads/blog_posts/12.thumbnail.webp)
Rewrite it in Rust: Fun Weekend & Happy Wife
3 months agoHow I rewrote a pet project in Rust, shipped it within 2 days start-to-finish, and gained social credit along the way.
![illustration of The joy of traditional SSR website development](/uploads/blog_posts/11.thumbnail.webp)
The joy of traditional SSR website development
4 months agoHow I got my sanity back after years of JavaScript madness. Building websites finally is fun again - plus hosting and maintenance is much better!
![illustration of The Solopreneur and AI assistants](/uploads/blog_posts/10.thumbnail.webp)
The Solopreneur and AI assistants
4 months agoMy thoughts about how solopreneurs and indie hackers can leverage AI tools to delegate work tasks without having employees or paying freelancers.
![illustration of Digital Assets](/uploads/blog_posts/9.thumbnail.webp)
Digital Assets
4 months agoLearn how to categorize, build, and leverage digital products like websites, chat assistants, ebooks, and apps to create a sustainable lifestyle business.