How-to

How to Summarize Long Documents with Fikra API

Last updated 2026-11-25. Facts are checked against the live registry.

Overview

Fikra API is an OpenAI-compatible AI inference API. You can summarize a long document by sending it as a chat-completions request to POST https://api.fikraapi.co.ke/v1/chat/completions. Because the API is OpenAI-compatible, you can use the OpenAI Python SDK with Fikra API's base URL.

Prerequisites

  • A Fikra API key, passed to the SDK using the FIKRA_API_KEY environment variable.
  • The openai Python package installed.
  • A document that fits within the model's context window. If the document is larger than the context window, split it into sections and summarize each section, then combine the summaries.

Step-by-step

  1. Set your API key in an environment variable:

bash export FIKRA_API_KEY="your-api-key"

  1. Create an OpenAI client pointing to Fikra API:

```python import os from openai import OpenAI

client = OpenAI( base_url="https://api.fikraapi.co.ke/v1", api_key=os.environ["FIKRA_API_KEY"], ) ```

  1. Send the document as a user message with a summarization instruction:

```python document = "The full text of the long document goes here."

response = client.chat.completions.create( model="deepseek-v4-flash-0731", messages=[ { "role": "system", "content": "Summarize the user's document within the context window.", }, { "role": "user", "content": document, }, ], )

summary = response.choices[0].message.content print(summary) ```

  1. For very long documents, break them into smaller chunks, summarize each chunk, and combine the resulting summaries into a final summary.

Streaming is supported: pass stream=True to the request and iterate over the response chunks if you want to show output incrementally.

Verify it works

The response follows the OpenAI chat-completions format. A successful call returns a 200 status code, and response.choices[0].message.content contains the generated summary. If the request is invalid or unauthorized, you will receive one of the errors listed below.

Costs

Fikra API charges in USD per 1M tokens, depending on the model. The published rates are:

Model Input (USD / 1M tokens) Output (USD / 1M tokens)
deepseek-v4-flash-0731 0.09 0.15
deepseek-v4.1-flash 0.25 0.80
deepseek-v4.1-flash-1017 0.30 0.85
deepseek-v4.1-flash-1017 0.40 0.40
deepseek-v4.1-flash-1017 6.00 12.00
deepseek-v4.1-flash-1017 1.00 1.00

Usage is paid from a token-credit wallet. You can top up via M-Pesa or card through Paystack, or use x402 USDC on Base for agent workloads.

Common errors

  • 401 , The API key is invalid or inactive. Check that FIKRA_API_KEY is set correctly.
  • 400 , The requested model is not supported. Use a model from the list above.
  • 429 , Rate limit exceeded. Unverified keys are limited to 30 requests per minute; trusted keys are limited to 100 requests per minute. Wait and retry.
  • 503 , Upstream service is busy. Retry with exponential backoff.

Live prices -> · Agent account -> · SDKs ->