Skip to content

improvement: update ai21 chat to OpenAI-compatible /chat/completions - #1769

Closed
ChrisJr404 wants to merge 1 commit into
Portkey-AI:mainfrom
ChrisJr404:fix/1215/ai21-openai-compatible-chat
Closed

ChrisJr404 wants to merge 1 commit into
Portkey-AI:mainfrom
ChrisJr404:fix/1215/ai21-openai-compatible-chat

Conversation

@ChrisJr404

Copy link
Copy Markdown

Description: (required)

Closes #1215. AI21's Jamba models are now served over an OpenAI-compatible chat endpoint, so this points the ai21 provider's chatComplete at /studio/v1/chat/completions and drops the old /{model}/chat shape.

  • api.ts: chatComplete now returns /chat/completions (base URL is unchanged, so requests hit https://api.ai21.com/studio/v1/chat/completions).
  • chatComplete.ts: request config swaps the bespoke AI21 params (numResults, maxTokens, minTokens, topKReturn, the presencePenalty/countPenalty scale objects, and the split messages/system transform) for the standard OpenAI ones — model, messages, max_tokens, temperature, top_p, n, stop, stream, tools, tool_choice, response_format. The system message stays in the messages array like every other OpenAI-style provider instead of being lifted into a separate system field.
  • Response transform reads choices[] / usage from the standard response instead of the old outputs[] shape, and I added a stream chunk transform (wired up as stream-chatComplete in index.ts) since the new endpoint emits OpenAI-style SSE.
  • complete and embed still call the legacy /{model}/complete and /embed routes, so I left those and their transforms alone. AI21ErrorResponseTransform is still exported from chatComplete.ts since complete.ts and embed.ts import it.

Reference: https://docs.ai21.com/reference/jamba-1-6-api-ref

Tests Run/Test cases added: (required)

  • Added src/providers/ai21/chatComplete.test.ts covering the endpoint path, the messages pass-through, the OpenAI response mapping, error detail handling, and the stream chunk rewrite (incl. the [DONE] sentinel). jest src/providers/ai21 → 6 passing.
  • npm run build (rollup) succeeds and prettier --check is clean on the touched files.

Type of Change:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)

AI21's Jamba models moved to an OpenAI-compatible chat endpoint. Point
chatComplete at /studio/v1/chat/completions, swap the bespoke request
params (numResults/maxTokens/topKReturn/penalty scales) for the standard
OpenAI ones, and read the response back from choices/usage instead of the
old outputs[] shape. Also adds streaming support since the new endpoint
emits OpenAI-style SSE chunks. complete and embed still use the legacy
routes and are untouched.
@punkpeye

Copy link
Copy Markdown

Portkey is not actively maintained. Consider submitting to https://github.com/glama-ai/lightport instead.

@ChrisJr404

Copy link
Copy Markdown
Author

Thanks for letting me know. I'll close this since the project isn't being actively maintained.

@ChrisJr404 ChrisJr404 closed this Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update ai21 integration

2 participants