| |
|
|
| package openmeter |
|
|
| import ( |
| "encoding/json" |
| "fmt" |
| "time" |
| ) |
|
|
| |
| type CreateFeatureRequest struct { |
| |
| |
| |
| Name string `json:"name"` |
| |
| |
| |
| Description *string `json:"description,omitempty"` |
| Labels *map[string]string `json:"labels,omitempty"` |
| Key string `json:"key"` |
| |
| |
| Meter *FeatureMeterReferenceInput `json:"meter,omitempty"` |
| |
| |
| |
| UnitCost *FeatureUnitCost `json:"unit_cost,omitempty"` |
| } |
|
|
| |
| type Feature struct { |
| ID string `json:"id"` |
| |
| |
| |
| Name string `json:"name"` |
| |
| |
| |
| Description *string `json:"description,omitempty"` |
| Labels map[string]string `json:"labels,omitempty"` |
| |
| CreatedAt time.Time `json:"created_at"` |
| |
| UpdatedAt time.Time `json:"updated_at"` |
| |
| DeletedAt *time.Time `json:"deleted_at,omitempty"` |
| Key string `json:"key"` |
| |
| |
| Meter *FeatureMeterReference `json:"meter,omitempty"` |
| |
| |
| |
| UnitCost *FeatureUnitCost `json:"unit_cost,omitempty"` |
| } |
|
|
| |
| type FeatureCostQueryResult struct { |
| |
| From *time.Time `json:"from,omitempty"` |
| |
| To *time.Time `json:"to,omitempty"` |
| |
| Data []FeatureCostQueryRow `json:"data"` |
| } |
|
|
| |
| type FeatureCostQueryRow struct { |
| |
| Usage Numeric `json:"usage"` |
| |
| |
| Cost Nullable[Numeric] `json:"cost"` |
| |
| Currency string `json:"currency"` |
| |
| |
| Detail *string `json:"detail,omitempty"` |
| |
| From time.Time `json:"from"` |
| |
| To time.Time `json:"to"` |
| |
| |
| Dimensions map[string]string `json:"dimensions"` |
| } |
|
|
| |
| type FeatureLLMTokenType string |
|
|
| const ( |
| FeatureLLMTokenTypeInput FeatureLLMTokenType = "input" |
| FeatureLLMTokenTypeOutput FeatureLLMTokenType = "output" |
| FeatureLLMTokenTypeCacheRead FeatureLLMTokenType = "cache_read" |
| FeatureLLMTokenTypeCacheWrite FeatureLLMTokenType = "cache_write" |
| FeatureLLMTokenTypeReasoning FeatureLLMTokenType = "reasoning" |
| FeatureLLMTokenTypeRequest FeatureLLMTokenType = "request" |
| FeatureLLMTokenTypeResponse FeatureLLMTokenType = "response" |
| ) |
|
|
| func (value FeatureLLMTokenType) Valid() bool { |
| switch value { |
| case FeatureLLMTokenTypeInput, FeatureLLMTokenTypeOutput, FeatureLLMTokenTypeCacheRead, FeatureLLMTokenTypeCacheWrite, FeatureLLMTokenTypeReasoning, FeatureLLMTokenTypeRequest, FeatureLLMTokenTypeResponse: |
| return true |
| default: |
| return false |
| } |
| } |
|
|
| |
| |
| |
| type FeatureLLMUnitCost struct { |
| |
| Type FeatureUnitCostType `json:"type"` |
| |
| |
| ProviderProperty *string `json:"provider_property,omitempty"` |
| |
| |
| Provider *string `json:"provider,omitempty"` |
| |
| |
| ModelProperty *string `json:"model_property,omitempty"` |
| |
| |
| Model *string `json:"model,omitempty"` |
| |
| |
| TokenTypeProperty *string `json:"token_type_property,omitempty"` |
| |
| |
| |
| TokenType *FeatureLLMTokenType `json:"token_type,omitempty"` |
| |
| |
| |
| Pricing *FeatureLLMUnitCostPricing `json:"pricing,omitempty"` |
| } |
|
|
| |
| type FeatureLLMUnitCostPricing struct { |
| |
| InputPerToken Numeric `json:"input_per_token"` |
| |
| OutputPerToken Numeric `json:"output_per_token"` |
| |
| CacheReadPerToken *Numeric `json:"cache_read_per_token,omitempty"` |
| |
| ReasoningPerToken *Numeric `json:"reasoning_per_token,omitempty"` |
| |
| CacheWritePerToken *Numeric `json:"cache_write_per_token,omitempty"` |
| } |
|
|
| |
| type FeatureManualUnitCost struct { |
| |
| Type FeatureUnitCostType `json:"type"` |
| |
| Amount Numeric `json:"amount"` |
| } |
|
|
| |
| type FeatureMeterReference struct { |
| |
| ID string `json:"id"` |
| |
| Filters map[string]QueryFilterStringMapItem `json:"filters,omitempty"` |
| } |
|
|
| |
| type FeatureMeterReferenceInput struct { |
| |
| ID string `json:"id"` |
| |
| Filters *map[string]QueryFilterStringMapItemInput `json:"filters,omitempty"` |
| } |
|
|
| |
| type FeaturePagePaginatedResponse struct { |
| Data []Feature `json:"data"` |
| Meta PaginatedMeta `json:"meta"` |
| } |
|
|
| |
| |
| |
| |
| |
| type FeatureUnitCost struct { |
| Type string `json:"type"` |
| raw json.RawMessage |
| } |
|
|
| func (u *FeatureUnitCost) UnmarshalJSON(data []byte) error { |
| u.raw = append([]byte(nil), data...) |
| if string(data) == "null" { |
| u.Type = "" |
| return nil |
| } |
|
|
| var envelope struct { |
| Value string `json:"type"` |
| } |
| if err := json.Unmarshal(data, &envelope); err != nil { |
| return err |
| } |
| u.Type = envelope.Value |
| return nil |
| } |
|
|
| func (u FeatureUnitCost) MarshalJSON() ([]byte, error) { |
| if len(u.raw) == 0 { |
| return []byte("null"), nil |
| } |
| return append([]byte(nil), u.raw...), nil |
| } |
|
|
| func (u FeatureUnitCost) AsFeatureManualUnitCost() (*FeatureManualUnitCost, error) { |
| if u.Type != "manual" { |
| return nil, fmt.Errorf("FeatureUnitCost: expected type %q, got %q", "manual", u.Type) |
| } |
| var value FeatureManualUnitCost |
| if err := json.Unmarshal(u.raw, &value); err != nil { |
| return nil, err |
| } |
| return &value, nil |
| } |
|
|
| func FeatureUnitCostFromFeatureManualUnitCost(value FeatureManualUnitCost) (FeatureUnitCost, error) { |
| value.Type = "manual" |
| raw, err := json.Marshal(value) |
| if err != nil { |
| return FeatureUnitCost{}, err |
| } |
| var result FeatureUnitCost |
| if err := result.UnmarshalJSON(raw); err != nil { |
| return FeatureUnitCost{}, err |
| } |
| return result, nil |
| } |
|
|
| func (u FeatureUnitCost) AsFeatureLLMUnitCost() (*FeatureLLMUnitCost, error) { |
| if u.Type != "llm" { |
| return nil, fmt.Errorf("FeatureUnitCost: expected type %q, got %q", "llm", u.Type) |
| } |
| var value FeatureLLMUnitCost |
| if err := json.Unmarshal(u.raw, &value); err != nil { |
| return nil, err |
| } |
| return &value, nil |
| } |
|
|
| func FeatureUnitCostFromFeatureLLMUnitCost(value FeatureLLMUnitCost) (FeatureUnitCost, error) { |
| value.Type = "llm" |
| raw, err := json.Marshal(value) |
| if err != nil { |
| return FeatureUnitCost{}, err |
| } |
| var result FeatureUnitCost |
| if err := result.UnmarshalJSON(raw); err != nil { |
| return FeatureUnitCost{}, err |
| } |
| return result, nil |
| } |
|
|
| |
| type FeatureUnitCostType string |
|
|
| const ( |
| FeatureUnitCostTypeLLM FeatureUnitCostType = "llm" |
| FeatureUnitCostTypeManual FeatureUnitCostType = "manual" |
| ) |
|
|
| func (value FeatureUnitCostType) Valid() bool { |
| switch value { |
| case FeatureUnitCostTypeLLM, FeatureUnitCostTypeManual: |
| return true |
| default: |
| return false |
| } |
| } |
|
|
| |
| |
| type UpdateFeatureRequest struct { |
| |
| |
| |
| |
| UnitCost Nullable[FeatureUnitCost] `json:"unit_cost,omitempty"` |
| } |
|
|