360 Secure SkillHub
360 安全技能中心

go-fireworks

该 Skill 说明如何在 Go 项目中使用非官方 go-fireworks 库,以类型化方法调用 Fireworks AI 的管理平面和推理接口;覆盖安装、认证、方法命名、错误处理与示例,并指出流式响应需自行处理。

psyb0t
psyb0t
热度 28.78
最近更新 2026-10-18 03:25:48
分类:开发依赖:代码执行 / 第三方 API应用场景:API 集成 / 代码生成

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add psyb0t/go-fireworks
Metadata
name
go-fireworks
description
Unofficial Go client for the Fireworks AI REST API, generated with oapi-codegen. `fireworks.NewClientWithResponses(baseURL, fireworks.WithRequestEditorFn(...))` from `github.com/psyb0t/go-fireworks` gives one typed method per spec operation, covering all 136 paths of the Fireworks AI Gateway REST API, the control plane (accounts, API keys, users, models, datasets, deployments, fine-tuning and batch jobs) under `https://api.fireworks.ai` and the inference endpoints (chat completions, completions, messages, responses) under `https://api.fireworks.ai/inference`. Responses decode into typed `JSON200` fields. Use when Go code needs to call Fireworks AI, or already imports go-fireworks.
license
MIT
homepage
https://github.com/psyb0t/go-fireworks
user-invocable
true
metadata
{"openclaw":{"emoji":"🎆","requires":{"bins":["go"]}}}
permissions
{"filesystem":"Guides edits to the Go source of the current project. The library reads and writes no files.","shell":"The Go toolchain (`go get`, `go build`, `go test`) to add and compile the dependency.","network":"`go get` fetches the module from your Go module proxy. At runtime the client sends HTTPS requests only to the base URL you give it, normally https://api.fireworks.ai or https://api.fireworks.ai/inference."}

go-fireworks

Typed Go client for the Fireworks AI REST API. Every operation in the spec is a method on ClientWithResponses, named after its operation ID.

For install, base URLs, method naming and error handling in detail, see references/setup.md.

Security & safety

  • Read the API key from an environment variable such as FIREWORKS_API_KEY. Never hardcode it, commit it or log it, and never print request headers.
  • Requests go only to the base URL passed to NewClientWithResponses. Prompts, datasets and model files sent through the client reach Fireworks AI.
  • Calls that spend money or delete things (create a deployment, start a fine-tuning or batch job, delete a model, dataset, deployment or API key) run only when the user asked for that action, and only on resources the task owns.

When to use

  • Go code calls Fireworks AI: chat or text completions, listing models, managing deployments, datasets or fine-tuning jobs.
  • The project already imports github.com/psyb0t/go-fireworks.

When NOT to use

  • You need streaming. The generated client returns the whole body; for stream: true read HTTPResponse.Body from the plain Client methods yourself.
  • The code is not Go. Use Fireworks AI's own SDKs.

Finding endpoints and types

The examples below cover a few calls. Every operation in the spec has a generated method, and the spec's descriptions are on them as Go doc comments. Look names and fields up instead of guessing. After go get github.com/psyb0t/go-fireworks, from inside your module:

go doc github.com/psyb0t/go-fireworks ClientWithResponsesInterface  # every endpoint method
go doc github.com/psyb0t/go-fireworks GatewayListModelsParams       # one method, params type or model
go doc -all github.com/psyb0t/go-fireworks                          # the whole package

The same documentation is at https://pkg.go.dev/github.com/psyb0t/go-fireworks.

Method names come from the spec's operation IDs. <OperationId>WithResponse takes the context, then the path parameters in order, then *<OperationId>Params when the operation has query or header parameters, then the request body when it has one. The JSON200 field (or JSON201 and so on, per declared status) holds the decoded body; it is nil for any other status. Control plane methods carry a Gateway prefix, inference methods carry the spec's full ID (CreateChatCompletionV1ChatCompletionsPost), and some response wrappers end in Response2 where a schema already took the plain name.

Usage

import (
	"context"
	"fmt"
	"net/http"
	"os"

	"github.com/psyb0t/go-fireworks"
)

auth := fireworks.WithRequestEditorFn(func(_ context.Context, req *http.Request) error {
	req.Header.Set("Authorization", "Bearer "+os.Getenv("FIREWORKS_API_KEY"))

	return nil
})

client, err := fireworks.NewClientWithResponses("https://api.fireworks.ai", auth)
if err != nil {
	return err
}

res, err := client.GatewayListModelsWithResponse(ctx, "my-account", &fireworks.GatewayListModelsParams{})
if err != nil {
	return err // transport error
}

if res.JSON200 == nil {
	return fmt.Errorf("list models: status %d: %s", res.StatusCode(), res.Body)
}

for _, m := range *res.JSON200.Models {
	fmt.Println(*m.Name)
}

Chat completions live on the inference base URL, so they need a second client:

inference, err := fireworks.NewClientWithResponses("https://api.fireworks.ai/inference", auth)
if err != nil {
	return err
}

var content fireworks.ChatMessage_Content
if err := content.FromChatMessageContent0("Say hi"); err != nil {
	return err
}

res, err := inference.CreateChatCompletionV1ChatCompletionsPostWithResponse(ctx, fireworks.ChatCompletionRequest{
	Model:    "accounts/fireworks/models/<model-id>",
	Messages: []fireworks.ChatMessage{{Role: "user", Content: &content}},
})
if err != nil {
	return err
}

if res.JSON200 == nil {
	return fmt.Errorf("chat: status %d: %s", res.StatusCode(), res.Body)
}

text, err := res.JSON200.Choices[0].Message.Content.AsChatMessageContent0()

Check JSON200 for nil before reading it. A non-2xx status is not a Go error; the status is in StatusCode() and the raw body in Body.