Model ID
Use with the Workers AI binding, the AI Gateway REST API, or the Unified API.
Calling the provider directly? Use the provider's model name instead, including with provider-native endpoints or the provider's own SDK. For example, Anthropic's name for anthropic/claude-opus-4.8 is claude-opus-4-8.
- Third-party
- Zero data retention
OpenAI's most capable model for the hardest projects, from start to finish. GPT-6.2 Astra supports advanced reasoning, coding, and agentic workflows.
| Model Info | |
|---|---|
| Context Window ↗ | 1,050,000 tokens |
| Terms and License | link ↗ |
| More information | link ↗ |
| Zero data retention | Yes |
| Request formats | Responses, Chat Completions |
| Pricing |
|
const response = await env.AI.run(
'openai/gpt-6.2-astra',
{
input:
'Plan a phased migration of a high-traffic API from one database to another. Include validation gates, observability, and rollback criteria.',
instructions: 'Return a concise sequence of actionable phases.',
max_output_tokens: 768,
reasoning: { effort: 'high' },
},
)
console.log(response)curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/responses \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "openai/gpt-6.2-astra",
"input": "Plan a phased migration of a high-traffic API from one database to another. Include validation gates, observability, and rollback criteria.",
"instructions": "Return a concise sequence of actionable phases.",
"max_output_tokens": 768,
"reasoning": {
"effort": "high"
}
}'1. **Set gates and rehearse.** Baseline peak-hour p99 latency, error rate, throughput, and database saturation. Set numeric promotion and rollback thresholds, a breach duration, and a maximum replication lag. Treat any confirmed critical data mismatch as an immediate stop. Assign a cutover owner and rehearse both cutover and rollback under peak load. 2. **Backfill while the source owns writes.** Take a consistent snapshot, record its change-log position, and copy in throttled batches. Replay changes from that position, including deletes, in commit order with idempotent retries. Pause the backfill if source health degrades. **Gate:** at a common checkpoint, partition checksums and business invariants match, and replication lag stays within budget under peak traffic. 3. **Shadow reads.** Mirror a sample of production reads to the target without serving its responses. Compare results at equivalent data versions so replication lag is not mistaken for corruption. Dashboard latency, errors, saturation, lag, and mismatches by endpoint and database. **Gate:** no unexplained differences; target performance meets the agreed thresholds. 4. **Canary served reads.** Route stable cohorts to the target in steps, for example 1% → 5% → 25% → 100%. Keep read-after-write requests on the source unless the target has applied the required commit. Promote only after a representative observation window at each step, including peak load before full rollout. **Rollback:** return reads to the source on a threshold breach or critical mismatch. 5. **Switch write ownership.** Briefly queue new writes, drain in-flight source writes, fence the source writer, and verify the target has applied the final source commit. Enable target writes and release the queue. Start reverse replication from the cutover checkpoint, with only the target accepting application writes. **Rollback:** fence target writes, drain and verify reverse replication through the last acknowledged commit, then reopen the source. If catch-up cannot be verified, hold writes rather than fail back to stale data. 6. **Soak and retire.** Keep the source synchronized through the agreed rollback window. **Exit gate:** peak-load SLOs hold, reconciliation remains clean, and a target backup has been successfully restored. Only then stop reverse replication and retire the source.
{
"id": "resp_0f32c611638e55d9006afc9fe98b2487d190b0aa37da1ca2f8",
"object": "response",
"created_at": 1794940905,
"status": "completed",
"access_programs": {
"cyber": "standard"
},
"background": false,
"billing": {
"payer": "developer"
},
"completed_at": 1794940920,
"error": null,
"frequency_penalty": 0,
"image": {
"context_compression": "disabled"
},
"incomplete_details": null,
"input_transformations": [],
"instructions": "Return a concise sequence of actionable phases.",
"max_output_tokens": 768,
"max_tool_calls": null,
"model": "gpt-6.2-astra",
"moderation": null,
"output": [
{
"id": "rs_0f32c611638e55d9006afc9feb253487d1814767f22dbd6094",
"type": "reasoning",
"content": [],
"encrypted_content": "gAAAAABq_J_5TOouOzkeVM7arFJnW7DOvd0OGjH131XBsGFxrWzTTmEu21h0nP3HWaP5GisK8ZpVs38CGVfob84osPoyb3Odid7M4ANsj6CB6o6z3DYFC5KPPWsA6oLeFQ0C5U2Z3lZaek4yvcNA3gQh_NkZpnDmP-4jtpKWAKExJKzyx05-WNCAdEwz9FLyreLQamnHAytdt9cdY7sXhiRMxQbXwxIgh3xry1OfulyaU2cyCmSpssRfUAcIuI6RJ_UVIkuYpil7Ff9Lf4iygbpgLHv9AXOLVsnWlpVvmaCNMmUk38QZo984zcOkRZ2j7-U_YJ0O3_48kEaB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EHclVUcCzvC-C6dx83A1ngWtXJPh0qXC2uwobDenok-NYYumKkU7O9vCKzg_lVYWYzpxAyvjEu26ekLB5P-8Al9gu13MIU0eR8NPs2NgZ-lci663tm_DS88zhLMygRNVdwjnZEbZCV38ifaWPaz0IgEGHSWi6iP5tFPADFotXPIMIdy1C4aQN-xJYNvtwjD-tKCyAYUKOARV1atUgeMQ044DCPDz0lus6bc3jDTFI7LbUVRJjzMTcFrztPmWxluy0uWtPJMMlK515tsQ6e1Kk39GsnewkaXM5Cdg1bnLXGBKwcUsmbpC78kAr-x3UFgq9pykGkzi7gmquTJUn_P2F4x8xUCmKTiEBK9_Xkw7OPkBQfS4hmHa8NDkQ_8n7LfcaQ2FOdXZzcUk8cieXKv26NlYV23aA6ga5V40iXfoOgwhEVVm4cNiJUGSCndoxvVYBQ496dMIl2SkoD8YQOPkm5_myHHOad7NsXsKpz_9AqmpsnT00hlfj6RlXVd0_xZtG2Xe9ziNFtpOLLEW55I5sUfNPYnt",
"summary": []
},
{
"id": "msg_0f32c611638e55d9006afc9ff0715487d1b743fbbcf86d83ea",
"type": "message",
"status": "completed",
"content": [
{
"type": "output_text",
"annotations": [],
"logprobs": [],
"text": "1. **Set gates and rehearse.** Baseline peak-hour p99 latency, error rate, throughput, and database saturation. Set numeric promotion and rollback thresholds, a breach duration, and a maximum replication lag. Treat any confirmed critical data mismatch as an immediate stop. Assign a cutover owner and rehearse both cutover and rollback under peak load.\n\n2. **Backfill while the source owns writes.** Take a consistent snapshot, record its change-log position, and copy in throttled batches. Replay changes from that position, including deletes, in commit order with idempotent retries. Pause the backfill if source health degrades. **Gate:** at a common checkpoint, partition checksums and business invariants match, and replication lag stays within budget under peak traffic.\n\n3. **Shadow reads.** Mirror a sample of production reads to the target without serving its responses. Compare results at equivalent data versions so replication lag is not mistaken for corruption. Dashboard latency, errors, saturation, lag, and mismatches by endpoint and database. **Gate:** no unexplained differences; target performance meets the agreed thresholds.\n\n4. **Canary served reads.** Route stable cohorts to the target in steps, for example 1% → 5% → 25% → 100%. Keep read-after-write requests on the source unless the target has applied the required commit. Promote only after a representative observation window at each step, including peak load before full rollout. **Rollback:** return reads to the source on a threshold breach or critical mismatch.\n\n5. **Switch write ownership.** Briefly queue new writes, drain in-flight source writes, fence the source writer, and verify the target has applied the final sou
... response truncated ...Web Search (RunV2) — Search the web and summarize current migration guidance
const response = await env.AI.run(
'openai/gpt-6.2-astra',
{
input:
'Find current best practices for migrating a high-traffic API between databases. Summarize three recommendations and cite sources.',
max_output_tokens: 512,
tools: [{ type: 'web_search_preview' }],
},
)
console.log(response)curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/responses \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "openai/gpt-6.2-astra",
"input": "Find current best practices for migrating a high-traffic API between databases. Summarize three recommendations and cite sources.",
"max_output_tokens": 512,
"tools": [
{
"type": "web_search_preview"
}
]
}'1. **Copy data while the old database serves traffic.** Keep the old database as the only place the API writes. Copy existing records in batches and use change data capture (CDC) to replicate writes that arrive during the copy. Test at peak traffic and slow the copy if API latency exceeds its target or replication lag keeps growing. ([docs.aws.amazon.com](https://docs.aws.amazon.com/pdfs/prescriptive-guidance/latest/strategy-database-migration/strategy-database-migration.pdf?utm_source=openai)) 2. **Test what clients would see, not just whether the rows match.** Validate the copied records, then run a sample of real read requests against both databases while returning only the old database’s response. Compare results and latency. Investigate mismatches after accounting for replication lag; expand reads on the new database only when it meets the endpoint’s correctness and latency requirements. ([stripe.com](https://stripe.com/blog/online-migrations)) 3. **Rehearse the write switch and the rollback.** For a single-writer migration, briefly pause all writers—including background jobs—and verify that the new database has applied the last committed transaction before redirecting writes. Decide in advance who can call a rollback and what triggers it. Once the new database accepts writes, switching traffic back is not enough: first synchronize those writes back to the old database, or fix the issue on the new one. ([docs.aws.amazon.com](https://docs.aws.amazon.com/prescriptive-guidance/latest/best-practices-migration-cutover/cutover-stage.html?utm_source=openai))
{
"id": "resp_01db8d6cecbd7035006afc9ff975b087d1981da4c2f71cea36",
"object": "response",
"created_at": 1794940921,
"status": "completed",
"access_programs": {
"cyber": "standard"
},
"background": false,
"billing": {
"payer": "developer"
},
"completed_at": 1794940935,
"error": null,
"frequency_penalty": 0,
"image": {
"context_compression": "disabled"
},
"incomplete_details": null,
"input_transformations": [],
"instructions": null,
"max_output_tokens": 512,
"max_tool_calls": null,
"model": "gpt-6.2-astra",
"moderation": null,
"output": [
{
"id": "ws_01db8d6cecbd7035006afc9ffa8a5087d1bf62223a20de9b28",
"type": "web_search_call",
"status": "completed",
"action": {
"type": "search",
"queries": [
"site:docs.aws.amazon.com database migration cutover CDC stop writes replication lag rollback database best practices high traffic",
"site:stripe.com blog online migrations dual writing shadow reads throttle backfill database migration"
],
"query": "site:docs.aws.amazon.com database migration cutover CDC stop writes replication lag rollback database best practices high traffic"
}
},
{
"id": "ws_01db8d6cecbd7035006afc9ffffdf087d1ad8db4ff8bca5bc9",
"type": "web_search_call",
"status": "completed",
"action": {
"type": "open_page",
"url": "https://stripe.com/blog/online-migrations"
}
},
{
"id": "msg_01db8d6cecbd7035006afca00200a487d189639ca33ee87d12",
"type": "message",
"status": "completed",
"content": [
{
"type": "output_text",
"annotations": [
{
"type": "url_citation",
"end_index": 499,
"start_index": 335,
"title": "AWS Prescriptive Guidance - Migration strategy for relational databases",
"url": "https://docs.aws.amazon.com/pdfs/prescriptive-guidance/latest/strategy-database-migration/strategy-database-migration.pdf?utm_source=openai"
},
{
"type": "url_citation",
"end_index": 964,
"start_index": 907,
"title": "Online migrations at scale",
"url": "https://stripe.com/blog/online-migrations"
},
{
"type": "url_citation",
"end_index": 1584,
"start_index": 1433,
"title": "Cutover stage - AWS Prescriptive Guidance",
"url": "https://docs.aws.amazon.com/prescriptive-guidance/latest/best-practices-migration-cutover/cutover-stage.html?utm_source=openai"
}
],
"logprobs": [],
"text": "1. **Copy data while the old database serves traffic.** Keep the old database as the only place the API writes. Copy existing records in batches and use change data capture (CDC) to replicate writes that arrive during the copy. Test at peak traffic and slow the copy if API latency exceeds its target or replication lag keeps growing. ([docs.aws.amazon.com](https://docs.aws.amazon.com/pdfs/prescriptive-guidance/latest/strategy-database-migration/strategy-database-migration.pdf?utm_source=openai))\n\n2. **Test what clients would see, not just whether the rows match.** Validate the copied records, then run a sample of real read requests against both databases while returning only the old database’s response. Compare results and latency. Investigate mismatches after accounting for replication lag; expand reads on the new database only when it meets the endpoint’s correctness and latency requirements. ([stripe.com](https://stripe.com/blog/online-migrations))\n\n3. **Rehearse the write switch and the rollback.** For a single-writer migration, briefly pause all writers—including background jobs—and verify that the new database has applied the last committed transaction before redirecting writes. Decide in advance who can call a rollback and what triggers it. Once the new database accepts writes, switching traffic back is not enough: first synchronize those writes back to the old database, or fix the issue on the new one. ([docs.aws.amazon.com](https://docs.aws.amazon.com/prescriptive-guidance/latest/best-practices-migration-cutover/cutover-stage.html?utm_source=openai))"
}
],
"phase": "final_answer",
"role": "assistant"
}
],
"parallel_tool_calls": true,
"presence_penalty": 0,
"previous_response_id": null,
"prompt_cache_key": null,
"prompt_cache_retention": "24h",
"reasoning": {
"context": "all_turns",
"effort": "medium",
"mode": "standard",
"summary": null
},
"safety_identifier": null,
"service_tier": "default",
"store": true,
"temperature": 1,
"text": {
"format": {
"type": "text"
},
"verbosity": "medium"
},
"tool_choice": "auto",
"tool_usage": {
"image_gen": {
"input_tokens": 0,
"input_tokens_details": {
"image_tokens": 0,
"text_tokens": 0
},
"output_tokens": 0,
"output_tokens_details": {
"image_tokens": 0,
"text_tokens": 0
},
"total_tokens": 0
},
"web_search": {
"num_requests": 1
}
},
"tools": [
{
"type": "web_search_preview",
"search_content_types": [
"text"
],
"search_context_size": "medium",
"user_location": {
"type": "approximate",
"city": null,
"country": "US",
"region": null,
"timezone": null
}
}
],
"top_logprobs": 0,
"top_p": 1,
"truncation": "disabled",
"usage": {
"input_tokens": 14663,
"input_tokens_details": {
"cache_write_tokens": 0,
"cache_write_tokens_details": {
"ttl_12h_tokens": 0,
"ttl_30m_tokens": 0
},
"cached_tokens": 4462
},
"output_tokens": 411,
"output_tokens_details": {
"reasoning_tokens": 95
},
"total_tokens": 15074
},
"user": null,
"metadata": {}
}Chat Completions Coding (RunV2) — Generate a concise, practical coding answer through Chat Completions
const response = await env.AI.run(
'openai/gpt-6.2-astra',
{
messages: [
{
role: 'user',
content:
'Write a TypeScript helper that retries an async operation up to three times with exponential backoff. Include a short usage example.',
},
],
max_completion_tokens: 768,
reasoning_effort: 'medium',
},
)
console.log(response)curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/chat/completions \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "openai/gpt-6.2-astra",
"messages": [
{
"role": "user",
"content": "Write a TypeScript helper that retries an async operation up to three times with exponential backoff. Include a short usage example."
}
],
"max_completion_tokens": 768,
"reasoning_effort": "medium"
}'```ts
async function withRetry<T>(
operation: () => Promise<T>,
initialDelayMs = 100,
): Promise<T> {
const maxRetries = 3;
for (let attempt = 0; ; attempt++) {
try {
return await operation();
} catch (error) {
if (attempt >= maxRetries) throw error;
const delayMs = initialDelayMs * 2 ** attempt;
await new Promise<void>((resolve) => setTimeout(resolve, delayMs));
}
}
}
```
The first attempt runs immediately. If it fails, the helper retries up to three times, waiting 100 ms, 200 ms, then 400 ms by default. If all four attempts fail, it rethrows the last error.
```ts
const status = await withRetry(async () => {
const response = await fetch("https://example.com/status");
if (!response.ok) throw new Error(`HTTP ${response.status}`);
return response.text();
});
console.log(status);
```{
"id": "resp_00db3ebe6f5e0285006afc9fb7d1c087d19ca378f226fffd3c",
"object": "response",
"created_at": 1794940855,
"status": "completed",
"access_programs": {
"cyber": "standard"
},
"background": false,
"billing": {
"payer": "developer"
},
"completed_at": 1794940859,
"error": null,
"frequency_penalty": 0,
"image": {
"context_compression": "disabled"
},
"incomplete_details": null,
"input_transformations": [],
"instructions": null,
"max_output_tokens": 768,
"max_tool_calls": null,
"model": "gpt-6.2-astra",
"moderation": null,
"output": [
{
"id": "rs_00db3ebe6f5e0285006afc9fb9118887d1aaa7ae8c8d45fc13",
"type": "reasoning",
"content": [],
"encrypted_content": "gAAAAABq_J-8C2fKwrp1kWMzQ_oJ1-w0l92o2AxPyvV_YmBWUNPvVa9Usb4mCfAVlZHLs8N08bzm5jKvQmK2wqjoig4jhxXIi-ePqXo8FuHwgT6inThs2BDbVjHOBd5eW3K4n3CVfbWjVbjN6t5EXF3917-_PWdZYTIP4LF6-1ld7vTKKV3Aw_cWCNX6jOoL9TsqR64YupdN3U6ffpxqMksKYa1kpmP9r9L0eCnlxMLTvGybx0ZSBZRlsXwj8YcTJP-PFarHgjMMZh3SepgFqky_uPcF_mIl3tWUkx2MHMJwhIZe_jbSVEjh6scM0y_XPCvGXzMHY44BNySCL4-Z5SkC3UI6MUu3emRk5P4JAUeOl0QVsaOMhgnDcQZyLeUZiCcq2_FR9bpUsBbxURTmcokA7d9_2bpTlggvGnkzEDgLtIu_mydMjdHOgWszS-yVmncx1zrUeGnojw0aMng8kOLEcdLPgdsAqO_GAT5Hnx0h7sDjNKT_i6eSfA5WG1NemMQOrsoxPFANjwuOK2c2bOCFKZCg58dHY5npj6b52Khnn9drxJ9LD1aXDpnsLzObko0ogo59AAWksPWpxDlEYjs2xH9YbKrrhbkY0rggEuTYo0Y6qSdwFJmlOwUhQEF_t2AuWtjZt1cp4GXjyXXV6lsU-wdwd4dcVxeDgzptBQC9DDmUfpgMPB2a0hbA56jZEHnbscXzdwpok8-EFgnwcCa-b_sTwAL5Y8aW23cKv-E2VrCJOweVnDhHJsSA2QP1GDM2bbUrSvMps5e9o3N_B0WH3rzkiQp677tswIdhfEvvCMBAuKxeP9oz4n91jsgPknNCetUzexf2_zB5a2CaGq3C8NnSYZF9QuFbSPWRVNcxYrVGCRDM54XVqoC2evsdjTdtMawGuE0gvs9zgfsw4lURbC7-BBGWB2Vvlhak405cCb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t2h8q_H98qtuMnCQxFJ48k5jBrxjwhTw5nSVYNLtbhIHKkvuHIrgEkDJFKZ3OEfh24IOYGswuqQ9TFi8GRDGugUh4tf2P6bDhDWObcfZaCgr8sIwK-Z6V8QLHnbnsPQeJiRnc0MtqqSPtteljZs1CQkN_c_wQ62_s0rWMeUoIENOVe86kS5L5YM9VAYBJntpKA8aVsZl_oLfmlaPsrv1bFEts2BC_UWCFDiFsg8OC8WYmu2L_u9MJCBt8yymtYe6SJDPHlpOyFq6BApqQ_qJIRumSPrsHv4KVCnnHkYXAvF8qBdcpP8oAeJW5B-hupE7QSci_t5RBkbozLLC8_NoC_-0FnCLzfJekuhic8FAPn-X4-I8IGrAUSKZtFUyHxU1N5CsEUVQDkGBhSfceCgwuc1LkHZrXA0nRGym-E_TlegS8D6Hyu45WzEM1kiZ82tTyU5VA8_dxPBGOiqT3LEZ0BZB7cdXuO26CweeSTAM09RLCIUypO6hEHO-NrKfad82qL0GipLWLS1qe8wpxEeOb_IBCGAaa1sc-G4YbJlbvnMJrSvlvRBZUCOMgQi5aw4BvgmpEeGF5fYzBQ_S3Io0MbQNe1qSHvk_g_EwmFqsrItRaqwYccxk6ZynREeKIO_ig1cj5g2h_rZkPwY_QCEPH19QF8fkVcyM1oKTHRlpnGRFSHmIcgRDd-arUpQNHmHee1WlD4tq_9O0Hc=",
"summary": []
},
{
"id": "msg_00db3ebe6f5e0285006afc9fb9a3f887d1a47ab77ea144d880",
"type": "message",
"status": "completed",
"content": [
{
"type": "output_text",
"annotations": [],
"logprobs": [],
"text": "```ts\nasync function withRetry<T>(\n operation: () => Promise<T>,\n initialDelayMs = 100,\n): Promise<T> {\n const maxRetries = 3;\n\n for (let attempt = 0; ; attempt++) {\n try {\n return await operation();\n } catch (error) {\n if (attempt >= maxRetries) throw error;\n\n const delayMs = initialDelayMs * 2 ** attempt;\n await new Promise<void>((resolve) => setTimeout(resolve, delayMs));\n }\n }\n}\n```\n\nThe first attempt runs immediately. If it fails, the helper retries up to three times, waiting 100 ms, 200 ms, then 400 ms by default. If all four attempts fail, it rethrows the last error.\n\n```ts\nconst status = await withRetry(async () => {\n const response = await fetch(\"https://example.com/status\");\n if (!response.ok) throw new Error(`HTTP ${response.status}`);\n return response.text();\n});\n\nconsole.log(status);\n```"
}
],
"phase": "final_answer",
"role": "assistant"
}
],
"parallel_tool_calls": true,
"presence_penalty": 0,
"previous_response_id": null,
"prompt_cache_key": null,
"prompt_cache_retention": "24h",
"reasoning": {
"context": "all_turns",
"effort": "medium",
"mode": "standard",
"summary": null
},
"safety_identifier": null,
"service_tier": "default",
"store": true,
"temperature": 1,
"text": {
"format": {
"type": "text"
},
"verbosity": "medium"
},
"tool_choice": "auto",
"tool_usage": {
"image_gen": {
"input_tokens": 0,
"input_tokens_details": {
"image_tokens": 0,
"text_tokens": 0
},
"output_tokens": 0,
"output_tokens_details": {
"image_tokens": 0,
"text_tokens": 0
},
"total_tokens": 0
},
"web_search": {
"num_requests": 0
}
},
"tools": [],
"top_logprobs": 0,
"top_p": 1,
"truncation": "disabled",
"usage": {
"input_tokens": 31,
"input_tokens_details": {
"cache_write_tokens": 0,
"cache_write_tokens_details": {
"ttl_12h_tokens": 0,
"ttl_30m_tokens": 0
},
"cached_tokens": 0
},
"output_tokens": 241,
"output_tokens_details": {
"reasoning_tokens": 22
},
"total_tokens": 272
},
"user": null,
"metadata": {}
}▶input
one ofrequiredinstructions
stringtemperature
numberminimum: 0maximum: 2max_output_tokens
numberexclusiveMinimum: 0top_p
numberminimum: 0maximum: 1stream
boolean▶tools[]
arraytool_choice
▶text{}
object▶reasoning{}
object▶messages[]
arrayrequiredtemperature
numberminimum: 0maximum: 2max_tokens
numberexclusiveMinimum: 0max_completion_tokens
numberexclusiveMinimum: 0top_p
numberminimum: 0maximum: 1frequency_penalty
numberminimum: -2maximum: 2presence_penalty
numberminimum: -2maximum: 2stream
boolean▶stream_options{}
object▶tools[]
arraytool_choice
response_format
▶modalities[]
array▶audio{}
objectreasoning_effort
stringOptional reasoning control; availability and accepted values are model-dependent.▶messages[]
arrayrequiredmax_tokens
numberrequiredexclusiveMinimum: 0▶system
one oftemperature
numberminimum: 0maximum: 1top_p
numberminimum: 0maximum: 1top_k
numberexclusiveMinimum: 0stream
boolean▶metadata{}
objectid
stringobject
stringconst: responsecreated_at
numbermodel
string▶output[]
arrayoutput_text
stringstatus
stringenum: in_progress, completed, failed, incomplete▶usage{}
objectid
stringobject
stringcreated
numbermodel
string▶choices[]
array▶usage{}
objectid
stringtype
stringconst: messagerole
stringconst: assistant▶content[]
arraymodel
stringstop_reason
string▶usage{}
object