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
10 changes: 10 additions & 0 deletions apps/gateway/internal/adapters/http/handlers/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"reflect"
"strings"
"testing"
"time"

"github.com/dappnode/dappnode-nexus-gateway/apps/gateway/internal/adapters/http/handlers"
"github.com/dappnode/dappnode-nexus-gateway/apps/gateway/internal/application/services"
Expand Down Expand Up @@ -107,11 +108,13 @@ func TestModelsHandler_NoAuthRequired(t *testing.T) {
}

func TestModelsHandler_ListsModels(t *testing.T) {
createdAt := time.Date(2026, 11, 15, 12, 0, 0, 0, time.UTC)
desc := "GPT-4.1 Mini model"
catalog := &mockModelCatalog{
models: []domain.PublicModel{
{
PublicModelID: "openai/gpt-4.1-mini",
CreatedAt: createdAt,
DisplayName: "GPT-4.1 Mini",
Description: &desc,
ProviderConfig: domain.ProviderConfig{ProviderName: "openai"},
Expand Down Expand Up @@ -154,6 +157,7 @@ func TestModelsHandler_ListsModels(t *testing.T) {
Object string `json:"object"`
Data []struct {
ID string `json:"id"`
Created int64 `json:"created"`
Object string `json:"object"`
OwnedBy string `json:"owned_by"`
DisplayName string `json:"display_name"`
Expand All @@ -178,6 +182,12 @@ func TestModelsHandler_ListsModels(t *testing.T) {
t.Fatalf("data len = %d, want 2", len(body.Data))
}
first := body.Data[0]
if first.Created != createdAt.Unix() {
t.Errorf("created = %d, want %d", first.Created, createdAt.Unix())
}
if body.Data[1].Created != 0 {
t.Errorf("missing creation date = %d, want 0", body.Data[1].Created)
}
if first.ID != "openai/gpt-4.1-mini" {
t.Errorf("data[0].id = %s, want openai/gpt-4.1-mini", first.ID)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ func toPublicModelData(m domain.PublicModel, eurToUSDRate float64) dto.ModelData
inputPrice := eurToCents(m.InputPricePerMillion)
outputPrice := eurToCents(m.OutputPricePerMillion)
proofMode := m.EffectiveProofMode()
created := int64(0)
if !m.CreatedAt.IsZero() {
created = m.CreatedAt.Unix()
}
data := dto.ModelData{
ID: m.PublicModelID,
Object: "model",
Kind: string(domain.CatalogKindPublicModel),
BaseModel: privateBaseModel(m.PublicModelID, m.UpstreamModelName),
OwnedBy: "nexus",
Created: 0,
Created: created,
DisplayName: m.DisplayName,
Description: m.Description,
ContextSize: &m.MaxContextWindow,
Expand Down
2 changes: 2 additions & 0 deletions apps/gateway/internal/adapters/metering/runtime_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ func (m runtimePublicModel) capabilities() json.RawMessage {

func (m runtimePublicModel) toDomain() domain.PublicModel {
model := domain.PublicModel{
CreatedAt: m.CreatedAt,
ID: m.ID,
PublicModelID: m.PublicModelID,
DisplayName: m.DisplayName,
Expand Down Expand Up @@ -450,6 +451,7 @@ type runtimeAPIKey struct {
}

type runtimePublicModel struct {
CreatedAt time.Time `json:"created_at"`
ID string `json:"id"`
PublicModelID string `json:"public_model_id"`
DisplayName string `json:"display_name"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func TestRuntimeClientMapsModelPricesWithoutPrecisionLoss(t *testing.T) {
"input_price_per_1m_tokens_microcents":75000000,
"output_price_per_1m_tokens_microcents":450000000,
"cache_read_price_per_1m_tokens_microcents":12500000,
"currency":"EUR","active":true
"created_at":"2026-11-15T12:00:00Z","currency":"EUR","active":true
}`))
}))
defer server.Close()
Expand All @@ -443,6 +443,9 @@ func TestRuntimeClientMapsModelPricesWithoutPrecisionLoss(t *testing.T) {
if err != nil {
t.Fatalf("GetPublicModel: %v", err)
}
if !model.CreatedAt.Equal(time.Date(2026, 11, 15, 12, 0, 0, 0, time.UTC)) {
t.Fatalf("created_at = %v", model.CreatedAt)
}
if model.InputPricePerMillion.String() != "0.75" || model.OutputPricePerMillion.String() != "4.5" {
t.Fatalf("prices = (%s, %s)", model.InputPricePerMillion, model.OutputPricePerMillion)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/domain/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package domain
import (
"encoding/json"
"strings"
"time"

"github.com/shopspring/decimal"
)
Expand Down Expand Up @@ -32,6 +33,7 @@ type ProviderTarget struct {

// PublicModel is the fully-resolved model exposed by the gateway.
type PublicModel struct {
CreatedAt time.Time
ID string
PublicModelID string
DisplayName string
Expand Down
Loading