brainwires-provider 0.11.0

LLM provider implementations (Anthropic, OpenAI Chat + Responses, Google Gemini, Ollama, Bedrock, Vertex AI, local llama.cpp) for the Brainwires Agent Framework. Speech (TTS/STT) providers live in `brainwires-provider-speech`.
Documentation
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
# OpenAI Responses API - Full Specification Reference

> Compiled from official OpenAI docs, Azure OpenAI docs, Go SDK deepwiki, and TypeScript SDK types.
> Last updated: 2026-03-06

---

## Endpoints

| Method | Path | Description |
|--------|------|-------------|
| POST | `/v1/responses` | Create a model response |
| GET | `/v1/responses/{response_id}` | Retrieve a response |
| DELETE | `/v1/responses/{response_id}` | Delete a response |
| POST | `/v1/responses/{response_id}/cancel` | Cancel an in-progress response |
| GET | `/v1/responses/{response_id}/input_items` | List input items |
| POST | `/v1/responses/compact` | Compact a response (context compression) |

---

## POST /v1/responses - Request Parameters

### Required
| Parameter | Type | Description |
|-----------|------|-------------|
| `model` | string | Model ID (e.g., "gpt-4o", "gpt-4.1", "o3", "o4-mini") |
| `input` | string \| array | Text string or array of input items |

### Optional
| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `instructions` | string | null | System/developer instructions |
| `tools` | array | [] | Tool definitions |
| `tool_choice` | string \| object | "auto" | Tool selection strategy |
| `parallel_tool_calls` | boolean | null | Allow parallel tool calls |
| `max_output_tokens` | integer | null | Max tokens in response |
| `temperature` | number | 1.0 | Sampling temperature (0-2) |
| `top_p` | number | 1.0 | Nucleus sampling |
| `stop` | array | null | Stop sequences |
| `frequency_penalty` | number | 0 | Frequency penalty (-2.0 to 2.0) |
| `presence_penalty` | number | 0 | Presence penalty (-2.0 to 2.0) |
| `stream` | boolean | false | Enable SSE streaming |
| `previous_response_id` | string | null | Chain to previous response |
| `store` | boolean | false | Persist response server-side |
| `metadata` | object | {} | Custom key-value pairs (max 16) |
| `truncation` | string | null | Truncation strategy: "auto" \| "disabled" |
| `reasoning` | object | null | Reasoning config (see below) |
| `text` | object | null | Text format config (see below) |
| `include` | array | [] | Extra fields to include in response |
| `user` | string | null | End-user identifier |
| `background` | boolean | false | Execute asynchronously |
| `service_tier` | string | null | Service tier preference |

### `reasoning` Object
```json
{
  "effort": "low" | "medium" | "high",
  "generate_summary": "auto" | "concise" | "detailed",
  "encrypted_content": null  // returned when include contains "reasoning.encrypted_content"
}
```
- `effort`: Controls reasoning depth (for o-series and reasoning models)
- `generate_summary`: Controls reasoning summary generation

### `text` Object (Response Format)
```json
// Plain text (default)
{ "format": { "type": "text" } }

// JSON object (unstructured)
{ "format": { "type": "json_object" } }

// JSON schema (structured output)
{
  "format": {
    "type": "json_schema",
    "name": "schema_name",
    "description": "optional description",
    "schema": { /* JSON Schema */ },
    "strict": true
  }
}
```

### `tool_choice` Values
- `"auto"` - Model decides whether to call tools
- `"required"` - Must call at least one tool
- `"none"` - No tool calls allowed
- `{ "type": "function", "name": "function_name" }` - Force specific function

### `include` Values
- `"file_search_call.results"` - Include file search results
- `"message.input_image.image_url"` - Include input image URLs
- `"computer_call_output.output.image_url"` - Include computer output images
- `"reasoning.encrypted_content"` - Include encrypted reasoning for stateless multi-turn

### `truncation` Values
- `"auto"` - Automatically truncate input to fit context
- `"disabled"` - Error if input exceeds context

---

## Input Item Types

### Message (`type: "message"`)
```json
{
  "type": "message",
  "role": "user" | "assistant" | "system" | "developer",
  "content": "string" | [/* content parts */],
  "status": "completed" | null
}
```

Roles:
- `"user"` - User message
- `"assistant"` - Assistant message (echoing back output)
- `"system"` - System instructions (legacy)
- `"developer"` - Developer instructions (preferred over system)

### Easy/Shorthand Message (no `type` field)
```json
{
  "role": "user",
  "content": "Hello"
}
```

### Function Call Output (`type: "function_call_output"`)
```json
{
  "type": "function_call_output",
  "call_id": "call_abc123",
  "output": "{\"result\": \"value\"}"
}
```

### Computer Call Output (`type: "computer_call_output"`)
```json
{
  "type": "computer_call_output",
  "call_id": "call_abc123",
  "output": {
    "type": "computer_screenshot",
    "image_url": "data:image/png;base64,..."
  }
}
```

### MCP Approval Response (`type: "mcp_approval_response"`)
```json
{
  "type": "mcp_approval_response",
  "approve": true,
  "approval_request_id": "mcpr_abc123"
}
```

### Item Reference (`type: "item_reference"`)
```json
{
  "type": "item_reference",
  "id": "msg_abc123"
}
```

---

## Content Part Types (for structured content arrays)

### Input Content Parts

#### `input_text`
```json
{ "type": "input_text", "text": "Hello world" }
```

#### `input_image`
```json
// URL form
{ "type": "input_image", "image_url": "https://..." , "detail": "auto" | "low" | "high" }

// Base64 form
{ "type": "input_image", "image_url": "data:image/jpeg;base64,..." }

// File ID form
{ "type": "input_image", "file_id": "file_abc123" }
```

#### `input_audio`
```json
{
  "type": "input_audio",
  "data": "base64_audio_data",
  "format": "wav" | "mp3" | "flac" | "webm" | "ogg"
}
```

#### `input_file`
```json
// File ID form
{ "type": "input_file", "file_id": "file_abc123" }

// Inline form
{
  "type": "input_file",
  "filename": "document.pdf",
  "file_data": "data:application/pdf;base64,..."
}
```

### Output Content Parts

#### `output_text`
```json
{
  "type": "output_text",
  "text": "Response text",
  "annotations": [
    {
      "type": "url_citation",
      "url": "https://...",
      "title": "Page Title",
      "start_index": 0,
      "end_index": 10
    },
    {
      "type": "file_citation",
      "file_id": "file_abc123",
      "quote": "quoted text",
      "start_index": 0,
      "end_index": 10
    },
    {
      "type": "file_path",
      "file_id": "file_abc123",
      "start_index": 0,
      "end_index": 10
    }
  ],
  "logprobs": []
}
```

#### `refusal`
```json
{ "type": "refusal", "refusal": "I cannot help with that." }
```

---

## Tool Types

### 1. Function Tool (`type: "function"`)
```json
{
  "type": "function",
  "name": "get_weather",
  "description": "Get weather for a location",
  "parameters": {
    "type": "object",
    "properties": {
      "location": { "type": "string" }
    },
    "required": ["location"]
  },
  "strict": false
}
```

### 2. Web Search (`type: "web_search_preview"`)
```json
{
  "type": "web_search_preview",
  "search_context_size": "low" | "medium" | "high",
  "user_location": {
    "type": "approximate",
    "city": "San Francisco",
    "region": "California",
    "country": "US",
    "timezone": "America/Los_Angeles"
  }
}
```

### 3. File Search (`type: "file_search"`)
```json
{
  "type": "file_search",
  "vector_store_ids": ["vs_abc123"],
  "max_num_results": 20,
  "ranking_options": {
    "ranker": "auto" | "default_2024_08_21",
    "score_threshold": 0.0
  },
  "filters": { /* metadata filter object */ }
}
```

### 4. Code Interpreter (`type: "code_interpreter"`)
```json
{
  "type": "code_interpreter",
  "container": {
    "type": "auto",
    "file_ids": ["file_abc123"]
  }
}
```

### 5. Computer Use (`type: "computer_use_preview"`)
```json
{
  "type": "computer_use_preview",
  "display_width": 1024,
  "display_height": 768,
  "environment": "browser" | "mac" | "windows" | "linux" | "ubuntu"
}
```
Actions: click, double_click, drag, keypress, move, screenshot, scroll, type, wait

### 6. MCP (`type: "mcp"`)
```json
{
  "type": "mcp",
  "server_label": "my_server",
  "server_url": "https://mcp-server.example.com",
  "require_approval": "always" | "never",
  "headers": {
    "Authorization": "Bearer token123"
  },
  "allowed_tools": ["tool1", "tool2"]
}
```

### 7. Image Generation (`type: "image_generation"`)
```json
{
  "type": "image_generation",
  "background": "transparent" | "opaque" | "auto",
  "input_image_mask": { /* mask config */ },
  "output_compression": 0-100,
  "output_format": "png" | "jpeg" | "webp",
  "partial_images": 0,
  "quality": "low" | "medium" | "high" | "auto",
  "size": "1024x1024" | "1536x1024" | "1024x1536" | "auto"
}
```

---

## Output Item Types

### Message (`type: "message"`)
```json
{
  "id": "msg_abc123",
  "type": "message",
  "role": "assistant",
  "status": "completed" | "in_progress" | null,
  "content": [/* output content parts: output_text, refusal */]
}
```

### Function Call (`type: "function_call"`)
```json
{
  "id": "fc_abc123",
  "type": "function_call",
  "name": "get_weather",
  "arguments": "{\"location\":\"SF\"}",
  "call_id": "call_abc123",
  "status": "completed"
}
```

### File Search Call (`type: "file_search_call"`)
```json
{
  "id": "fs_abc123",
  "type": "file_search_call",
  "status": "completed",
  "queries": ["search query"],
  "results": [
    {
      "file_id": "file_abc123",
      "filename": "doc.pdf",
      "score": 0.95,
      "text": "relevant text",
      "attributes": {}
    }
  ]
}
```

### Web Search Call (`type: "web_search_call"`)
```json
{
  "id": "ws_abc123",
  "type": "web_search_call",
  "status": "completed"
}
```

### Computer Call (`type: "computer_call"`)
```json
{
  "id": "cc_abc123",
  "type": "computer_call",
  "call_id": "call_abc123",
  "action": {
    "type": "click" | "screenshot" | "type" | "scroll" | ...,
    "x": 100,
    "y": 200
  },
  "pending_safety_checks": [],
  "status": "completed"
}
```

### Code Interpreter Call (`type: "code_interpreter_call"`)
```json
{
  "id": "ci_abc123",
  "type": "code_interpreter_call",
  "code": "print('hello')",
  "container_id": "ctr_abc123",
  "status": "completed",
  "outputs": [
    { "type": "logs", "logs": "hello\n" },
    { "type": "image", "image_url": "..." },
    { "type": "file", "file_id": "file_abc123" }
  ]
}
```

### MCP Call (`type: "mcp_call"`)
```json
{
  "id": "mcp_abc123",
  "type": "mcp_call",
  "server_label": "github",
  "name": "tool_name",
  "arguments": "{}",
  "output": "result",
  "status": "completed" | "failed"
}
```

### MCP Approval Request (`type: "mcp_approval_request"`)
```json
{
  "id": "mcpr_abc123",
  "type": "mcp_approval_request",
  "name": "tool_name",
  "arguments": {},
  "server_label": "github"
}
```

### MCP List Tools (`type: "mcp_list_tools"`)
```json
{
  "id": "mcplt_abc123",
  "type": "mcp_list_tools",
  "server_label": "github",
  "tools": [{ "name": "...", "description": "...", "input_schema": {} }]
}
```

### Reasoning (`type: "reasoning"`)
```json
{
  "id": "rs_abc123",
  "type": "reasoning",
  "summary": [
    {
      "type": "summary_text",
      "text": "reasoning summary text"
    }
  ],
  "encrypted_content": "encrypted_base64..." // only with include
}
```

### Image Generation Call (`type: "image_generation_call"`)
```json
{
  "id": "ig_abc123",
  "type": "image_generation_call",
  "result": "base64_image_data",
  "status": "completed"
}
```

---

## Response Object

```json
{
  "id": "resp_abc123",
  "object": "response",
  "created_at": 1741369938.0,
  "status": "completed",
  "error": null,
  "incomplete_details": null,
  "instructions": null,
  "model": "gpt-4o-2024-08-06",
  "output": [/* output items */],
  "output_text": "Convenience field: concatenated text",
  "parallel_tool_calls": null,
  "previous_response_id": null,
  "reasoning": null,
  "service_tier": null,
  "metadata": {},
  "temperature": 1.0,
  "top_p": 1.0,
  "max_output_tokens": null,
  "tool_choice": null,
  "tools": [],
  "text": null,
  "truncation": null,
  "store": false,
  "usage": {
    "input_tokens": 20,
    "output_tokens": 11,
    "total_tokens": 31,
    "output_tokens_details": {
      "reasoning_tokens": 0
    }
  },
  "user": null,
  "reasoning_effort": null
}
```

### Status Values
- `"queued"` - Awaiting processing (background mode)
- `"in_progress"` - Actively processing
- `"completed"` - Finished successfully
- `"incomplete"` - Terminated early (e.g., max tokens)
- `"cancelled"` - User cancelled
- `"failed"` - Error occurred

---

## Streaming Events

All events are SSE with `event:` and `data:` fields. The `data` payload is JSON.

### Response Lifecycle Events
| Event Type | Key Fields | Description |
|------------|------------|-------------|
| `response.created` | `response` | Stream initialized |
| `response.in_progress` | `response` | Processing started |
| `response.completed` | `response` | Generation finished (includes full response with usage) |
| `response.failed` | `response` | Generation failed |
| `response.incomplete` | `response` | Response truncated/incomplete |

### Output Item Events
| Event Type | Key Fields | Description |
|------------|------------|-------------|
| `response.output_item.added` | `item`, `output_index` | New output item started |
| `response.output_item.done` | `item`, `output_index` | Output item completed |

### Text Content Events
| Event Type | Key Fields | Description |
|------------|------------|-------------|
| `response.content_part.added` | `part`, `item_id`, `output_index`, `content_index` | Content part started |
| `response.content_part.done` | `part`, `item_id`, `output_index`, `content_index` | Content part completed |
| `response.output_text.delta` | `delta`, `item_id`, `output_index`, `content_index` | Incremental text |
| `response.output_text.done` | `text`, `item_id`, `output_index`, `content_index` | Full text completed |

### Refusal Events
| Event Type | Key Fields | Description |
|------------|------------|-------------|
| `response.refusal.delta` | `delta`, `item_id`, `content_index` | Incremental refusal text |
| `response.refusal.done` | `refusal`, `item_id`, `content_index` | Refusal completed |

### Function Call Events
| Event Type | Key Fields | Description |
|------------|------------|-------------|
| `response.function_call_arguments.delta` | `delta`, `item_id`, `output_index` | Incremental function args |
| `response.function_call_arguments.done` | `arguments`, `item_id`, `output_index` | Function args completed |

### Reasoning Events
| Event Type | Key Fields | Description |
|------------|------------|-------------|
| `response.reasoning_summary_part.added` | `part`, `item_id`, `summary_index` | Reasoning summary started |
| `response.reasoning_summary_text.delta` | `delta`, `item_id`, `summary_index` | Incremental reasoning |
| `response.reasoning_summary_text.done` | `text`, `item_id`, `summary_index` | Reasoning text completed |
| `response.reasoning_summary_part.done` | `part`, `item_id`, `summary_index` | Reasoning part completed |

### File Search Events
| Event Type | Key Fields | Description |
|------------|------------|-------------|
| `response.file_search_call.in_progress` | `item_id`, `output_index` | File search starting |
| `response.file_search_call.searching` | `item_id`, `output_index` | File search active |
| `response.file_search_call.completed` | `item_id`, `output_index` | File search finished |

### Code Interpreter Events
| Event Type | Key Fields | Description |
|------------|------------|-------------|
| `response.code_interpreter_call.in_progress` | `item_id`, `output_index` | Code execution starting |
| `response.code_interpreter_call.interpreting` | `item_id`, `output_index` | Code executing |
| `response.code_interpreter_call.completed` | `item_id`, `output_index` | Code execution done |

### Web Search Events
| Event Type | Key Fields | Description |
|------------|------------|-------------|
| `response.web_search_call.in_progress` | `item_id`, `output_index` | Web search starting |
| `response.web_search_call.searching` | `item_id`, `output_index` | Web search active |
| `response.web_search_call.completed` | `item_id`, `output_index` | Web search finished |

### MCP Events
| Event Type | Key Fields | Description |
|------------|------------|-------------|
| `response.mcp_call.in_progress` | `item_id`, `output_index` | MCP call starting |
| `response.mcp_call.completed` | `item_id`, `output_index` | MCP call finished |
| `response.mcp_call.failed` | `item_id`, `output_index` | MCP call failed |
| `response.mcp_list_tools.in_progress` | `item_id` | MCP tool listing starting |
| `response.mcp_list_tools.completed` | `item_id` | MCP tool listing done |

### Image Generation Events
| Event Type | Key Fields | Description |
|------------|------------|-------------|
| `response.image_generation_call.in_progress` | `item_id` | Image gen starting |
| `response.image_generation_call.generating` | `item_id` | Image generating |
| `response.image_generation_call.partial_image` | `item_id`, `partial_image_b64` | Partial image data |
| `response.image_generation_call.completed` | `item_id`, `result` | Image gen completed |

### Error Event
| Event Type | Key Fields | Description |
|------------|------------|-------------|
| `error` | `error` (object with code, message) | Error occurred |

### Streaming Flow Examples

**Simple text:**
```
response.created
response.in_progress
response.output_item.added (message)
response.content_part.added (output_text)
response.output_text.delta (x N)
response.output_text.done
response.content_part.done
response.output_item.done
response.completed
```

**Function call:**
```
response.created
response.in_progress
response.output_item.added (function_call)
response.function_call_arguments.delta (x N)
response.function_call_arguments.done
response.output_item.done
response.completed
```

**With reasoning:**
```
response.created
response.in_progress
response.output_item.added (reasoning)
response.reasoning_summary_part.added
response.reasoning_summary_text.delta (x N)
response.reasoning_summary_text.done
response.reasoning_summary_part.done
response.output_item.done
response.output_item.added (message)
response.content_part.added
response.output_text.delta (x N)
response.output_text.done
response.content_part.done
response.output_item.done
response.completed
```

---

## GET /v1/responses/{response_id}

Returns the full response object. Supports `?stream=true&starting_after=N` to resume streaming.

## DELETE /v1/responses/{response_id}

Deletes a stored response. Returns `{ "id": "resp_...", "object": "response.deleted", "deleted": true }`.

## POST /v1/responses/{response_id}/cancel

Cancels an in-progress response. Returns the response object with `status: "cancelled"`.

## GET /v1/responses/{response_id}/input_items

Lists input items for a response. Returns paginated list:
```json
{
  "object": "list",
  "data": [/* input items */],
  "has_more": false,
  "first_id": "msg_...",
  "last_id": "msg_..."
}
```

## POST /v1/responses/compact

Compresses conversation context. Accepts `model`, `input` (array), and/or `previous_response_id`.
Returns compacted output items to use as input for the next request.

---

## Annotations Types

### URL Citation
```json
{
  "type": "url_citation",
  "url": "https://example.com",
  "title": "Page Title",
  "start_index": 0,
  "end_index": 50
}
```

### File Citation
```json
{
  "type": "file_citation",
  "file_id": "file_abc123",
  "quote": "relevant quoted text",
  "start_index": 10,
  "end_index": 30
}
```

### File Path
```json
{
  "type": "file_path",
  "file_id": "file_abc123",
  "start_index": 0,
  "end_index": 20
}
```

---

## Background Mode

Set `background: true` to execute asynchronously. Requires `store: true`.

Poll with `GET /v1/responses/{id}` until status is terminal (completed/failed/cancelled/incomplete).

Can stream background responses with `stream: true` + `background: true`.
Resume streaming with `GET /v1/responses/{id}?stream=true&starting_after={sequence_number}`.

---

## Conversation Management

### Server-side (stateful)
Use `previous_response_id` to chain responses. Server maintains full conversation context.

### Client-side (stateless)
Pass full conversation history in `input` array. Echo back output items as input items.

### Conversation Object
```json
{
  "conversation": {
    "id": "conv_abc123"
  }
}
```
Associates response with a named conversation.

---

## Context Management

```json
{
  "context_management": [
    {
      "type": "compaction",
      "compact_threshold": 50000
    }
  ]
}
```
Automatically compacts context when token count exceeds threshold (minimum: 1000).