You're almost there! Please answer a few more questions for access to the Applications content. Complete registration
Interested in joining? Complete your registration by providing Areas of Interest here. Register

ChatGPT API Integration

edited Jul 24, 2025 7:54AM in Planning 2 comments

Summary:

Posting a small groovy snippet to allow chatGPT API integration.

This is meant as a bit of fun with no practical applications at the moment.

You will need to generate an API Key here: https://platform.openai.com/overview and replace it in the code below as bearerToken

Code Snippet (add any code snippets that support your topic, if applicable):

String ChatGPT_API(String Prompt){
	def bearerToken ="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
  	def json = JsonOutput.toJson([model: 'gpt-3.5-turbo', messages: [[ role: 'user', content:Prompt ]]])
        Connection ChatGPTconnection = connection("https://api.openai.com/v1/chat/completions", "user", "password")
        HttpResponse<String> jsonResponse = ChatGPTconnection.post()
        	    .header("Content-Type", 'application/json') //.header=headers
                    .header("Authorization", 'Bearer '+bearerToken)
                    .body(json)
   

Howdy, Stranger!

Log In

To view full details, sign in.

Register

Don't have an account? Click here to get started!