File size: 2,797 Bytes
cee2387
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package llmcost

import (
	"fmt"
	"net/http"

	"github.com/openmeterio/openmeter/pkg/framework/commonhttp"
	"github.com/openmeterio/openmeter/pkg/models"
)

func NewPriceNotFoundError(provider, modelID string) error {
	return models.NewGenericNotFoundError(
		fmt.Errorf("llm cost price not found for provider: %s, model_id: %s", provider, modelID),
	)
}

func NewPriceOverrideNotFoundError(id string) error {
	return models.NewGenericNotFoundError(
		fmt.Errorf("llm cost price override not found by id: %s", id),
	)
}

const ErrCodeProviderEmpty models.ErrorCode = "llm_cost_provider_empty"

var ErrProviderEmpty = models.NewValidationIssue(
	ErrCodeProviderEmpty,
	"provider must not be empty",
	models.WithFieldString("provider"),
	models.WithCriticalSeverity(),
	commonhttp.WithHTTPStatusCodeAttribute(http.StatusBadRequest),
)

const ErrCodeModelIDEmpty models.ErrorCode = "llm_cost_model_id_empty"

var ErrModelIDEmpty = models.NewValidationIssue(
	ErrCodeModelIDEmpty,
	"model_id must not be empty",
	models.WithFieldString("model_id"),
	models.WithCriticalSeverity(),
	commonhttp.WithHTTPStatusCodeAttribute(http.StatusBadRequest),
)

const ErrCodeNamespaceEmpty models.ErrorCode = "llm_cost_namespace_empty"

var ErrNamespaceEmpty = models.NewValidationIssue(
	ErrCodeNamespaceEmpty,
	"namespace must not be empty",
	models.WithFieldString("namespace"),
	models.WithCriticalSeverity(),
	commonhttp.WithHTTPStatusCodeAttribute(http.StatusBadRequest),
)

const ErrCodePriceIDEmpty models.ErrorCode = "llm_cost_price_id_empty"

var ErrPriceIDEmpty = models.NewValidationIssue(
	ErrCodePriceIDEmpty,
	"price id must not be empty",
	models.WithFieldString("id"),
	models.WithCriticalSeverity(),
	commonhttp.WithHTTPStatusCodeAttribute(http.StatusBadRequest),
)

const ErrCodePriceMustBeNonNegative models.ErrorCode = "llm_cost_price_non_negative"

var ErrPriceMustBeNonNegative = models.NewValidationIssue(
	ErrCodePriceMustBeNonNegative,
	"price must be non-negative",
	models.WithFieldString("pricing"),
	models.WithCriticalSeverity(),
	commonhttp.WithHTTPStatusCodeAttribute(http.StatusBadRequest),
)

const ErrCodeEffectiveFromAfterTo models.ErrorCode = "llm_cost_effective_from_after_to"

var ErrEffectiveFromAfterTo = models.NewValidationIssue(
	ErrCodeEffectiveFromAfterTo,
	"effective_from must not be after effective_to",
	models.WithFieldString("effective_from"),
	models.WithCriticalSeverity(),
	commonhttp.WithHTTPStatusCodeAttribute(http.StatusBadRequest),
)

const ErrCodeInvalidPriceSource models.ErrorCode = "llm_cost_invalid_source"

var ErrInvalidPriceSource = models.NewValidationIssue(
	ErrCodeInvalidPriceSource,
	"invalid price source",
	models.WithFieldString("source"),
	models.WithCriticalSeverity(),
	commonhttp.WithHTTPStatusCodeAttribute(http.StatusBadRequest),
)