Skip to content

Use Claude Code with your ChatGPT, Kimi, Cursor or Grok subscription via a local Anthropic-compatible proxy

Rust

support Grok reasoning effort

Raine Virta721470a9f6ec
diff --git a/docs/src/content/docs/providers/grok.md b/docs/src/content/docs/providers/grok.md
index 3ed3fdd..b01414c 100644
--- a/docs/src/content/docs/providers/grok.md
+++ b/docs/src/content/docs/providers/grok.md
@@ -34,7 +34,7 @@ ANTHROPIC_SMALL_FAST_MODEL=grok-4.6 \
## Reasoning and tools
-The proxy translates Claude messages, function tools, tool results, thinking controls, token usage, and streaming events. Grok reasoning text appears as Claude Code thinking blocks.
+The proxy translates Claude messages, function tools, tool results, thinking controls, token usage, and streaming events. Grok reasoning text appears as Claude Code thinking blocks. Grok supports `none`, `low`, `medium`, and `high` effort levels. `xhigh` is forwarded for `grok-4.6`; higher compatibility levels are mapped to the highest supported Grok level for other registered models.
Search reaches Grok-native tools when the caller asks for it:
@@ -55,7 +55,7 @@ hosted-tool blocks.
## OpenAI-compatible APIs
-When the OpenAI routes are enabled, Grok models work with both `POST /v1/chat/completions` and `POST /v1/responses`. Text, reasoning, function tools, tool results, token limits, streaming, usage, and errors use the standard shape for the chosen route. Responses requests also return Grok searches as `web_search_call` items. Citations are available on both routes.
+When the OpenAI routes are enabled, Grok models work with both `POST /v1/chat/completions` and `POST /v1/responses`. Text, reasoning, function tools, tool results, token limits, streaming, usage, and errors use the standard shape for the chosen route. Set `reasoning_effort` on Chat Completions or `reasoning.effort` on Responses. Responses requests also return Grok searches as `web_search_call` items. Citations are available on both routes.
## Multimodal support
diff --git a/docs/src/content/docs/reference/http-api.md b/docs/src/content/docs/reference/http-api.md
index 3a593c7..e5fbbaf 100644
--- a/docs/src/content/docs/reference/http-api.md
+++ b/docs/src/content/docs/reference/http-api.md
@@ -81,6 +81,8 @@ For Kimi, Grok, OpenCode Go, and Cursor, the route accepts:
- `reasoning_effort`
- streaming, non-streaming responses, and `stream_options.include_usage`
+For Grok, `reasoning_effort` accepts `none`, `low`, `medium`, `high`, `xhigh`, and `max`. `xhigh` is available at full strength on `grok-4.6`; `xhigh` and `max` map to `high` for other registered Grok models.
+
Codex uses its own compatibility path. It supports text messages, `reasoning_effort`, `response_format`, `stream_options.include_usage`, `temperature`, `top_p`, and `user`. Reasoning effort defaults to `medium`, and the proxy-wide Codex effort setting takes precedence. Function calls, images, audio, log probabilities, multiple choices, storage, and output token limits are not supported on the Codex Chat Completions path.
Non-streaming requests return a `chat.completion` object. Streaming requests return `chat.completion.chunk` events followed by `data: [DONE]`. Grok citations are included in message annotations.
@@ -133,6 +135,8 @@ Codex models use native Responses passthrough, including native JSON and SSE out
- `reasoning.effort`
- streaming or non-streaming output
+For Grok, `reasoning.effort` accepts `none`, `low`, `medium`, `high`, `xhigh`, and `max`, with model-specific mapping for the highest levels.
+
Responses include the accepted tool settings. Grok search appears as a `web_search_call`, with sources in URL citation annotations. When a provider reaches its output token limit, the response status is `incomplete` and the reason is `max_output_tokens`.
`store: true` and other unsupported non-null fields return an error. Stored response retrieval, deletion, and WebSocket client connections are not supported.
diff --git a/src/openai_compat/request.rs b/src/openai_compat/request.rs
index c467d66..fac3aa6 100644
--- a/src/openai_compat/request.rs
+++ b/src/openai_compat/request.rs
@@ -136,7 +136,7 @@ pub fn parse_request(
} else {
OpenAiResponseMetadata::default()
};
- let effort = parse_effort(surface, object)?;
+ let effort = parse_effort(surface, object, provider)?;
validate_cursor(provider, session_id, stream, &messages, &tools)?;
let mut extra = Map::new();
@@ -299,6 +299,7 @@ fn parse_max_tokens(
fn parse_effort(
surface: OpenAiSurface,
object: &Map<String, Value>,
+ provider: &str,
) -> Result<Option<String>, OpenAiError> {
let value = match surface {
OpenAiSurface::ChatCompletions => object.get("reasoning_effort"),
@@ -325,15 +326,21 @@ fn parse_effort(
}),
)
})?;
- match effort {
- "low" | "medium" | "high" | "xhigh" | "max" => Ok(Some(effort.to_string())),
- _ => Err(OpenAiError::invalid(
+ let supported = if provider == "grok" {
+ ["none", "low", "medium", "high", "xhigh", "max"].as_slice()
+ } else {
+ ["low", "medium", "high", "xhigh", "max"].as_slice()
+ };
+ if supported.contains(&effort) {
+ Ok(Some(effort.to_string()))
+ } else {
+ Err(OpenAiError::invalid(
format!("Unsupported reasoning effort: '{effort}'"),
Some(match surface {
OpenAiSurface::ChatCompletions => "reasoning_effort",
OpenAiSurface::Responses => "reasoning.effort",
}),
- )),
+ ))
}
}
@@ -1234,6 +1241,51 @@ mod tests {
assert_eq!(parsed.messages.extra["output_config"]["effort"], "high");
}
+ #[test]
+ fn grok_effort_accepts_none_on_both_openai_surfaces() {
+ let chat = parse_request(
+ OpenAiSurface::ChatCompletions,
+ json!({
+ "model":"grok-4.5",
+ "messages":[{"role":"user","content":"hello"}],
+ "reasoning_effort":"none"
+ }),
+ "grok",
+ None,
+ )
+ .unwrap();
+ assert_eq!(chat.messages.extra["output_config"]["effort"], "none");
+
+ let responses = parse_request(
+ OpenAiSurface::Responses,
+ json!({
+ "model":"grok-4.5",
+ "input":"hello",
+ "reasoning":{"effort":"none"}
+ }),
+ "grok",
+ None,
+ )
+ .unwrap();
+ assert_eq!(responses.messages.extra["output_config"]["effort"], "none");
+ }
+
+ #[test]
+ fn non_grok_effort_rejects_none() {
+ let error = parse_request(
+ OpenAiSurface::ChatCompletions,
+ json!({
+ "model":"kimi-k2.6",
+ "messages":[{"role":"user","content":"hello"}],
+ "reasoning_effort":"none"
+ }),
+ "kimi",
+ None,
+ )
+ .unwrap_err();
+ assert_eq!(error.param.as_deref(), Some("reasoning_effort"));
+ }
+
#[test]
fn rejects_unsupported_fields_and_cursor_tools_without_session() {
let error = parse_request(
diff --git a/src/providers/grok/translate/request.rs b/src/providers/grok/translate/request.rs
index 3300781..ecfbaab 100644
--- a/src/providers/grok/translate/request.rs
+++ b/src/providers/grok/translate/request.rs
@@ -5,7 +5,9 @@ use serde_json::Value;
use crate::anthropic::schema::{Message, MessagesRequest};
use crate::config::GrokToolImageMode;
-use crate::providers::translate_shared::{ImageSource, image_source_to_url, parallel_tool_calls};
+use crate::providers::translate_shared::{
+ ImageSource, image_source_to_url, parallel_tool_calls, read_effort_with_allowed,
+};
#[derive(Debug, Clone, Serialize)]
pub struct GrokResponsesRequest {
@@ -19,6 +21,8 @@ pub struct GrokResponsesRequest {
pub tool_choice: Option<GrokToolChoice>,
#[serde(skip_serializing_if = "Option::is_none")]
pub parallel_tool_calls: Option<bool>,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub reasoning: Option<GrokReasoning>,
pub store: bool,
pub stream: bool,
#[serde(skip_serializing_if = "Option::is_none")]
@@ -136,6 +140,11 @@ pub enum GrokToolChoice {
Function { r#type: String, name: String },
}
+#[derive(Debug, Clone, Serialize)]
+pub struct GrokReasoning {
+ pub effort: String,
+}
+
pub fn translate_request(
req: &MessagesRequest,
model: String,
@@ -214,6 +223,12 @@ pub fn translate_request_with_options(
} else {
parse_tool_choice(req.extra.get("tool_choice"), &mut tools)?
};
+ let reasoning =
+ read_effort_with_allowed(req, &["none", "low", "medium", "high", "xhigh", "max"])?.map(
+ |effort| GrokReasoning {
+ effort: map_reasoning_effort(effort, &model),
+ },
+ );
let mut call_ids = HashSet::new();
let mut input = Vec::new();
let mut budget = ReattachBudget::new(&req.messages, image_mode);
@@ -227,6 +242,7 @@ pub fn translate_request_with_options(
tools,
tool_choice,
parallel_tool_calls: parallel_tool_calls(req),
+ reasoning,
store: false,
stream: true,
max_output_tokens: req.max_tokens,
@@ -389,6 +405,15 @@ fn requests_web_search(req: &MessagesRequest) -> bool {
.any(|phrase| contains_phrase(&text, phrase))
}
+fn map_reasoning_effort(effort: &str, model: &str) -> String {
+ match effort {
+ "none" | "low" | "medium" | "high" => effort.to_string(),
+ "xhigh" | "max" if model == "grok-4.6" => "xhigh".to_string(),
+ "xhigh" | "max" => "high".to_string(),
+ _ => unreachable!("read_effort_with_allowed validates the effort"),
+ }
+}
+
fn reject_unknown_top_level(req: &MessagesRequest) -> anyhow::Result<()> {
for key in req.extra.keys() {
if ![
@@ -1296,6 +1321,53 @@ mod tests {
assert_eq!(value["input"][2]["type"], "function_call_output");
assert_eq!(value["tool_choice"]["type"], "function");
}
+ #[test]
+ fn grok_translation_forwards_reasoning_effort() {
+ let cases = [
+ ("grok-4.5", "none", "none"),
+ ("grok-4.5", "low", "low"),
+ ("grok-4.5", "high", "high"),
+ ("grok-4.5", "xhigh", "high"),
+ ("grok-4.5", "max", "high"),
+ ("grok-4.6", "xhigh", "xhigh"),
+ ("grok-4.6", "max", "xhigh"),
+ ];
+ for (model, requested, expected) in cases {
+ let request: MessagesRequest = serde_json::from_value(serde_json::json!({
+ "model": model,
+ "messages": [{"role":"user","content":"hello"}],
+ "output_config": {"effort": requested}
+ }))
+ .unwrap();
+ let value =
+ serde_json::to_value(translate_request(&request, model.into()).unwrap()).unwrap();
+ assert_eq!(value["reasoning"]["effort"], expected);
+ }
+ }
+
+ #[test]
+ fn grok_translation_omits_reasoning_without_effort() {
+ let request: MessagesRequest = serde_json::from_value(serde_json::json!({
+ "model":"grok-4.5",
+ "messages":[{"role":"user","content":"hello"}]
+ }))
+ .unwrap();
+ let value =
+ serde_json::to_value(translate_request(&request, "grok-4.5".into()).unwrap()).unwrap();
+ assert!(value.get("reasoning").is_none());
+ }
+
+ #[test]
+ fn grok_translation_rejects_unknown_reasoning_effort() {
+ let request: MessagesRequest = serde_json::from_value(serde_json::json!({
+ "model":"grok-4.5",
+ "messages":[{"role":"user","content":"hello"}],
+ "output_config": {"effort": "invalid"}
+ }))
+ .unwrap();
+ assert!(translate_request(&request, "grok-4.5".into()).is_err());
+ }
+
#[test]
fn grok_translation_maps_claude_web_search_to_hosted_web_search() {
let request: MessagesRequest = serde_json::from_value(serde_json::json!({
diff --git a/src/providers/translate_shared.rs b/src/providers/translate_shared.rs
index 77acd03..e98d871 100644
--- a/src/providers/translate_shared.rs
+++ b/src/providers/translate_shared.rs
@@ -67,14 +67,20 @@ pub fn parallel_tool_calls(req: &MessagesRequest) -> Option<bool> {
}
pub fn read_effort(req: &MessagesRequest) -> Result<Option<&str>, anyhow::Error> {
+ read_effort_with_allowed(req, &["low", "medium", "high", "xhigh", "max"])
+}
+
+pub fn read_effort_with_allowed<'a>(
+ req: &'a MessagesRequest,
+ allowed: &[&str],
+) -> Result<Option<&'a str>, anyhow::Error> {
let output_config = match req.extra.get("output_config") {
Some(Value::Object(m)) => m,
_ => return Ok(None),
};
match output_config.get("effort") {
Some(Value::String(s)) => {
- let valid = ["low", "medium", "high", "xhigh", "max"];
- if valid.contains(&s.as_str()) {
+ if allowed.contains(&s.as_str()) {
Ok(Some(s.as_str()))
} else {
anyhow::bail!("Invalid output_config.effort: {s}")