{"name":"KnowAPI composite APIs","version":"composite-1","summary":"Describe a relational join across existing KnowAPI datasets. The relationship is validated on real records (key types, cardinality, coverage, entity identity); unsupported or ambiguous joins are rejected, never guessed. A valid composite is materialized, versioned, refreshed when its sources change, and served as a normal queryable API with per-record source provenance.","lifecycle":["POST /v2/composite-apis/plan (free, nothing stored): body {description?, sources?:[{alias,api_id}], spec?:{relationships,select}} returns candidates, schemas, typed relationship proposals, dry run","POST /v2/composite-apis (key + Idempotency-Key): validate on real records and publish, or reject with reasons, or wait for requested sources","GET /v2/composite-apis/{id}: status, validation evidence, freshness, dependency graph","GET /v1/apis/{id}/query: query rows (pay per call like any API)","POST /v2/composite-apis/{id}/refresh (owner): dependency-aware rebuild","POST /v2/composite-apis/{id}/versions (owner): new definition version"],"endpoints":{"plan":"POST https://api.knowapi.dev/v2/composite-apis/plan","create":"POST https://api.knowapi.dev/v2/composite-apis","list":"GET https://api.knowapi.dev/v2/composite-apis","status":"GET https://api.knowapi.dev/v2/composite-apis/{id}","versions":"GET https://api.knowapi.dev/v2/composite-apis/{id}/versions","new_version":"POST https://api.knowapi.dev/v2/composite-apis/{id}/versions","refresh":"POST https://api.knowapi.dev/v2/composite-apis/{id}/refresh","query":"GET https://api.knowapi.dev/v1/apis/{id}/query","docs":"GET https://api.knowapi.dev/v2/composite-apis/docs","mcp_tools":["discover_building_blocks","inspect_building_block","scout_composites","analyze_relationship","plan_composite_api","create_composite_api","check_composite_api","refresh_composite_api","query_api (for the published composite)"]},"spec_schema":{"type":"object","required":["name","sources","relationships","select"],"properties":{"name":{"type":"string","minLength":3,"maxLength":120},"description":{"type":"string","maxLength":500},"refresh_hours":{"type":"integer","minimum":1,"maximum":720,"default":24},"sources":{"type":"array","minItems":2,"maxItems":5,"items":{"type":"object","required":["alias"],"properties":{"alias":{"type":"string","pattern":"^[a-z][a-z0-9_]{0,31}$"},"api_id":{"type":"string","description":"existing product (dataset or published composite)"},"request":{"type":"string","description":"describes a missing dataset; a data request is filed and the composite waits for it"}}}},"relationships":{"type":"array","description":"exactly one per attached source, ordered from the first source outward (a tree: no cycles)","items":{"type":"object","required":["left","right","key_type","cardinality"],"properties":{"left":{"type":"object","properties":{"alias":{"type":"string"},"field":{"type":"string"}}},"right":{"type":"object","properties":{"alias":{"type":"string"},"field":{"type":"string"}}},"key_type":{"type":"string","description":"what the key identifies, e.g. npi, fips, lei"},"normalize":{"enum":["exact","trim_lower","digits"],"default":"exact"},"cardinality":{"enum":["one_to_one","many_to_one","one_to_many","many_to_many"],"description":"left rows per right row; verified against real records"},"allow_many_to_many":{"type":"boolean","default":false},"join":{"enum":["inner","left"],"default":"left"},"min_match_rate":{"type":"number","exclusiveMinimum":0,"maximum":1,"default":0.5},"identity_checks":{"type":"array","description":"independent fields that must agree on matched pairs (e.g. names), default agreement 0.9","items":{"type":"object","properties":{"left_field":{"type":"string"},"right_field":{"type":"string"},"min_agreement":{"type":"number"}}}}}}},"select":{"type":"array","maxItems":60,"items":{"type":"object","required":["alias","field"],"properties":{"alias":{"type":"string"},"field":{"type":"string"},"as":{"type":"string"}}}}}},"example_spec":{"name":"Nursing homes with state inspection counts","description":"Facility records joined to the state-level inspection summary on the 2-letter state code.","sources":[{"alias":"homes","api_id":"<api_id of a nursing home dataset>"},{"alias":"states","api_id":"<api_id of a state inspection summary dataset>"}],"relationships":[{"left":{"alias":"homes","field":"state"},"right":{"alias":"states","field":"state_code"},"key_type":"state","cardinality":"many_to_one","join":"left","min_match_rate":0.9}],"select":[{"alias":"homes","field":"name","as":"facility"},{"alias":"homes","field":"state"},{"alias":"states","field":"inspections","as":"state_inspections"}]},"validation":{"checks":["field existence and type compatibility","declared cardinality vs duplicate keys in the real records","null keys (never matched)","match rate vs min_match_rate","right-side coverage completeness","identity_checks agreement on matched pairs","normalization collisions","projected rows vs row cap and fan-out limit","no cycles, tree-shaped join graph, composite nesting <= 3"],"matching":"Exact equality after the declared normalization only. No fuzzy, similarity or model-based matching exists."},"limits":{"max_sources":5,"max_output_fields":60,"standard_row_cap":250000,"row_cap_note":"Output rows and every source read are capped at 250,000. Above that, the dataset-specific, settled, unexpired storage entitlement from the storage ledger is required; plans and extra response rows never raise it.","max_fanout_per_key":100,"max_nesting":3,"creations_per_caller_per_day":5},"pricing":{"model":"A published composite is a normal KnowAPI API: the first free calls return a 10-record sample, then the per-call price shown in the directory applies (x402 pay-per-call, or prepaid credit). Calls returning 500 or 3,000 records use the standard more-rows tiers. Planning and status reads are free. Filing a missing-source request uses the normal request pipeline and its build fee rules.","see":"https://api.knowapi.dev/v1/apis/{id}/query (402 body carries the exact price)"},"freshness":{"refresh":"Each composite rebuilds on its refresh_hours schedule, only when a dependency changed. The new version replaces the old one atomically. If a source is stale, unreadable, or the new data fails validation, the previous version keeps serving and the response carries stale:true, stale_reasons and last_error."},"provenance":"Every row carries _provenance: for each source the api_id, record_key, source_url and retrieved_at of the exact record joined (or the reason there was none), plus the join key used.","errors":{"invalid_spec":{"http":400,"meaning":"The spec is malformed (aliases, names, relationships, select).","fix":"Read errors[].path and correct the spec."},"invalid_source":{"http":400,"meaning":"A source must have exactly one of api_id or request.","fix":"Use an existing api_id, or describe the missing dataset in request."},"duplicate_dependency":{"http":400,"meaning":"The same product appears under two aliases (a self-join).","fix":"Use each product once."},"join_cycle":{"http":400,"meaning":"Relationships form a cycle; the join graph must be a tree rooted at the first source.","fix":"Attach each source exactly once, ordered from the first source outward."},"graph_not_connected":{"http":400,"meaning":"A relationship starts from a source that is not yet joined.","fix":"Order relationships from the first source outward."},"missing_key_type":{"http":400,"meaning":"key_type (the entity the key identifies, e.g. npi, fips) is required.","fix":"Declare what the key identifies."},"dependency_cycle":{"http":422,"meaning":"The composite would depend on itself through other composites.","fix":"Remove the dependency that closes the loop."},"dependency_too_deep":{"http":422,"meaning":"Composites are nested more than 3 levels.","fix":"Flatten the dependency chain."},"not_found":{"http":404,"meaning":"No such product or composite (also returned when it belongs to someone else).","fix":"Check the id and the key you are using."},"not_public":{"http":422,"meaning":"A source product is not publicly queryable, so it cannot be composed.","fix":"Compose only products listed in the directory."},"unsupported_template":{"http":422,"meaning":"Only stored record datasets and published composites can be composed today.","fix":"Pick a dataset from the directory whose schema lists fields."},"dependency_not_ready":{"http":422,"meaning":"A source composite is not published yet.","fix":"Wait for it to publish."},"source_pending":{"http":202,"meaning":"A source is still a data request that has not been built.","fix":"Poll the composite status; it validates automatically when the source exists."},"unknown_field":{"http":422,"meaning":"A key or selected field is not in the source schema.","fix":"Use field names from /v2/data-products/{id}/schema."},"type_mismatch":{"http":422,"meaning":"The two key fields have incompatible types.","fix":"Choose fields of the same type."},"cardinality_violation":{"http":422,"meaning":"Real records contradict the declared cardinality (duplicate keys where unique was declared); the join would be ambiguous.","fix":"Declare the observed cardinality or choose a unique key."},"many_to_many_not_allowed":{"http":422,"meaning":"Many-to-many joins multiply rows and need explicit opt-in.","fix":"Set allow_many_to_many:true if the fan-out is intended and bounded."},"join_explosion":{"http":422,"meaning":"The join would exceed the row cap or a key matches more than 100 records. Nothing is truncated silently.","fix":"Use a more selective key or add a storage entitlement for a larger cap."},"ambiguous_key_normalization":{"http":422,"meaning":"The declared normalization maps different raw keys to one key, so identity is ambiguous.","fix":"Use normalize:\"exact\" or clean the source."},"no_matches":{"http":422,"meaning":"No key matched: the fields do not identify the same entities.","fix":"Pick the field that actually identifies the same entity."},"insufficient_coverage":{"http":422,"meaning":"Fewer left keys matched than min_match_rate (default 50%).","fix":"Choose a better key, or lower min_match_rate knowingly."},"identity_mismatch":{"http":422,"meaning":"Matched records disagree on the identity_checks fields; the key does not identify the same entity.","fix":"Choose another key or correct identity_checks."},"identity_unverifiable":{"http":422,"meaning":"An identity check had no comparable matched pairs.","fix":"Check fields with values on both sides."},"incomplete_source_coverage":{"http":422,"meaning":"The right-side source is not fully held, so an unmatched key would not prove absence.","fix":"Wait for a full read of the source."},"source_over_row_cap":{"http":422,"meaning":"A source holds more records than the row cap.","fix":"Use a smaller source or a storage entitlement."},"license_blocked":{"http":422,"meaning":"A source or one of its own dependencies has a recorded license or terms that explicitly forbid republishing.","fix":"Choose a different source."},"existing_assets_found":{"http":409,"meaning":"A requested source is already covered by existing building blocks.","fix":"Use the listed api_id, or resend with allow_new_request:true."},"records_unavailable":{"http":503,"meaning":"Records of a block could not be read for analysis.","fix":"Retry later."},"idempotency_conflict":{"http":409,"meaning":"The Idempotency-Key was used with a different spec.","fix":"Use a new key for a different spec."},"unknown_filter":{"http":400,"meaning":"A query parameter is not an output field.","fix":"Filter on columns listed in the response."},"not_published":{"http":409,"meaning":"Only a published composite can refresh or take new versions.","fix":"Wait for status published."},"not_ready":{"http":503,"meaning":"No validated version exists to serve.","fix":"Check status."},"payment_required":{"http":402,"meaning":"Free calls are used. Pay with x402, or use prepaid credit.","fix":"Follow the PAYMENT-REQUIRED header or add_credit_url."}},"limitations":["Only stored record datasets (extracted_dataset: feeds, pages, PDFs read into records) and published composites can be sources; live-only, screening, crypto, weather and Know products cannot.","Composites are public and listed once published; there are no private composites.","Matching is exact after one declared normalization; fuzzy or name-based entity resolution is not offered.","The natural-language entry point discovers candidates and proposes relationships; it does not turn free text into a spec by itself. The agent submits the spec.","Buying storage above 250,000 rows for a composite is not available yet; an existing settled entitlement is honored.","No bulk export endpoint for composites yet.","Refresh runs on the schedule of the service and on demand by the owner; it does not re-fetch upstream publishers, it rebuilds from the stored records of its sources."]}