Call an AI API in Go

One HTTP request — copy, paste, ship.

How to Call an AI API in Go (Example) | Svivva

Calling an AI API from Go takes a single HTTP request. Define your endpoint's behavior as a prompt on Svivva, then call it like any other JSON API from your Go code.

Go example

package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"net/http"
)

func main() {
	body, _ := json.Marshal(map[string]string{"text": "Summarize this in two sentences."})
	resp, err := http.Post("https://your-endpoint.example/run", "application/json", bytes.NewReader(body))
	if err != nil { panic(err) }
	defer resp.Body.Close()
	var out map[string]any
	json.NewDecoder(resp.Body).Decode(&out)
	fmt.Println(out["result"])
}

Notes

  • The endpoint is a normal HTTPS URL — no SDK required.
  • Send your input as JSON; read the structured result from the response.
  • Add a timeout and check the status code, as shown above.

Frequently asked questions

Do I need an SDK to call an AI API in Go?

No. Any Go HTTP client works because the endpoint is plain HTTPS + JSON.

How do I change the AI behavior?

Edit the prompt that defines the endpoint. Your Go code and the request contract stay the same.

Is this production-ready?

Yes — add input validation, a timeout, and error handling (shown above), and you can ship it.

Related

Why Choose Svivva

Working Go code you can copy

No SDK — plain HTTPS + JSON

Change AI behavior without touching your code

How It Works

Deploy a prompt-to-API endpoint, then call it from Go using the example above.

Who It's For

Go developers adding AI features fast.

Related Tools

Ready to ship with Svivva?

Turn your ideas into production-ready APIs in minutes. No infrastructure setup required.

Get Started Free

Svivva

Ship your next AI project

Create your workspace — no credit card required to explore.