Claude · API reference

Conversations

Send text, images and documents to Claude, then continue using the returned conversation and assistant IDs. Shared controls and content blocks use Claude API names; conversation state and account selection are managed by Loci.

POST/claude/completionStart
POST/claude/completion/{conversation_id}Continue

01

Start and continue

Rent an account first. Both URLs accept JSON and return one completed JSON response. Send a Loci X-API-Key, or Authorization: Bearer <token>, and Content-Type: application/json.

curl https://scraping.loci.lat/claude/completion \
  -H "X-API-Key: $LOCI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "account_id": "1",
  "model": "claude-sonnet-5-5",
  "system": "Keep answers concise.",
  "content": [
    {
      "type": "text",
      "text": "Explain how solar panels work."
    }
  ]
}'

Keep the response’s conversation_id and id. For the next turn, put conversation_id in the URL and id in assistant_last_message_id. Send only the new user content; the conversation already holds previous turns.

▸ ▾ Continue the same conversation — Complete request
curl https://scraping.loci.lat/claude/completion/22222222-2222-4222-8222-222222222222 \
  -H "X-API-Key: $LOCI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "account_id": "1",
  "model": "claude-sonnet-5-5",
  "system": "Keep answers concise.",
  "content": [
    {
      "type": "text",
      "text": "What happens on a cloudy day?"
    }
  ],
  "assistant_last_message_id": "33333333-3333-4333-8333-333333333333"
}'

The conversation ID stays fixed. The assistant ID changes with each response. Use the same active rental and repeat its system instructions. Tools, thinking and effort are selected on each request; repeat any values you want to keep.

02

Body parameters

Both URLs share this body. Supply model and a turn containing nonblank text or at least one attachment. Unknown fields and invalid values return 400.

model

stringrequired

The model to use for this turn. See the model list. Send the exact ID on every request. Availability also depends on the rented account.

account_id

stringoptional

The account_id returned by a rental, for example "1". Omission selects your latest active rental. Pass it explicitly when you have multiple rentals so a later rental does not change which account handles a conversation.

The rental must belong to the authenticated caller and remain unexpired. Conversations and uploaded file IDs are scoped to that rental’s fixed term.

assistant_last_message_id

UUID stringrequired when continuing

The preceding response’s id. Include it when the URL contains a conversation ID; omit it when starting a conversation. It identifies the assistant turn to continue from, not the conversation itself.

prompt

stringoptional · default empty string

A convenient way to send plain text, such as "Summarize this report.". You can instead use a text block in content.

If both are present, prompt comes first and the text blocks follow, joined with newlines. Put each piece of text in one place to avoid sending it twice.

content

array of content blocksoptional · default []

The current user turn as text, image or document blocks. The content block reference below describes each source format and its fields.

At most 20 entries across content and files combined. Each text block counts as one entry. Text is combined in order; images and documents are attached alongside that text.

files

array of stringsoptional · default []

IDs returned by Upload a file. For example, [ "file_11111111111141118111111111111111" ]. This is a shorthand for attaching existing uploaded files without wrapping each ID in a content block.

Files must belong to the selected rental. Uploaded files can be reused in later turns or other conversations during that rental. Use each attachment once per request, either here or in content.

system

string | array of text blocksoptional · default empty string

Instructions for the whole conversation, up to 100,000 UTF-8 bytes. Text blocks use {"type":"text","text":"…"} and are joined with newlines before the byte limit is checked.

Set instructions on the first turn and repeat the same resolved text on every continuation. Omitting system means empty instructions, so omitting a previously nonempty value is a change and returns 400. Start a new conversation to use different instructions.

▸ ▾ System instructions as text blocks
{
  "system": [
    {
      "type": "text",
      "text": "You help explain scientific concepts."
    },
    {
      "type": "text",
      "text": "Use concise language and define technical terms."
    }
  ]
}

thinking

objectoptional

Selects thinking behavior for this turn. The object contains one required field, type:

  • "adaptive" — automatic thinking; the default for models other than Haiku 4.5.
  • "enabled" — extended thinking; the default and accepted value for Haiku 4.5.

For example, {"thinking":{"type":"adaptive"}}. Returned thinking can contain summaries or redacted content. See response content before assuming there is a complete thinking string.

output_config

objectoptional

Contains the required effort field: "low", "medium", "high" or "xhigh". Higher effort asks Claude to spend more reasoning effort on the turn. Omission defaults to "high".

Example: {"output_config":{"effort":"medium"}}. Omit this object for Haiku 4.5. The setting is chosen afresh on each request.

effort

stringoptional · shorthand

Loci’s shorthand for output_config.effort, with the same values and default. Prefer output_config in new integrations. If you send both, they must agree. Omit both forms for Haiku 4.5.

tools

array of server-tool declarationsoptional · default []

Enables web search, code execution, or both for this turn. Claude decides when to use an enabled tool. Repeat the declarations on later turns to keep those tools available. See Server tools for the exact values.

03

Content blocks

Each block has a type and the fields for that variant. Image and document inputs accept an uploaded file ID or inline data. Inline attachments must contain 1 byte to 8 MiB after decoding; standard base64 is required for binary data.

Text · type: text

text is a required string. Multiple text blocks are joined with newlines after any prompt.

{
  "type": "text",
  "text": "Describe what is in this image."
}
Image · source.type: base64

source requires type: "base64", media_type and data. Accepted image media types are image/jpeg, image/png, image/gif and image/webp. Send the base64 bytes themselves in data.

{
  "type": "image",
  "source": {
    "type": "base64",
    "media_type": "image/jpeg",
    "data": "<base64 image bytes>"
  }
}

An optional title becomes the attachment filename. Omission uses attachment with the matching file extension.

Document · source.type: base64

source requires type: "base64", media_type and data. Accepted document media types for this source are application/pdf and text/plain.

{
  "type": "document",
  "title": "report.pdf",
  "source": {
    "type": "base64",
    "media_type": "application/pdf",
    "data": "<base64 PDF bytes>"
  }
}
Document · source.type: text

Provide a plain-text document without base64 encoding. All three source fields are required; media_type must be "text/plain" and data must be a nonempty string.

{
  "type": "document",
  "title": "notes.txt",
  "source": {
    "type": "text",
    "media_type": "text/plain",
    "data": "Revenue grew by 12% this quarter."
  }
}
Image or document · source.type: file

Use type: "image" for an uploaded image, or type: "document" for an uploaded document. The source requires type: "file" and file_id. The stored file already carries its name and media type; this variant takes only type and source at the block level.

{
  "type": "document",
  "source": {
    "type": "file",
    "file_id": "file_11111111111141118111111111111111"
  }
}

Multipart upload accepts PNG, JPEG, GIF, WebP, PDF, plain text, CSV and JSON. Uploaded file references expire with the rental. Generated output files are for download.

For inline images or documents, title is an optional filename of 1–200 UTF-8 bytes, without slashes, backslashes, double quotes or control characters. Default filenames use the detected media type’s extension.

▸ ▾ Full request with text and an uploaded document
{
  "account_id": "1",
  "model": "claude-sonnet-5-5",
  "content": [
    {
      "type": "text",
      "text": "Summarize the main findings."
    },
    {
      "type": "document",
      "source": {
        "type": "file",
        "file_id": "file_11111111111141118111111111111111"
      }
    }
  ]
}

04

Server tools

These tools run within Claude’s conversation. Send a declaration with its exact type and name. A declaration makes a tool available; it does not guarantee Claude will use it.

Web search
{
  "tools": [
    {
      "type": "web_search_20250305",
      "name": "web_search"
    }
  ]
}

Allows Claude to search the web when answering. Search inputs, results and citations are preserved in the response’s content blocks. Read citation metadata with the associated text so your application can show sources.

Code execution
{
  "tools": [
    {
      "type": "code_execution_20250825",
      "name": "code_execution"
    }
  ]
}

Allows Claude to run code and work with artifacts. Tool results may include generated files; download them using IDs from the response’s files array.

▸ ▾ Enable both tools for a request
{
  "account_id": "1",
  "model": "claude-sonnet-5-5",
  "prompt": "Find the latest published figures, cite the sources, and create a CSV of the results.",
  "tools": [
    {
      "type": "web_search_20250305",
      "name": "web_search"
    },
    {
      "type": "code_execution_20250825",
      "name": "code_execution"
    }
  ]
}

Tool inputs and results keep the web session’s block names and payloads. Returned tool_use blocks describe work inside Claude; your client continues with a new user turn after the completed response. Preserve unfamiliar blocks instead of treating every item as text.

05

Response

A successful request returns 200 with a completed message. The request-id response header identifies this request.

{
  "id": "33333333-3333-4333-8333-333333333333",
  "type": "message",
  "role": "assistant",
  "model": "claude-sonnet-5-5",
  "content": [
    {
      "type": "text",
      "text": "Solar panels turn sunlight into electricity using photovoltaic cells."
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": null,
  "conversation_id": "22222222-2222-4222-8222-222222222222",
  "usage_left": {
    "windows": {
      "5h": {
        "remaining_percent": 98,
        "resets_at": 1792242000,
        "status": "within_limit"
      }
    }
  }
}

id / conversation_id

UUID stringsalways present

id identifies this assistant response. conversation_id identifies its conversation. Use both for the next request, with the same rental that produced them.

type / role / model

stringsalways present

type is "message", role is "assistant", and model identifies the model in the response.

content

array of blocksalways present

Ordered response blocks. Read each item’s type; a response can contain several kinds.

  • text carries answer text and may include citations.
  • thinking may carry a thinking string, summaries, a signature or truncation metadata. A summary can be present while the thinking string is empty.
  • redacted_thinking carries opaque data. Preserve it as supplied.
  • tool_use includes a tool name, ID and assembled input. tool_result can contain nested results and local-resource file metadata. Tool-specific fields are retained.

To display the final answer, collect text blocks in order and render their citations. Keep other blocks available for tool activity and thinking summaries.

stop_reason / stop_sequence

string | nullalways present

The stopping information reported by Claude. A normal completed turn commonly has stop_reason: "end_turn". A value is null when absent; do not infer the reason from the text’s length. Treat other returned reason strings as reported values.

stop_details

objectwhen supplied

Additional stopping metadata reported by Claude, preserved with its original fields.

usage

object | nullalways present

Token usage when the session reports it. Fields such as input_tokens and output_tokens are retained when available. null means no counts were supplied. Missing counts are never estimated or replaced with zero.

usage_left

object | nullalways present

Remaining account quota by window. windows is a map whose keys come from Claude, such as "5h" and "7d". Each window contains:

  • remaining_percent: 0–100, or null when unavailable.
  • resets_at: reset time in Unix seconds, or null.
  • status: the reported window status, or null.

The whole value is null when no quota windows were reported. These percentages describe the account’s allowance, not token counts or your Loci credit balance.

files / warnings

arrayswhen nonempty

files contains registered output-file metadata. warnings contains nonfatal issues encountered while registering those files. A file warning does not discard the completed reply. Both fields are omitted when empty.

06

Generated files

When Claude produces downloadable files, the response can include a files array. Use the Loci ID to download the bytes; paths inside tool results are metadata.

▸ ▾ Generated file metadata
{
  "files": [
    {
      "id": "file_11111111111141118111111111111111",
      "type": "file",
      "filename": "results.csv",
      "mime_type": "text/csv",
      "size_bytes": 128,
      "created_at": "2026-10-17T10:00:00Z",
      "downloadable": true
    }
  ]
}
curl https://scraping.loci.lat/v1/files/file_11111111111141118111111111111111/content \
  -H "X-API-Key: $LOCI_API_KEY" \
  -H "X-Loci-Account-Id: 1" \
  -o results.csv

Downloads require authentication and the same active rental. Save files before that rental expires. Generated files are downloadable outputs; use uploaded files for input attachments.

If warnings reports a registration failure, List files still shows any files that were registered successfully. Deleting a Loci file removes access through Files; copies already attached to a conversation remain with Claude.

07

Errors and retries

Conversation and Files errors use this envelope. The body’s request_id matches the request-id header; keep it when reporting a failed request.

{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "assistant_last_message_id is required to continue a conversation"
  },
  "request_id": "req_example"
}
StatusMeaning and next step
400Invalid fields, values or continuation settings. Correct the request before trying again.
401Missing or invalid Loci authentication. Check your API key or bearer token.
403The selected rental is unavailable, expired or belongs to another caller. Check account_id and its expiry.
404The conversation or file is not available in this rental. Verify both the ID and selected rental.
413The request is too large. Reduce the payload or file size.
429Claude reported a rate limit. Respect Retry-After when present and inspect the account quota.
500A Loci configuration or storage error. Keep the request ID for support.
502The upstream request failed or its reply was malformed or incomplete.
503 / 529The service or Claude is overloaded. Respect Retry-After when present before retrying.

Generation is never retried automatically. A failed or interrupted request may already have used account quota. A manual retry can generate another answer; request-id identifies a request and is not an idempotency key. An incomplete reply returns an error instead of a successful partial message.