Skip to content
Open
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
6 changes: 5 additions & 1 deletion docs/src/content/docs/providers/grok.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ Search reaches Grok-native tools when the caller asks for it:

- Anthropic's `web_search_20250305` declaration maps to Grok hosted web search.
The Grok CLI endpoint accepts the minimal declaration without domain or
location constraints.
location constraints. `CCP_SEARCH_CONSTRAINTS` selects what happens when
Claude Code still sends those fields: `soft` (default) copies constraints into a
prompt hint, `warning` drops them and logs, `hard` returns 400.
- A caller-managed search tool remains a function tool for the caller to run.
- An X or Twitter query is additionally offered hosted `x_search`, which the
model can use or ignore alongside the caller's tools.
Expand Down Expand Up @@ -83,6 +85,8 @@ Traffic captures redact Anthropic image data and upstream image data URLs.
- `CCP_GROK_TOOL_IMAGE` selects `omit`, `reattach`, `inline`, or `reject`.
- `CCP_GROK_HOSTED_SEARCH` enables hosted search replacement and forcing.
- `CCP_GROK_SEARCH_BLOCKS` selects `text` or `native` hosted-search reporting.
- `CCP_SEARCH_CONSTRAINTS` selects `soft`, `warning`, or `hard` for Anthropic
hosted-search domain and location fields Grok cannot enforce.

See [Configuration](/reference/configuration/) for defaults.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ claude-code-proxy targets Claude Code's practical Anthropic API usage rather tha
- Model availability varies by account and region.
- Hosted general web search and X search are translated with citations and usage.
- Hosted web search omits `max_uses` because the Grok CLI endpoint exposes no
equivalent cap. Non-null domain filters and user location are rejected because
dropping them would weaken the caller's requested search scope.
equivalent cap. Non-null domain filters and user location follow
`CCP_SEARCH_CONSTRAINTS` (`soft` default, `warning`, or `hard`) because the
endpoint cannot enforce them.
- The implemented multimodal path does not claim general image or video compatibility.

## Cursor Agent
Expand Down
1 change: 1 addition & 0 deletions docs/src/content/docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ All keys are optional. An unreadable file, malformed JSON, or incompatible field
| `CCP_LOG_VERBOSE` | `log.verbose` | `false` | Preserves full string fields in structured logs when present, regardless of its value. |
| `CCP_TRAFFIC_LOG` | none | `false` | Enables full request captures for `1`, `true`, or `yes`. |
| `XDG_STATE_HOME` | none | `~/.local/state` | State base on macOS and Linux. |
| `CCP_SEARCH_CONSTRAINTS` | none | `soft` | How to treat Anthropic hosted-search options a provider cannot enforce (`allowed_domains`, `blocked_domains`, `user_location`). `soft` drops them and copies constraints into a prompt hint. `warning` drops them and logs. `hard` returns 400. First provider: Grok. Codex maps domain filters natively and ignores this setting. |

`CCP_CONFIG_DIR` affects `config.json` and file-backed provider auth. It does not relocate the state directory.

Expand Down
34 changes: 34 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,40 @@ pub fn grok_search_blocks() -> GrokSearchBlocks {
parse_grok_search_blocks(std::env::var("CCP_GROK_SEARCH_BLOCKS").ok().as_deref())
}

// ---------------------------------------------------------------------------
// Hosted-search constraints that a provider cannot enforce
// (CCP_SEARCH_CONSTRAINTS)
// ---------------------------------------------------------------------------

/// How the proxy treats Anthropic hosted-search options that the upstream
/// provider cannot enforce (`allowed_domains`, `blocked_domains`,
/// `user_location`).
///
/// Applies to providers that lack those fields. First provider: Grok. Codex
/// maps domain filters natively and does not use this policy.
///
/// `Soft` is the default: drop the fields and copy constraints into a prompt hint.
/// `Warning` drops them, logs, and continues with no hint. `Hard` is the
/// legacy 400. Unknown values fall back to `Soft`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SearchConstraints {
Soft,
Warning,
Hard,
}

pub fn parse_search_constraints(raw: Option<&str>) -> SearchConstraints {
match raw.map(str::trim) {
Some("hard") => SearchConstraints::Hard,
Some("warning") => SearchConstraints::Warning,
_ => SearchConstraints::Soft,
}
}

pub fn search_constraints() -> SearchConstraints {
parse_search_constraints(std::env::var("CCP_SEARCH_CONSTRAINTS").ok().as_deref())
}

struct ResolvedOpenCodeConfig {
api_key: Option<String>,
api_key_source: Option<&'static str>,
Expand Down
Loading
Loading