@raven/sdk package provides a type-safe TypeScript client for sending requests through the Raven AI Gateway. It handles authentication, streaming, error handling, and response parsing.
Installation
Initialization
Create a client with your virtual key and base URL:Configuration Options
| Option | Type | Required | Description |
|---|---|---|---|
apiKey | string | Yes | Your Raven virtual key |
baseUrl | string | Yes | Raven API base URL |
headers | Record<string, string> | No | Additional headers for every request |
Custom Headers
Pass additional headers that are included in every request:Sending Requests
generateText
Send a non-streaming request and receive the complete response:
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model ID (e.g., gpt-4o) |
provider | string | Yes | Provider name (e.g., openai) |
messages | Message[] | Yes | Array of conversation messages |
system | string | No | System prompt (alternative to system message) |
temperature | number | No | Sampling temperature (0-2) |
topP | number | No | Nucleus sampling parameter |
maxTokens | number | No | Maximum tokens to generate |
stop | string[] | No | Stop sequences |
tools | ToolDefinition[] | No | Function/tool definitions |
toolChoice | ToolChoice | No | Tool selection strategy |
Streaming
streamText
Stream responses token by token:
Full Stream Access
Access the raw stream chunks for more control:Aborting a Stream
Cancel an in-progress stream:Error Handling
The SDK throws typed errors for different failure scenarios:Error Types
| Error | Status | Description |
|---|---|---|
AuthenticationError | 401 | Invalid or missing API key |
RateLimitError | 429 | Rate limit exceeded |
ProviderError | 500+ | Upstream provider error |
RavenError | Any | Base error class for all other errors |