[ Docs ]
Go SDK
Planned IdonAI Go client — module path, chat completions, and streaming notes.
Status
The github.com/idonai/idonai-go module path is reserved. Public install lands when API keys ship. Until then, treat the snippets below as the intended client shape and validate prompts in Quark or against the REST contract.
Install (planned)
go get github.com/idonai/idonai-go
Pin a module version in go.mod once tags exist. Prefer a single shared client per process with a bounded HTTP transport.
Client init
package main
import (
"os"
"github.com/idonai/idonai-go"
)
func main() {
client := idonai.NewClient(os.Getenv("IDONAI_API_KEY"))
_ = client
}
Load the key from the environment or your secret store. See Authentication.
Chat completion
resp, err := client.Chat.Completions.Create(
context.Background(),
idonai.ChatCompletionRequest{
Model: "origin",
Messages: []idonai.Message{
{Role: "user", Content: "Explain quantum entanglement."},
},
MaxTokens: 1024,
},
)
if err != nil {
log.Fatal(err)
}
fmt.Println(resp.Choices[0].Message.Content)
Swap Model to "nextgen" for harder tasks. Model ids match Quark and the API reference.
Streaming
Streaming will expose an iterator or channel of chunks (SSE under the hood). Always check err after the stream ends, and cancel the context when the caller disconnects.
// Sketch — exact helper names may refine at publish time
stream, err := client.Chat.Completions.CreateStream(
ctx,
idonai.ChatCompletionRequest{
Model: "origin",
Stream: true,
Messages: []idonai.Message{
{Role: "user", Content: "Outline three steps."},
},
},
)
if err != nil {
log.Fatal(err)
}
defer stream.Close()
for stream.Next() {
fmt.Print(stream.Current().Delta)
}
if err := stream.Err(); err != nil {
log.Fatal(err)
}
Errors
Inspect typed API errors for status codes. Retry 429 and transient 5xx with backoff; do not blindly retry 400 / 401. Rate-limit guidance lives in Rate limits.