Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions arkruntime/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/volcengine/volcengine-go-sdk/volcengine/session"
"github.com/volcengine/volcengine-go-sdk/volcengine/volcengineerr"

sdk "github.com/volcengine/ark-runtime-go"
"github.com/volcengine/ark-runtime-go/arkruntime/model"
"github.com/volcengine/ark-runtime-go/arkruntime/utils"
)
Expand Down Expand Up @@ -285,6 +286,7 @@ func (c *Client) newRequest(ctx context.Context, method, url, _, resourceId stri
header: make(http.Header),
}
args.query = make(map[string][]string)
args.header.Set("User-Agent", "ark-runtime-go/"+sdk.Version())

requestID := utils.GenRequestId()
args.header.Set(model.ClientRequestHeader, requestID)
Expand Down
65 changes: 65 additions & 0 deletions arkruntime/user_agent_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) 2026 ByteDance Ltd. and/or its affiliates.
// SPDX-License-Identifier: Apache-2.0

package arkruntime_test

import (
"context"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"

"github.com/volcengine/ark-runtime-go/arkruntime"
"github.com/volcengine/ark-runtime-go/arkruntime/model/images"
)

func TestRequestUserAgent(t *testing.T) {
version, err := os.ReadFile("../VERSION")
if err != nil {
t.Fatal(err)
}
for _, test := range []struct {
name string
custom bool
value string
expected string
}{
{name: "repository version", expected: "ark-runtime-go/" + strings.TrimSpace(string(version))},
{name: "custom override", custom: true, value: "my-app/2.0", expected: "my-app/2.0"},
{name: "explicitly disabled", custom: true},
} {
t.Run(test.name, func(t *testing.T) {
headers := make(chan http.Header, 1)
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
headers <- r.Header.Clone()
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"model":"test-model","created":1,"data":[]}`))
}))
defer server.Close()
client := arkruntime.NewClientWithApiKey("test-key",
arkruntime.WithBaseUrl(server.URL), arkruntime.WithRetryTimes(0))
request := &images.CreateImageGenerationRequest{Model: "test-model", Prompt: "test"}
if test.custom {
_, err = client.GenerateImages(context.Background(), request,
arkruntime.WithCustomHeader("User-Agent", test.value))
} else {
_, err = client.GenerateImages(context.Background(), request)
}
if err != nil {
t.Fatal(err)
}
got := <-headers
if got.Get("User-Agent") != test.expected {
t.Errorf("User-Agent = %q, want %q", got.Get("User-Agent"), test.expected)
}
if got.Get("X-Client-Request-Id") == "" {
t.Error("missing client request ID")
}
if got.Get("Authorization") != "Bearer test-key" {
t.Error("authentication header changed")
}
})
}
}
18 changes: 18 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2026 ByteDance Ltd. and/or its affiliates.
// SPDX-License-Identifier: Apache-2.0

// Package arkruntime provides build metadata for the Ark runtime SDK.
package arkruntime

import (
_ "embed"
"strings"
)

//go:embed VERSION
var version string

// Version returns the SDK version embedded from the repository's VERSION file.
func Version() string {
return strings.TrimSpace(version)
}
Loading