Repository navigation
Expand file tree
/
Copy pathtest_api.rs
More file actions
57 lines (52 loc) · 1.83 KB
/
Copy pathtest_api.rs
File metadata and controls
57 lines (52 loc) · 1.83 KB
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
use reqwest::header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE, USER_AGENT};
#[tokio::main]
async fn main() {
let client = reqwest::Client::builder()
.user_agent("cortex-cli/0.1.0")
.timeout(std::time::Duration::from_secs(300))
.tcp_nodelay(true)
.build()
.unwrap();
// Include tools like the CLI does
let body = serde_json::json!({
"model": "claude-opus-4-5-20251101",
"input": [{"role": "user", "content": "hi"}],
"stream": true,
"tools": [
{
"type": "function",
"name": "Read",
"description": "Read file contents",
"parameters": {"type": "object", "properties": {"path": {"type": "string"}}, "required": ["path"]}
},
{
"type": "function",
"name": "Write",
"description": "Write to file",
"parameters": {"type": "object", "properties": {"path": {"type": "string"}, "content": {"type": "string"}}, "required": ["path", "content"]}
}
],
"tool_choice": "auto"
});
println!("Sending request with tools...");
let resp = client
.post("https://api.cortex.foundation/v1/responses")
.header(CONTENT_TYPE, "application/json")
.header(ACCEPT, "text/event-stream")
.header(USER_AGENT, "cortex-cli/0.1.0")
.header(
AUTHORIZATION,
format!(
"Bearer {}",
std::env::var("CORTEX_API_KEY")
.expect("CORTEX_API_KEY environment variable required")
),
)
.json(&body)
.send()
.await
.unwrap();
println!("Status: {}", resp.status());
let text = resp.text().await.unwrap();
println!("Body: {}", &text[..text.len().min(500)]);
}