openai-sdk changedcli-sdks-libraries/libraries/openai-sdk
Nearest release: v2.1.307, published an hour after this site recorded the change. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.
Recorded here
Lines+55added
Lines−55removed
From line
1
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits12to this page, all time
The whole hunk
from line 1, old and new numbered
/
from line 1
11---
22title: OpenAI SDK compatibility
33url: https://platform.claude.com/docs/en/cli-sdks-libraries/libraries/openai-sdk
4description: Anthropic provides a compatibility layer that enables you to use the OpenAI SDK to test the Claude API. With a few code changes, you can quickly evaluate Anthropic model capabilities.
4description: Anthropic provides a compatibility layer that lets you use the OpenAI SDK to test the Claude API. With a few code changes, you can quickly evaluate Anthropic model capabilities.
55---
66
77<Note>
8 This compatibility layer is primarily intended to test and compare model capabilities, and is not considered a long-term or production-ready solution for most use cases. While it is intended to remain fully functional and not have breaking changes, the priority is the reliability and effectiveness of the [Claude API](https://platform.claude.com/docs/en/api/overview).
8 This compatibility layer is primarily intended to test and compare model capabilities, and is not considered a long-term or production-ready solution for most use cases. Although it is intended to remain fully functional and not have breaking changes, the priority is the reliability and effectiveness of the [Claude API](https://platform.claude.com/docs/en/api/overview).
99
1010 For more information on known compatibility limitations, see [Important OpenAI compatibility limitations](https://platform.claude.com/docs/en/cli-sdks-libraries/libraries/openai-sdk#important-openai-compatibility-limitations).
1111
12 If you encounter any issues with the OpenAI SDK compatibility feature, please share your feedback via this [compatibility feedback form](https://forms.gle/oQV4McQNiuuNbz9n8).
12 If you encounter any issues with the OpenAI SDK compatibility feature, share your feedback through this [compatibility feedback form](https://forms.gle/oQV4McQNiuuNbz9n8).
1313</Note>
1414
1515<Tip>
16 For the best experience and access to Claude API full feature set ([PDF processing](https://platform.claude.com/docs/en/build-with-claude/pdf-support), [citations](https://platform.claude.com/docs/en/build-with-claude/citations), [thinking](https://platform.claude.com/docs/en/build-with-claude/thinking), and [prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching)), use the native [Claude API](https://platform.claude.com/docs/en/api/overview).
16 For the best experience and access to the full Claude API feature set ([PDF processing](https://platform.claude.com/docs/en/build-with-claude/pdf-support), [citations](https://platform.claude.com/docs/en/build-with-claude/citations), [thinking](https://platform.claude.com/docs/en/build-with-claude/thinking), and [prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching)), use the native [Claude API](https://platform.claude.com/docs/en/api/overview).
1717</Tip>
1818
1919## Getting started with the OpenAI SDK
from line 20
2020
2121To use the OpenAI SDK compatibility feature, you'll need to:
2222
231. Use an official OpenAI SDK
231. Use an official OpenAI SDK.
2424
25252. Change the following
2626
2727 * Update your base URL to point to the Claude API
2828 * Replace your API key with a [Claude API key](https://platform.claude.com/settings/keys) from the Claude Console
29 * If your key is a [personal or service account key](https://platform.claude.com/docs/en/manage-claude/authentication#key-types) with access to multiple workspaces, also send the `anthropic-workspace-id` header on every request (for example, `default_headers` in the Python SDK or `defaultHeaders` in TypeScript); see [Select a workspace](https://platform.claude.com/docs/en/manage-claude/authentication#select-a-workspace)
29 * If your key is a [personal or service account key](https://platform.claude.com/docs/en/manage-claude/authentication#key-types) that isn't scoped to a workspace, also send the `anthropic-workspace-id` header on every request (for example, `default_headers` in the Python SDK or `defaultHeaders` in TypeScript); see [Select a workspace](https://platform.claude.com/docs/en/manage-claude/authentication#select-a-workspace)
3030 * Update your model name to use a [Claude model](https://platform.claude.com/docs/en/models/overview)
3131
323. Review the following sections for what features are supported
323. Review the following sections for what features are supported.
3333
3434### Quick start example
3535
from line 184
184184Here are the most substantial differences from using OpenAI:
185185
186186* The `strict` parameter for function calling is ignored, which means the tool use JSON is not guaranteed to follow the supplied schema. For guaranteed schema conformance, use the native [Claude API with Structured Outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs).
187* Audio input is not supported; it will be ignored and stripped from input
188* Prompt caching is not supported, but it is supported in the [Anthropic SDKs](https://platform.claude.com/docs/en/cli-sdks-libraries/overview)
187* Audio input is not supported; it is ignored and stripped from input.
188* Prompt caching is not supported, but it is supported in the [Anthropic SDKs](https://platform.claude.com/docs/en/cli-sdks-libraries/overview).
189189* System/developer messages are hoisted and concatenated into the top-level `system` field, wherever they appear in the conversation. To add system instructions partway through a conversation, use [mid-conversation system messages](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages) in the native Claude API.
190190
191191Most unsupported fields are silently ignored rather than producing errors. These are all documented in the following sections.
from line 192
192192
193193### Output quality considerations
194194
195If you’ve done lots of tweaking to your prompt, it’s likely to be well-tuned to OpenAI specifically. Consider reworking it for Claude using the [prompting best practices guide](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices).
195If you’ve adjusted your prompt extensively, it’s likely to be well-tuned to OpenAI specifically. Consider reworking it for Claude using the [prompting best practices](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices) guide.
196196
197197### System / developer message hoisting
198198
199Most of the inputs to the OpenAI SDK clearly map directly to Anthropic’s API parameters, but one distinct difference is the handling of system / developer prompts. These two prompts can be put throughout a chat conversation via OpenAI. The compatibility layer takes all system/developer messages and concatenates them together with a single newline (`\n`) in between them. This full string is then supplied as the top-level `system` field, ahead of every message.
199Most of the inputs to the OpenAI SDK clearly map directly to Claude API parameters, but one distinct difference is the handling of system / developer prompts. These two prompts can be put throughout a chat conversation in the OpenAI API. The compatibility layer takes all system/developer messages and concatenates them together with a single newline (`\n`) in between them. This full string is then supplied as the top-level `system` field, ahead of every message.
200200
201201### Thinking support
202202
from line 297
297297| `n` | Must be exactly 1 |
298298| `logprobs` | Ignored |
299299| `metadata` | Ignored |
300| `response_format` | Ignored. For JSON output, use [Structured Outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs) with the native Claude API |
300| `response_format` | Ignored. For JSON output, use [structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs) with the native Claude API |
301301| `prediction` | Ignored |
302302| `presence_penalty` | Ignored |
303303| `frequency_penalty` | Ignored |
from line 318
318318 <Tab title="Tools">
319319 `tools[n].function` fields
320320
321 | Field | Support status |
322 | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
323 | `name` | Fully supported |
324 | `description` | Fully supported |
325 | `parameters` | Fully supported |
326 | `strict` | Ignored. Use [Structured Outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs) with native Claude API for strict schema validation |
321 | Field | Support status |
322 | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
323 | `name` | Fully supported |
324 | `description` | Fully supported |
325 | `parameters` | Fully supported |
326 | `strict` | Ignored. Use [structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs) with the native Claude API for strict schema validation |
327327 </Tab>
328328
329329 <Tab title="Functions">
from line 330
330330 `functions[n]` fields
331331
332332 <Info>
333 OpenAI has deprecated the `functions` field and suggests using `tools` instead.
333 OpenAI has deprecated the `functions` field and recommends using `tools` instead.
334334 </Info>
335335
336 | Field | Support status |
337 | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
338 | `name` | Fully supported |
339 | `description` | Fully supported |
340 | `parameters` | Fully supported |
341 | `strict` | Ignored. Use [Structured Outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs) with native Claude API for strict schema validation |
336 | Field | Support status |
337 | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
338 | `name` | Fully supported |
339 | `description` | Fully supported |
340 | `parameters` | Fully supported |
341 | `strict` | Ignored. Use [structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs) with the native Claude API for strict schema validation |
342342 </Tab>
343343 </Tabs>
344344</Accordion>
from line 351
351351 Fields for `messages[n].role == "developer"`
352352
353353 <Info>
354 Developer messages are hoisted to beginning of conversation as part of the initial system message
354 Developer messages are hoisted to the beginning of the conversation as part of the initial system message.
355355 </Info>
356356
357357 | Field | Support status |
from line 364
364364 Fields for `messages[n].role == "system"`
365365
366366 <Info>
367 System messages are hoisted to beginning of conversation as part of the initial system message
367 System messages are hoisted to the beginning of the conversation as part of the initial system message.
368368 </Info>
369369
370370 | Field | Support status |
from line 428
428428
429429### Response fields
430430
431| Field | Support status |
432| --------------------------------- | ------------------------------ |
433| `id` | Fully supported |
434| `choices[]` | Will always have a length of 1 |
435| `choices[].finish_reason` | Fully supported |
436| `choices[].index` | Fully supported |
437| `choices[].message.role` | Fully supported |
438| `choices[].message.content` | Fully supported |
439| `choices[].message.tool_calls` | Fully supported |
440| `object` | Fully supported |
441| `created` | Fully supported |
442| `model` | Fully supported |
443| `finish_reason` | Fully supported |
444| `content` | Fully supported |
445| `usage.completion_tokens` | Fully supported |
446| `usage.prompt_tokens` | Fully supported |
447| `usage.total_tokens` | Fully supported |
448| `usage.completion_tokens_details` | Always empty |
449| `usage.prompt_tokens_details` | Always empty |
450| `choices[].message.refusal` | Always empty |
451| `choices[].message.audio` | Always empty |
452| `logprobs` | Always empty |
453| `service_tier` | Always empty |
454| `system_fingerprint` | Always empty |
431| Field | Support status |
432| --------------------------------- | ------------------------ |
433| `id` | Fully supported |
434| `choices[]` | Always has a length of 1 |
435| `choices[].finish_reason` | Fully supported |
436| `choices[].index` | Fully supported |
437| `choices[].message.role` | Fully supported |
438| `choices[].message.content` | Fully supported |
439| `choices[].message.tool_calls` | Fully supported |
440| `object` | Fully supported |
441| `created` | Fully supported |
442| `model` | Fully supported |
443| `finish_reason` | Fully supported |
444| `content` | Fully supported |
445| `usage.completion_tokens` | Fully supported |
446| `usage.prompt_tokens` | Fully supported |
447| `usage.total_tokens` | Fully supported |
448| `usage.completion_tokens_details` | Always empty |
449| `usage.prompt_tokens_details` | Always empty |
450| `choices[].message.refusal` | Always empty |
451| `choices[].message.audio` | Always empty |
452| `logprobs` | Always empty |
453| `service_tier` | Always empty |
454| `system_fingerprint` | Always empty |
455455
456456### Error message compatibility
457457
458The compatibility layer maintains consistent error formats with the OpenAI API. However, the detailed error messages will not be equivalent. Only use the error messages for logging and debugging.
458The compatibility layer maintains consistent error formats with the OpenAI API. However, the detailed error messages are not equivalent. Only use the error messages for logging and debugging.
459459
460460### Header compatibility
461461
462While the OpenAI SDK automatically manages headers, here is the complete list of headers supported by the Claude API for developers who need to work with them directly.
462Although the OpenAI SDK automatically manages headers, here is the complete list of headers supported by the Claude API for developers who need to work with them directly.
463463
464| Header | Support Status |
464| Header | Support status |
465465| -------------------------------- | ------------------- |
466466| `x-ratelimit-limit-requests` | Fully supported |
467467| `x-ratelimit-limit-tokens` | Fully supported |
No line in this hunk matches that.