Install
openclaw skills install @psyb0t/go-writer-aiUnofficial Go client for the Writer (writer.com) API, generated from Writer's OpenAPI spec. writer.NewClientWithResponses("https://api.writer.com", auth) from github.com/psyb0t/go-writer-ai gives typed methods for chat (ChatWithResponse), text completions (CompletionsWithResponse), models (ModelsWithResponse), files (GatewayGetFilesWithResponse, GatewayUploadFileWithBodyWithResponse), Knowledge Graphs (CreateGraphWithResponse, QuestionWithResponse), no-code applications (GenerateContentWithResponse), the PDF parser, web search and vision, with responses decoded into JSON200. Auth is a Bearer API key set through a RequestEditorFn. Use when Go code needs to call the Writer API or already imports go-writer-ai.
openclaw skills install @psyb0t/go-writer-aiTyped Go client for the Writer API. Package writer, generated with oapi-codegen; every operation in the spec is a method on ClientWithResponses.
For install, the full operation list and streaming, see references/setup.md.
WRITER_API_KEY environment variable. Never hardcode it, commit it, or log it, and never print request headers.https://api.writer.com.github.com/psyb0t/go-writer-ai.*http.Response for stream: true; it does not parse server-sent events.import (
"context"
"fmt"
"net/http"
"os"
"github.com/psyb0t/go-writer-ai"
)
auth := writer.WithRequestEditorFn(func(_ context.Context, req *http.Request) error {
req.Header.Set("Authorization", "Bearer "+os.Getenv("WRITER_API_KEY"))
return nil
})
client, err := writer.NewClientWithResponses("https://api.writer.com", auth)
if err != nil {
return err
}
models, err := client.ModelsWithResponse(ctx)
if err != nil {
return err // transport error
}
if models.JSON200 == nil {
return fmt.Errorf("models: %s", models.Status()) // API error, see models.Body
}
for _, model := range models.JSON200.Models {
fmt.Println(model.Id, model.Name)
}
Chat:
var content writer.ChatMessage_Content
if err := content.FromChatMessageContent0("hello"); err != nil {
return err
}
res, err := client.ChatWithResponse(ctx, writer.ChatRequest{
Model: "<model-id>", // an Id from Models
Messages: []writer.ChatMessage{{
Content: &content,
Role: writer.ChatMessageRequestRoleUser,
}},
})
if err != nil {
return err
}
if res.JSON200 == nil || len(res.JSON200.Choices) == 0 {
return fmt.Errorf("chat: %s", res.Status())
}
fmt.Println(res.JSON200.Choices[0].Message.Content)
Check JSON200 for nil before using it. On an error status the raw body is in Body.