Help me to use API in the PHP code

Hi there,
I’m thrilled to use OpenAi. So, I wanna go ahead. But I’m not that good at coding! I want to use it on a WordPress site. For this, I am trying to build a plugin. But I can not make any seance how to use this API. I have already made a plugin with Github API using the cURL function. But I think OpenAi API is more complicated to me! Can you please give me an example of how I can use it on the PHP cURL function? Your documentation is not helping me with this.

Please convert the billow script to PHP for me.

-H “Content-Type: application/json”
-H “Authorization: Bearer $OPENAI_API_KEY”
-d ‘{
“model”: “text-davinci-002”,
“prompt”: “Write a article about: hi\n”,
“temperature”: 0.7,
“max_tokens”: 256,
“top_p”: 1,
“frequency_penalty”: 0,
“presence_penalty”: 0

Thank you. I hope anyone will help me!

Hi @proguide365,

I’m not sure if you’re still needing help with this project, but this tutorial may help:

A WordPress environment is quite different to a Laravel framework based application, however you could still make use of our OpenAI API client for PHP.

It would allow you to query the OpenAI completions endpoint with only a few lines of code.



Safe way to use WordPress core class WP_Http WP_Http | Class | WordPress Developer Resources as a base to build your own OpenAI API client on top of it. This will allow you to benefit from already available WP info structure (available transports, events, models, debuggers etc).

Then depending on your needs you might also use other parts of WordPress to speed up your development.

Feel free to reach if you need some guidance in WP.

1 Like

I’m surprised there isn’t a WP plugin yet with a bring your own key model… Hrm…

1 Like

Reselling tokens sounds as a far more lucrative way of monetisation… But you have to be a good WP guy to get this up. Then, the app approval process.

From what I’ve seen there is only useTopic via Thrive that has gpt3 in it and again, it’s not inside WordPress.

I’m playing with using WordPress as the underlying structure for a legal assistant, but that’s going to be used internally only.

1 Like

I asked a great WP plugin developer (the Relevanssi author) to build such a plugin but he said no. Since Wordpress is so popular, someone should definitely be building an OpenAI plugin. Unfortunately I don’t have the skill set.

1 Like

What would be the plugin goal?

Image generation would be nifty and save time - input text / press button / image popped into post…

Or maybe a button to take a headline and fill out the subheads for the article in the body… Mostly the tools available now but directly in WP. For me, anyway…

To allow wordpress site owners to connect to the OpenAI API without having to write their own PHP or other code. A huge percentage of the world’s websites are built with wordpress. For example, my company’s website is built with wordpress and I’ve had to write a lot of custom code to implement GPT-3’s embeddings-based search and, soon, question answering.

Love that idea. Might be worth pursuing. Thanks. Do you know of any APIs out there to upscale the image resolution (at least X4 for full width retinas in 16:9) ? That would be the must-have. Just imagine: type text in set featured image box, get a couple of thumbnails to choose from, click one to select, get 1024x1024, click another button up-scale to 4096x4096, click to crop the aspect ratio you need… Set the image as featured and you’re done.

Fraction of the istock cost and 10x times faster…

Definitely worth pursuing this idea.

Ok. If i get your point: start with implementing the semantic search (via embeddings), then maybe extend to question answering.

Very interesting. Especially, knowing that i just finished a conversation with my business partners about it.

Personally, I’m thinking of using something like as a backend of the search engine for the sake of cost/performance compared to implementing openAI embeddings into WordPress. But had no experience with them (will be reaching to them anyway for my side project).

But definitely nothing prevents you from using one for the search engine/context finder and another for question answering. That would be a bomb actually.

Needs a user interface in WordPress to be able to configure searchable entities, but that’s not an issue for me (check out my github).

What would be your approximate budget? (Don’t worry, I’ll try to pre-sell it to some of my clients as well, so that no-one pays the beast alone).

1 Like

We are using useTopic for this one, directly integrated with wordpress via Thrive solutions :

Works like a wizzard, does all dirty research and crafting job, then share briefing with your writers to get final draft, and then back to use topic to fine tune and get on top of search results. Tested it on our website here then started using it for our clients

1 Like

I’m looking at Pinecone and Weviate. At the moment, I just store my embeddings in WP’s SQL database. My budget is $0. :rofl: I don’t need this built for me, because I’ve already built an integration between WP and OpenAI with custom code. I was saying that I believe there is a market for a wordpress plugin connecting WP and OpenAI. So WP users would have something standardized and could integrate faster, prefereably in a no-code or low-code way. There is something in the cookbook I believe, which could probably be developed into a WP plugin.


Sorry confused you with the original author of the thread.

1 Like

Looks like this one might work out, especially in WordPress: Super Resolution API | DeepAI

Well, doesn’t seem to produce usable results fast enough to become interesting, a lot of edits needed to prompt to get something worth it.

Styles settings are definitely needed as no ability to use a base image to apply prompt to as in stable diffusion.

But the high resolution thing might be more useful to save money on stock photos (buying smaller image then use the upscale function to be able to use it on the website).

I have to work out my other commitments, but I have built some WordPress plugins (more custom work for clients; than FOSS releases). I think OpenAI has a lot of promise. I thought I was off to the races leveraging this project (GitHub - dneustadt/openai-client: OpenAI PHP API Client). It’s great, but doesn’t cover all of the endpoints.
I want to develop an OpenAI WordPress plugin.
My thinking of what it would need:

  • a way to put in an OpenAI key and client ID in the admin settings
  • a set of endpoints to assist in content generation

My question: What would the plugin need to do to be of value?

Hi @dewolfe001, thanks for replying. I was thinking less about content generation and more about search and question answering. (But of course content generation is on people’s minds a lot!) For websites with heavy content or complex text, the ability to search and find the most relevant posts/pages/custom post types, especially if there were filtering features, would be very useful. The existing search plugins are not nearly as easy and effective as what I think is possible with GPT-3. I have spent a lot of time experimenting with them, especially Relevanssi which I believe is the best on the market, and its author did some custom development for me before I started using GPT-3. Even more exciting than search is question answering, where GPT-3 could really shine on people’s websites. If users could just input a question into a search box and obtain an answer based ONLY on the CONTENT of THAT PARTICULAR SITE. That’s what my website Lexata does, but it was done with custom work because there is no plugin. I really think a lot of website owners would find this useful. It could be freemium where you don’t charge anything for the search feature (but website owners have to bring their own key) and then charge for the question answering function. I really wish I had the technical skills to build the plugin myself. I have a good conceptual understanding of what is required (e.g. embeddings are generated from certain content in the wp mysql database) but I certainly can’t write the code. :slight_smile:

1 Like

Hi lmccallum,
I was able to get some of the basics working with text completion to rephrase a short prompt as different text.
I’ll take a run at seeing if I can present something like ChatGPT with questions and answers. Ideally, it should limit the questions to what is containing on the site (similar to Relevansi), but I don’t know if that’s possible at present in ChatGPT.

ChatGPT definitely can’t do question answering for a specific website. It would have to be done with the embeddings endpoint combined with text-davinci-003.