पाठ 4 / 27
Anthropic और OpenAI साथ-साथ
मुख्य अंतर जानें ताकि आप किसी भी provider के docs पढ़ सकें।
वही विचार, अलग वर्तनी
दोनों APIs मॉडल नाम, भूमिका-चिह्नित messages की सूची और settings लेती हैं; दोनों उत्तर, generation रुकने का कारण और token usage लौटाती हैं। आम अंतर: authentication header (Anthropic के लिए x-api-key और anthropic-version; OpenAI के लिए Authorization: Bearer); system prompt (Anthropic में अलग शीर्ष-स्तर system field; OpenAI में system भूमिका वाला message, या नई Responses API में instructions); max_tokens (Anthropic Messages में आवश्यक; Chat Completions में वैकल्पिक); उत्तर का स्थान (content[0].text बनाम choices[0].message.content); stop reason नाम (end_turn, max_tokens, tool_use बनाम stop, length, tool_calls); और tool formats (input_schema बनाम parameters वाला function)। मॉडल नाम और सुविधाएँ अक्सर बदलती हैं, इसलिए मौजूदा आधिकारिक docs पढ़ें और मॉडल नाम configuration में रखें।
तुलना तालिका
इस कोर्स में प्रयुक्त SDK संस्करणों के अनुसार field नाम; अपने संस्करण के लिए docs देखें।
Anthropic (Messages) OpenAI (Chat Completions)
endpoint /v1/messages /v1/chat/completions (newer: /v1/responses)
auth x-api-key + anthropic-version Authorization: Bearer <key>
system prompt top-level "system" message with role "system"
max_tokens required optional
reply content[0].text choices[0].message.content
stop reasons end_turn / max_tokens / tool_use stop / length / tool_calls
usage input_tokens, output_tokens prompt_tokens, completion_tokens, total_tokens
tool schema input_schema function.parametersपतला adapter रखें
Provider calls को अपने एक छोटे module में लपेटें ताकि provider बदलने या SDK upgrade करने पर एक ही file बदले।
त्वरित जाँच: Anthropic की Messages API system prompt कहाँ रखती है?
- URL में
- अलग शीर्ष-स्तर system field में
- API key में
- कहीं नहीं; समर्थित नहीं
Answer
अलग शीर्ष-स्तर system field में — Anthropic system prompt को messages सूची से अलग रखता है।