Documentation Index
Fetch the complete documentation index at: https://docs.fenra.io/llms.txt
Use this file to discover all available pages before exploring further.
This guide covers how to send xAI usage data to Fenra.
Grok API
xAI’s API follows the OpenAI format:
async function chat(messages) {
const response = await fetch('https://api.x.ai/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.XAI_API_KEY}`
},
body: JSON.stringify({
model: 'grok-beta',
messages
})
});
const result = await response.json();
// Send to Fenra
await fetch('https://ingest.fenra.io/usage/transactions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Api-Key': process.env.FENRA_API_KEY
},
body: JSON.stringify({
provider: 'xai',
model: result.model,
usage: [{
type: 'tokens',
metrics: {
input_tokens: result.usage.prompt_tokens,
output_tokens: result.usage.completion_tokens,
total_tokens: result.usage.total_tokens
}
}],
context: {
billable_customer_id: process.env.BILLABLE_CUSTOMER_ID
}
})
});
return result;
}
Reasoning Tokens
For Grok-3 and Grok-4 models with reasoning, include reasoning tokens:
usage: [{
type: 'tokens',
metrics: {
input_tokens: result.usage.prompt_tokens,
output_tokens: result.usage.completion_tokens,
total_tokens: result.usage.total_tokens,
reasoning_tokens: result.usage.completion_tokens_details?.reasoning_tokens || 0
}
}]
Prompt Caching
xAI automatically caches prompt prefixes. Include cached tokens:
usage: [{
type: 'tokens',
metrics: {
input_tokens: result.usage.prompt_tokens,
output_tokens: result.usage.completion_tokens,
total_tokens: result.usage.total_tokens,
cached_tokens: result.usage.prompt_tokens_details?.cached_tokens || 0
}
}]
Multimodal Tokens
For vision and audio models, track separate token types:
usage: [{
type: 'tokens',
metrics: {
input_tokens: result.usage.prompt_tokens,
output_tokens: result.usage.completion_tokens,
total_tokens: result.usage.total_tokens,
text_tokens: result.usage.prompt_tokens_details?.text_tokens || 0,
audio_tokens: result.usage.prompt_tokens_details?.audio_tokens || 0,
image_tokens: result.usage.prompt_tokens_details?.image_tokens || 0
}
}]
When using tools like web search, track tool invocations:
const result = await fetch('https://api.x.ai/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.XAI_API_KEY}`
},
body: JSON.stringify({
model: 'grok-4.1-fast',
messages,
tools: [{ type: 'web_search' }]
})
}).then(r => r.json());
// Count tool invocations from response
const toolCalls = result.choices[0]?.message?.tool_calls || [];
await fetch('https://ingest.fenra.io/usage/transactions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Api-Key': process.env.FENRA_API_KEY
},
body: JSON.stringify({
provider: 'xai',
model: result.model,
usage: [
{
type: 'tokens',
metrics: {
input_tokens: result.usage.prompt_tokens,
output_tokens: result.usage.completion_tokens,
total_tokens: result.usage.total_tokens
}
},
{
type: 'requests',
metrics: {
count: toolCalls.filter(t => t.type === 'web_search').length,
request_type: 'web_search'
}
}
],
context: {
billable_customer_id: process.env.BILLABLE_CUSTOMER_ID
}
})
});
Live Search
For Live Search, track sources used:
usage: [
{
type: 'tokens',
metrics: {
input_tokens: result.usage.prompt_tokens,
output_tokens: result.usage.completion_tokens,
total_tokens: result.usage.total_tokens
}
},
{
type: 'requests',
metrics: {
count: 1,
request_type: 'live_search',
sources_used: result.usage.num_sources_used || 0
}
}
]
Supported Models
Fenra supports all xAI models. Available models include:
| Model | Description |
|---|
grok-4.1-fast | Latest fast model (generic) |
grok-4.1-fast-reasoning | Latest fast model with reasoning capabilities |
grok-4.1-fast-non-reasoning | Latest fast model without reasoning |
grok-4-fast-reasoning | Fast model with reasoning capabilities |
grok-4-fast-non-reasoning | Fast model without reasoning |
grok-code-fast-1 | Code-optimized fast model |
grok-4 | Flagship reasoning model |
grok-4-0709 | Dated variant of Grok-4 |
grok-3 | Legacy reasoning model |
grok-3-mini | Cost-efficient small model |
grok-beta | Legacy beta model |
grok-2-vision-1212 | Vision model |
grok-2-image-1212 | Image generation model |
Next Steps