This document relates AI Gateway HTTP routes to how @macpaw/ai-sdk talks to the gateway today. The SDK does not ship a typed HTTP client; it uses an OpenAI-compatible provider plus createGatewayFetch for arbitrary paths.
Gateway routes are versioned under /api/v1/.... Use createGatewayFetch with the correct path, or let the Vercel/OpenAI stack issue requests under the same prefix.
| API | Typical path |
|---|---|
| Chat completions | /api/v1/chat/completions |
| Responses | /api/v1/responses |
| Embeddings | /api/v1/embeddings |
| Model info | /api/v1/model/info |
| Images generations | /api/v1/images/generations |
| Images edits | /api/v1/images/edits |
| Audio transcriptions | /api/v1/audio/transcriptions |
| Audio translations | /api/v1/audio/translations |
- SDK
DEFAULT_BASE_URLS.production:https://api.macpaw.com/ai - Other environments: pass
baseURLexplicitly onGatewayProviderSettings/createGatewayFetch.
Gateway expects Authorization: Bearer <token>. The SDK sets it from getAuthToken() on gateway-scoped requests. After 401, it calls getAuthToken(true) once and retries.
parseErrorResponse / parseErrorResponseFromResponse in gateway-errors.ts support:
- Gateway JSON:
statusCode,message,timestamp,code,path, optionalerrors[] - OpenAI proxy shape:
{ error: { message, type, code } }
Codes map to ErrorCode and typed errors (AuthError, CreditsError, …).
- Multipart (
multipart/form-data): buildFormDatain app code andPOSTviacreateGatewayFetch. - SSE: consumed by upstream
ai/ provider streaming, not by a separate SSE helper in this package’s public API.
| Style | Mechanism |
|---|---|
generateText, streamText, tools, embeddings via Vercel |
createAIGatewayProvider / createGatewayProvider |
| Custom HTTP (multipart, bespoke routes) | createGatewayFetch + fetch API |
| Same gateway, same auth/retry/middleware | Both use GatewayProviderSettings semantics |
Conclusion: Wire format, base URL, auth, and error shapes stay aligned with AI Gateway. The SDK surface is intentionally thin: provider + fetch bridge + NestJS helpers.