Skip to content

Commit 051be03

Browse files
author
Nicholas Cecere
committed
Add thinking capability to model resource
1 parent 697902c commit 051be03

File tree

5 files changed

+66
-20
lines changed

5 files changed

+66
-20
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.2.4] - 2025-03-13
9+
10+
### Added
11+
- Added new `thinking` capability to model resource with configurable parameters:
12+
- `thinking_enabled` - Boolean to enable/disable thinking capability (default: false)
13+
- `thinking_budget_tokens` - Integer to set token budget for thinking (default: 1024)
14+
815
## [0.2.2] - 2025-02-06
916

1017
### Added

docs/resources/model.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ resource "litellm_model" "gpt4" {
1515
tier = "paid"
1616
mode = "completion"
1717
reasoning_effort = "medium"
18+
thinking_enabled = true
19+
thinking_budget_tokens = 1024
1820
tpm = 100000
1921
rpm = 1000
2022
@@ -64,6 +66,10 @@ The following arguments are supported:
6466
* `medium`
6567
* `high`
6668

69+
* `thinking_enabled` - (Optional) Enables the model's thinking capability. Default is `false`.
70+
71+
* `thinking_budget_tokens` - (Optional) Sets the token budget for the model's thinking capability. Default is `1024`.
72+
6773
* `input_cost_per_million_tokens` - (Optional) Cost per million input tokens. This will be automatically converted to the per-token cost required by the API.
6874

6975
* `output_cost_per_million_tokens` - (Optional) Cost per million output tokens. This will be automatically converted to the per-token cost required by the API.

litellm/resource_model.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ func resourceLiteLLMModel() *schema.Resource {
3838
"high",
3939
}, false),
4040
},
41+
"thinking_enabled": {
42+
Type: schema.TypeBool,
43+
Optional: true,
44+
Default: false,
45+
},
46+
"thinking_budget_tokens": {
47+
Type: schema.TypeInt,
48+
Optional: true,
49+
Default: 1024,
50+
},
4151
"model_api_key": {
4252
Type: schema.TypeString,
4353
Optional: true,

litellm/resource_model_crud.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ func createOrUpdateModel(d *schema.ResourceData, m interface{}, isUpdate bool) e
3535
modelID = uuid.New().String()
3636
}
3737

38+
// Create thinking configuration if enabled
39+
var thinking map[string]interface{}
40+
if d.Get("thinking_enabled").(bool) {
41+
thinking = map[string]interface{}{
42+
"type": "enabled",
43+
"budget_tokens": d.Get("thinking_budget_tokens").(int),
44+
}
45+
}
46+
3847
modelReq := ModelRequest{
3948
ModelName: d.Get("model_name").(string),
4049
LiteLLMParams: LiteLLMParams{
@@ -58,6 +67,7 @@ func createOrUpdateModel(d *schema.ResourceData, m interface{}, isUpdate bool) e
5867
VertexLocation: d.Get("vertex_location").(string),
5968
VertexCredentials: d.Get("vertex_credentials").(string),
6069
ReasoningEffort: d.Get("reasoning_effort").(string),
70+
Thinking: thinking,
6171
},
6272
ModelInfo: ModelInfo{
6373
ID: modelID,
@@ -140,6 +150,18 @@ func resourceLiteLLMModelRead(d *schema.ResourceData, m interface{}) error {
140150
d.Set("input_cost_per_million_tokens", d.Get("input_cost_per_million_tokens"))
141151
d.Set("output_cost_per_million_tokens", d.Get("output_cost_per_million_tokens"))
142152

153+
// Handle thinking configuration
154+
if modelResp.LiteLLMParams.Thinking != nil {
155+
if thinkingType, ok := modelResp.LiteLLMParams.Thinking["type"].(string); ok && thinkingType == "enabled" {
156+
d.Set("thinking_enabled", true)
157+
if budgetTokens, ok := modelResp.LiteLLMParams.Thinking["budget_tokens"].(float64); ok {
158+
d.Set("thinking_budget_tokens", int(budgetTokens))
159+
}
160+
}
161+
} else {
162+
d.Set("thinking_enabled", false)
163+
}
164+
143165
return nil
144166
}
145167

litellm/types.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,27 @@ type TeamResponse struct {
4545

4646
// LiteLLMParams represents the parameters for LiteLLM.
4747
type LiteLLMParams struct {
48-
CustomLLMProvider string `json:"custom_llm_provider"`
49-
TPM int `json:"tpm,omitempty"`
50-
RPM int `json:"rpm,omitempty"`
51-
ReasoningEffort string `json:"reasoning_effort,omitempty"`
52-
APIKey string `json:"api_key,omitempty"`
53-
APIBase string `json:"api_base,omitempty"`
54-
APIVersion string `json:"api_version,omitempty"`
55-
Model string `json:"model"`
56-
InputCostPerToken float64 `json:"input_cost_per_token,omitempty"`
57-
OutputCostPerToken float64 `json:"output_cost_per_token,omitempty"`
58-
InputCostPerPixel float64 `json:"input_cost_per_pixel,omitempty"`
59-
OutputCostPerPixel float64 `json:"output_cost_per_pixel,omitempty"`
60-
InputCostPerSecond float64 `json:"input_cost_per_second,omitempty"`
61-
OutputCostPerSecond float64 `json:"output_cost_per_second,omitempty"`
62-
AWSAccessKeyID string `json:"aws_access_key_id,omitempty"`
63-
AWSSecretAccessKey string `json:"aws_secret_access_key,omitempty"`
64-
AWSRegionName string `json:"aws_region_name,omitempty"`
65-
VertexProject string `json:"vertex_project,omitempty"`
66-
VertexLocation string `json:"vertex_location,omitempty"`
67-
VertexCredentials string `json:"vertex_credentials,omitempty"`
48+
CustomLLMProvider string `json:"custom_llm_provider"`
49+
TPM int `json:"tpm,omitempty"`
50+
RPM int `json:"rpm,omitempty"`
51+
ReasoningEffort string `json:"reasoning_effort,omitempty"`
52+
Thinking map[string]interface{} `json:"thinking,omitempty"`
53+
APIKey string `json:"api_key,omitempty"`
54+
APIBase string `json:"api_base,omitempty"`
55+
APIVersion string `json:"api_version,omitempty"`
56+
Model string `json:"model"`
57+
InputCostPerToken float64 `json:"input_cost_per_token,omitempty"`
58+
OutputCostPerToken float64 `json:"output_cost_per_token,omitempty"`
59+
InputCostPerPixel float64 `json:"input_cost_per_pixel,omitempty"`
60+
OutputCostPerPixel float64 `json:"output_cost_per_pixel,omitempty"`
61+
InputCostPerSecond float64 `json:"input_cost_per_second,omitempty"`
62+
OutputCostPerSecond float64 `json:"output_cost_per_second,omitempty"`
63+
AWSAccessKeyID string `json:"aws_access_key_id,omitempty"`
64+
AWSSecretAccessKey string `json:"aws_secret_access_key,omitempty"`
65+
AWSRegionName string `json:"aws_region_name,omitempty"`
66+
VertexProject string `json:"vertex_project,omitempty"`
67+
VertexLocation string `json:"vertex_location,omitempty"`
68+
VertexCredentials string `json:"vertex_credentials,omitempty"`
6869
}
6970

7071
// ModelInfo represents information about a model.

0 commit comments

Comments
 (0)